/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/* The basic idea of this class is that we have two ways to search our * data, by prefix and by key. We use an unordered_map for fast prefix * searching and an STL map for fast key searching. * * The references to an 'Index' refer to an earlier implementation of the * name space map and remain to support code which uses these interfaces. * * In this implementation, key and index should always be the same number. * * All references to Indices are now deprecated and the corresponding * 'Key' methods should be used instead * * Martin 13/06/01
*/
OUString SvXMLNamespaceMap::GetQNameByKey( sal_uInt16 nKey, const OUString& rLocalName, bool bCache) const
{ // We always want to return at least the rLocalName...
switch ( nKey )
{ case XML_NAMESPACE_UNKNOWN: // ...if it's a completely unknown namespace, assert and return the local name
SAL_WARN("xmloff.core", "unknown namespace, probable missing xmlns: declaration");
[[fallthrough]]; case XML_NAMESPACE_NONE: // ...if there isn't one, return the local name return rLocalName; case XML_NAMESPACE_XMLNS:
{ // ...if it's in the xmlns namespace, make the prefix // don't bother caching this, it rarely happens if (!rLocalName.isEmpty()) // not default namespace return m_sXMLNS + ":" + rLocalName; else return m_sXMLNS;
} case XML_NAMESPACE_XML:
{ // this namespace is reserved, and needs not to be declared return GetXMLToken(XML_XML) + ":" + rLocalName;
} default:
{
QNameCache::const_iterator aQCacheIter; if (bCache)
aQCacheIter = m_aQNameCache.find ( QNamePair ( nKey, rLocalName ) ); else
aQCacheIter = m_aQNameCache.end(); if ( aQCacheIter != m_aQNameCache.end() ) return (*aQCacheIter).second; else
{ auto aIter = maKeyToNamespaceMap.find ( nKey ); if ( aIter != maKeyToNamespaceMap.end() )
{ // ...if it's in our map, make the prefix const OUString & prefix( (*aIter).second.sPrefix );
OUString sQName; if (!prefix.isEmpty()) // not default namespace
sQName = prefix + ":" + rLocalName; else
sQName = rLocalName; if (bCache)
m_aQNameCache.emplace(QNamePair(nKey, rLocalName), sQName); return sQName;
} else
{ // ... if it isn't, this is a Bad Thing, assert and return the local name
assert(false); return rLocalName;
}
}
}
}
}
/** @param rQName either attribute name or qualified/namespaced attribute value @param bCacheAttrName true: rQName is element or attribute name, cache it false: rQName is attribute value, may contain extra ':', don't cache it
*/
sal_uInt16 SvXMLNamespaceMap::GetKeyByQName(const OUString& rQName,
OUString *pPrefix,
OUString *pLocalName,
OUString *pNamespace,
QNameMode const eMode) const
{
sal_uInt16 nKey;
NameSpaceHash::const_iterator it; if (eMode == QNameMode::AttrNameCached)
it = m_aNameCache.find ( rQName ); else
it = m_aNameCache.end(); if ( it != m_aNameCache.end() )
{ const NameSpaceEntry &rEntry = (*it).second; if ( pPrefix )
*pPrefix = rEntry.m_sPrefix; if ( pLocalName )
*pLocalName = rEntry.m_sName;
nKey = rEntry.m_nKey; if ( pNamespace )
{ auto aMapIter = maKeyToNamespaceMap.find (nKey);
*pNamespace = aMapIter != maKeyToNamespaceMap.end() ? (*aMapIter).second.sName : OUString();
}
} else
{
OUString sEntryPrefix, sEntryName;
sal_Int32 nColonPos = rQName.indexOf( ':' ); if( -1 == nColonPos )
{ // case: no ':' found -> default namespace
sEntryName = rQName;
} else
{ // normal case: ':' found -> get prefix/suffix
sEntryPrefix = rQName.copy( 0, nColonPos );
sEntryName = rQName.copy( nColonPos + 1 );
}
if (eMode == QNameMode::AttrNameCached && sEntryName.indexOf(':') != -1)
{
SAL_INFO("xmloff", "invalid attribute name with multiple ':'");
assert(false); return XML_NAMESPACE_UNKNOWN;
}
bool SvXMLNamespaceMap::NormalizeW3URI( OUString& rName )
{ // check if URI matches: // http://www.w3.org/[0-9]*/[:letter:]* // (year)/(WG name) // For the following WG/standards names: // - xforms
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.