2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2013-11-11 22:30:35 -06:00
|
|
|
#include <sal/config.h>
|
2012-01-31 11:32:02 +01:00
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
2007-06-27 13:56:21 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#include <xmloff/nmspmap.hxx>
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2013-11-11 22:30:35 -06:00
|
|
|
#include <xmloff/xmlnmspe.hxx>
|
2008-07-01 15:02:18 +00:00
|
|
|
|
|
|
|
|
2005-03-23 10:24:03 +00:00
|
|
|
using namespace ::xmloff::token;
|
2001-06-29 20:07:26 +00:00
|
|
|
|
2001-06-13 13:16:16 +00:00
|
|
|
/* The basic idea of this class is that we have two two ways to search our
|
2015-01-01 19:58:59 +00:00
|
|
|
* data...by prefix and by key. We use an unordered_map for fast prefix
|
2001-06-13 13:16:16 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2001-07-10 11:00:37 +00:00
|
|
|
* All references to Indices are now deprecated and the corresponding
|
|
|
|
* 'Key' methods should be used instead
|
|
|
|
*
|
2001-06-13 13:16:16 +00:00
|
|
|
* Martin 13/06/01
|
|
|
|
*/
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
SvXMLNamespaceMap::SvXMLNamespaceMap()
|
|
|
|
: sXMLNS( GetXMLToken ( XML_XMLNS ) )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
SvXMLNamespaceMap::SvXMLNamespaceMap( const SvXMLNamespaceMap& rMap )
|
|
|
|
: sXMLNS( GetXMLToken ( XML_XMLNS ) )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
aNameHash = rMap.aNameHash;
|
|
|
|
aNameMap = rMap.aNameMap;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:47:50 +02:00
|
|
|
SvXMLNamespaceMap& SvXMLNamespaceMap::operator=( const SvXMLNamespaceMap& rMap )
|
2004-11-16 09:07:21 +00:00
|
|
|
{
|
|
|
|
aNameHash = rMap.aNameHash;
|
|
|
|
aNameMap = rMap.aNameMap;
|
2016-05-19 12:47:50 +02:00
|
|
|
return *this;
|
2004-11-16 09:07:21 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
SvXMLNamespaceMap::~SvXMLNamespaceMap()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-14 21:14:47 +01:00
|
|
|
bool SvXMLNamespaceMap::operator ==( const SvXMLNamespaceMap& rCmp ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2014-01-14 21:14:47 +01:00
|
|
|
return aNameHash == rCmp.aNameHash;
|
2001-04-18 15:14:13 +00:00
|
|
|
}
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2016-03-29 08:07:14 +02:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::Add_( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey )
|
2001-04-18 15:14:13 +00:00
|
|
|
{
|
2001-07-10 11:00:37 +00:00
|
|
|
if( XML_NAMESPACE_UNKNOWN == nKey )
|
|
|
|
{
|
|
|
|
// create a new unique key with UNKNOWN flag set
|
|
|
|
nKey = XML_NAMESPACE_UNKNOWN_FLAG;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
|
|
|
|
if( aIter == aNameMap.end() )
|
|
|
|
break;
|
|
|
|
nKey++;
|
|
|
|
}
|
2013-03-04 23:11:48 +09:00
|
|
|
while ( true );
|
2001-07-10 11:00:37 +00:00
|
|
|
}
|
2010-10-15 12:10:06 -05:00
|
|
|
::rtl::Reference<NameSpaceEntry> pEntry(new NameSpaceEntry);
|
2001-04-18 15:14:13 +00:00
|
|
|
pEntry->sName = rName;
|
|
|
|
pEntry->nKey = nKey;
|
|
|
|
pEntry->sPrefix = rPrefix;
|
2001-09-24 12:59:52 +00:00
|
|
|
aNameHash[ rPrefix ] = pEntry;
|
|
|
|
aNameMap [ nKey ] = pEntry;
|
2001-07-10 11:00:37 +00:00
|
|
|
return nKey;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::Add( const OUString& rPrefix, const OUString& rName,
|
|
|
|
sal_uInt16 nKey )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
if( XML_NAMESPACE_UNKNOWN == nKey )
|
2000-09-18 23:31:44 +00:00
|
|
|
nKey = GetKeyByName( rName );
|
|
|
|
|
2015-06-04 20:30:21 +01:00
|
|
|
#ifdef NDEBUG
|
2001-07-10 11:00:37 +00:00
|
|
|
if( XML_NAMESPACE_NONE == nKey )
|
|
|
|
return USHRT_MAX;
|
2015-06-04 20:30:21 +01:00
|
|
|
#else
|
|
|
|
assert(XML_NAMESPACE_NONE != nKey);
|
|
|
|
#endif
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
if ( aNameHash.find ( rPrefix ) == aNameHash.end() )
|
2016-03-29 08:07:14 +02:00
|
|
|
nKey = Add_( rPrefix, rName, nKey );
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2001-04-18 15:14:13 +00:00
|
|
|
return nKey;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2004-11-26 20:32:24 +00:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::AddIfKnown( const OUString& rPrefix, const OUString& rName )
|
|
|
|
{
|
|
|
|
sal_uInt16 nKey = GetKeyByName( rName );
|
|
|
|
|
2015-06-04 20:30:21 +01:00
|
|
|
#ifdef NDEBUG
|
2004-11-26 20:32:24 +00:00
|
|
|
if( XML_NAMESPACE_NONE == nKey )
|
|
|
|
return XML_NAMESPACE_UNKNOWN;
|
2015-06-04 20:30:21 +01:00
|
|
|
#else
|
|
|
|
assert(nKey != XML_NAMESPACE_NONE);
|
|
|
|
#endif
|
2004-11-26 20:32:24 +00:00
|
|
|
|
2008-01-04 12:15:03 +00:00
|
|
|
if( XML_NAMESPACE_UNKNOWN != nKey )
|
|
|
|
{
|
|
|
|
NameSpaceHash::const_iterator aIter = aNameHash.find( rPrefix );
|
|
|
|
if( aIter == aNameHash.end() || (*aIter).second->sName != rName )
|
2016-03-29 08:07:14 +02:00
|
|
|
nKey = Add_( rPrefix, rName, nKey );
|
2008-01-04 12:15:03 +00:00
|
|
|
}
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
return nKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetKeyByPrefix( const OUString& rPrefix ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
NameSpaceHash::const_iterator aIter = aNameHash.find(rPrefix);
|
|
|
|
return (aIter != aNameHash.end()) ? (*aIter).second->nKey : USHRT_MAX;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetKeyByName( const OUString& rName ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN;
|
2001-04-18 15:14:13 +00:00
|
|
|
NameSpaceHash::const_iterator aIter = aNameHash.begin(), aEnd = aNameHash.end();
|
|
|
|
while (aIter != aEnd )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
if ((*aIter).second->sName == rName)
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
nKey = (*aIter).second->nKey;
|
2000-09-18 23:31:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-11-26 21:38:23 +00:00
|
|
|
++aIter;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
return nKey;
|
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
const OUString& SvXMLNamespaceMap::GetPrefixByKey( sal_uInt16 nKey ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-07-10 11:00:37 +00:00
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find (nKey);
|
2001-04-18 15:14:13 +00:00
|
|
|
return (aIter != aNameMap.end()) ? (*aIter).second->sPrefix : sEmpty;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
const OUString& SvXMLNamespaceMap::GetNameByKey( sal_uInt16 nKey ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-07-10 11:00:37 +00:00
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find (nKey);
|
2001-04-18 15:14:13 +00:00
|
|
|
return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
OUString SvXMLNamespaceMap::GetAttrNameByKey( sal_uInt16 nKey ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
OUStringBuffer sAttrName;
|
2001-07-10 11:00:37 +00:00
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
|
2001-04-18 15:14:13 +00:00
|
|
|
if (aIter != aNameMap.end())
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
|
|
|
sAttrName.append( sXMLNS );
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString & prefix( (*aIter).second->sPrefix );
|
2012-01-25 17:00:07 -02:00
|
|
|
if (!prefix.isEmpty()) // not default namespace
|
2010-02-12 16:56:44 +01:00
|
|
|
{
|
2013-11-13 12:10:31 +02:00
|
|
|
sAttrName.append( ':' );
|
2010-02-12 16:56:44 +01:00
|
|
|
sAttrName.append( prefix );
|
|
|
|
}
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
return sAttrName.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
OUString SvXMLNamespaceMap::GetQNameByKey( sal_uInt16 nKey,
|
2005-03-08 14:36:44 +00:00
|
|
|
const OUString& rLocalName,
|
2014-03-28 10:53:57 +02:00
|
|
|
bool bCache) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-06-13 13:16:16 +00:00
|
|
|
// We always want to return at least the rLocalName...
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
switch ( nKey )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-06-13 13:16:16 +00:00
|
|
|
case XML_NAMESPACE_UNKNOWN:
|
|
|
|
// ...if it's a completely unknown namespace, assert and return the local name
|
2015-05-22 09:54:43 +01:00
|
|
|
SAL_WARN("xmloff.core", "unknown namespace, probable missing xmlns: declaration");
|
2016-05-10 17:04:20 +02:00
|
|
|
SAL_FALLTHROUGH;
|
2001-06-13 13:16:16 +00:00
|
|
|
case XML_NAMESPACE_NONE:
|
|
|
|
// ...if there isn't one, return the local name
|
2001-07-10 11:00:37 +00:00
|
|
|
return rLocalName;
|
2001-06-13 13:16:16 +00:00
|
|
|
case XML_NAMESPACE_XMLNS:
|
|
|
|
{
|
|
|
|
// ...if it's in the xmlns namespace, make the prefix
|
2001-09-24 12:59:52 +00:00
|
|
|
// don't bother caching this, it rarely happens
|
|
|
|
OUStringBuffer sQName;
|
2001-06-13 13:16:16 +00:00
|
|
|
sQName.append ( sXMLNS );
|
2012-01-25 17:00:07 -02:00
|
|
|
if (!rLocalName.isEmpty()) // not default namespace
|
2010-02-12 16:56:44 +01:00
|
|
|
{
|
2013-11-13 12:10:31 +02:00
|
|
|
sQName.append ( ':' );
|
2010-02-12 16:56:44 +01:00
|
|
|
sQName.append ( rLocalName );
|
|
|
|
}
|
2011-12-14 14:43:58 -05:00
|
|
|
return sQName.makeStringAndClear();
|
2001-06-13 13:16:16 +00:00
|
|
|
}
|
2008-07-01 15:02:18 +00:00
|
|
|
case XML_NAMESPACE_XML:
|
|
|
|
{
|
|
|
|
// this namespace is reserved, and needs not to be declared
|
|
|
|
OUStringBuffer sQName;
|
|
|
|
sQName.append ( GetXMLToken(XML_XML) );
|
2013-11-13 12:10:31 +02:00
|
|
|
sQName.append ( ':' );
|
2008-07-01 15:02:18 +00:00
|
|
|
sQName.append ( rLocalName );
|
2011-12-14 14:43:58 -05:00
|
|
|
return sQName.makeStringAndClear();
|
2008-07-01 15:02:18 +00:00
|
|
|
}
|
2001-06-13 13:16:16 +00:00
|
|
|
default:
|
|
|
|
{
|
2005-03-08 14:36:44 +00:00
|
|
|
QNameCache::const_iterator aQCacheIter;
|
|
|
|
if (bCache)
|
2012-01-31 11:32:02 +01:00
|
|
|
aQCacheIter = aQNameCache.find ( QNamePair ( nKey, rLocalName ) );
|
2005-03-08 14:36:44 +00:00
|
|
|
else
|
|
|
|
aQCacheIter = aQNameCache.end();
|
2001-09-24 12:59:52 +00:00
|
|
|
if ( aQCacheIter != aQNameCache.end() )
|
|
|
|
return (*aQCacheIter).second;
|
2001-06-13 13:16:16 +00:00
|
|
|
else
|
|
|
|
{
|
2001-09-24 12:59:52 +00:00
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
|
|
|
|
if ( aIter != aNameMap.end() )
|
|
|
|
{
|
|
|
|
OUStringBuffer sQName;
|
|
|
|
// ...if it's in our map, make the prefix
|
2009-02-12 14:03:59 +00:00
|
|
|
const OUString & prefix( (*aIter).second->sPrefix );
|
2012-01-25 17:00:07 -02:00
|
|
|
if (!prefix.isEmpty()) // not default namespace
|
2009-02-12 14:03:59 +00:00
|
|
|
{
|
|
|
|
sQName.append( prefix );
|
2013-11-13 12:10:31 +02:00
|
|
|
sQName.append( ':' );
|
2009-02-12 14:03:59 +00:00
|
|
|
}
|
2001-09-24 12:59:52 +00:00
|
|
|
sQName.append ( rLocalName );
|
2005-03-08 14:36:44 +00:00
|
|
|
if (bCache)
|
|
|
|
{
|
|
|
|
OUString sString(sQName.makeStringAndClear());
|
2012-01-31 11:32:02 +01:00
|
|
|
aQNameCache.insert(
|
|
|
|
QNameCache::value_type(
|
|
|
|
QNamePair(nKey, rLocalName), sString));
|
2005-03-08 14:36:44 +00:00
|
|
|
return sString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return sQName.makeStringAndClear();
|
2001-09-24 12:59:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ... if it isn't, this is a Bad Thing, assert and return the local name
|
2015-05-20 14:10:55 +02:00
|
|
|
assert(false);
|
2001-09-24 12:59:52 +00:00
|
|
|
return rLocalName;
|
|
|
|
}
|
2001-06-13 13:16:16 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 08:07:14 +02:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName_(
|
2001-07-10 11:00:37 +00:00
|
|
|
const OUString& rAttrName,
|
2016-03-16 10:17:37 +02:00
|
|
|
OUString *pLocalName) const
|
2001-07-10 11:00:37 +00:00
|
|
|
{
|
2016-03-29 08:07:14 +02:00
|
|
|
return GetKeyByAttrName_( rAttrName, nullptr, pLocalName, nullptr, false/*bCache*/ );
|
2001-07-10 11:00:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:07:14 +02:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName_( const OUString& rAttrName,
|
2000-09-18 23:31:44 +00:00
|
|
|
OUString *pPrefix,
|
|
|
|
OUString *pLocalName,
|
2005-03-08 14:36:44 +00:00
|
|
|
OUString *pNamespace,
|
2014-03-28 10:53:57 +02:00
|
|
|
bool bCache) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN;
|
2000-09-18 23:31:44 +00:00
|
|
|
|
2006-06-19 17:05:24 +00:00
|
|
|
NameSpaceHash::const_iterator it;
|
2005-03-08 14:36:44 +00:00
|
|
|
if (bCache)
|
2006-06-19 17:05:24 +00:00
|
|
|
it = aNameCache.find ( rAttrName );
|
2005-03-08 14:36:44 +00:00
|
|
|
else
|
2006-06-19 17:05:24 +00:00
|
|
|
it = aNameCache.end();
|
|
|
|
if ( it != aNameCache.end() )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2010-10-15 12:10:06 -05:00
|
|
|
const NameSpaceEntry &rEntry = *((*it).second);
|
2003-03-27 17:21:03 +00:00
|
|
|
if ( pPrefix )
|
|
|
|
*pPrefix = rEntry.sPrefix;
|
|
|
|
if ( pLocalName )
|
|
|
|
*pLocalName = rEntry.sName;
|
|
|
|
nKey = rEntry.nKey;
|
|
|
|
if ( pNamespace )
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2003-03-27 17:21:03 +00:00
|
|
|
NameSpaceMap::const_iterator aMapIter = aNameMap.find (nKey);
|
2015-08-26 22:59:12 +02:00
|
|
|
*pNamespace = aMapIter != aNameMap.end() ? (*aMapIter).second->sName : OUString();
|
2003-03-27 17:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-15 12:10:06 -05:00
|
|
|
rtl::Reference<NameSpaceEntry> xEntry(new NameSpaceEntry());
|
2006-05-02 11:21:02 +00:00
|
|
|
|
2013-11-13 12:10:31 +02:00
|
|
|
sal_Int32 nColonPos = rAttrName.indexOf( ':' );
|
2003-03-27 17:21:03 +00:00
|
|
|
if( -1L == nColonPos )
|
|
|
|
{
|
|
|
|
// case: no ':' found -> default namespace
|
2014-11-12 14:24:10 +05:30
|
|
|
(xEntry->sPrefix).clear();
|
2006-05-02 11:21:02 +00:00
|
|
|
xEntry->sName = rAttrName;
|
2001-09-24 12:59:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-27 17:21:03 +00:00
|
|
|
// normal case: ':' found -> get prefix/suffix
|
2006-05-02 11:21:02 +00:00
|
|
|
xEntry->sPrefix = rAttrName.copy( 0L, nColonPos );
|
|
|
|
xEntry->sName = rAttrName.copy( nColonPos + 1L );
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
2003-03-27 17:21:03 +00:00
|
|
|
|
2000-09-18 23:31:44 +00:00
|
|
|
if( pPrefix )
|
2006-05-02 11:21:02 +00:00
|
|
|
*pPrefix = xEntry->sPrefix;
|
2000-09-18 23:31:44 +00:00
|
|
|
if( pLocalName )
|
2006-05-02 11:21:02 +00:00
|
|
|
*pLocalName = xEntry->sName;
|
2003-03-27 17:21:03 +00:00
|
|
|
|
2006-05-02 11:21:02 +00:00
|
|
|
NameSpaceHash::const_iterator aIter = aNameHash.find( xEntry->sPrefix );
|
2003-03-27 17:21:03 +00:00
|
|
|
if ( aIter != aNameHash.end() )
|
|
|
|
{
|
|
|
|
// found: retrieve namespace key
|
2006-05-02 11:21:02 +00:00
|
|
|
nKey = xEntry->nKey = (*aIter).second->nKey;
|
2003-03-27 17:21:03 +00:00
|
|
|
if ( pNamespace )
|
|
|
|
*pNamespace = (*aIter).second->sName;
|
|
|
|
}
|
2006-05-02 11:21:02 +00:00
|
|
|
else if ( xEntry->sPrefix == sXMLNS )
|
2003-03-27 17:21:03 +00:00
|
|
|
// not found, but xmlns prefix: return xmlns 'namespace'
|
2006-05-02 11:21:02 +00:00
|
|
|
nKey = xEntry->nKey = XML_NAMESPACE_XMLNS;
|
2003-03-27 17:21:03 +00:00
|
|
|
else if( nColonPos == -1L )
|
|
|
|
// not found, and no namespace: 'namespace' none
|
2006-05-02 11:21:02 +00:00
|
|
|
nKey = xEntry->nKey = XML_NAMESPACE_NONE;
|
2003-03-27 17:21:03 +00:00
|
|
|
|
2005-03-08 14:36:44 +00:00
|
|
|
if (bCache)
|
2012-01-31 11:32:02 +01:00
|
|
|
{
|
|
|
|
aNameCache.insert(NameSpaceHash::value_type(rAttrName, xEntry));
|
|
|
|
}
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nKey;
|
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetFirstKey() const
|
|
|
|
{
|
|
|
|
return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetNextKey( sal_uInt16 nLastKey ) const
|
|
|
|
{
|
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find ( nLastKey );
|
|
|
|
return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second->nKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// All methods after this are deprecated...
|
|
|
|
|
2015-04-02 14:07:31 +02:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetIndexByKey( sal_uInt16 nKey )
|
2001-07-10 11:00:37 +00:00
|
|
|
{
|
|
|
|
return nKey;
|
|
|
|
}
|
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetFirstIndex() const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
|
|
|
|
2001-07-10 11:00:37 +00:00
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetNextIndex( sal_uInt16 nOldIdx ) const
|
2000-09-18 23:31:44 +00:00
|
|
|
{
|
2001-04-18 15:14:13 +00:00
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find ( nOldIdx );
|
|
|
|
return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second->nKey;
|
2000-09-18 23:31:44 +00:00
|
|
|
}
|
2001-07-10 11:00:37 +00:00
|
|
|
|
2016-01-15 09:36:20 +02:00
|
|
|
void SvXMLNamespaceMap::AddAtIndex( sal_uInt16 /*nIdx*/, const OUString& rPrefix,
|
2001-07-10 11:00:37 +00:00
|
|
|
const OUString& rName, sal_uInt16 nKey )
|
|
|
|
{
|
|
|
|
if( XML_NAMESPACE_UNKNOWN == nKey )
|
|
|
|
nKey = GetKeyByName( rName );
|
|
|
|
|
2015-05-20 14:10:55 +02:00
|
|
|
assert(XML_NAMESPACE_NONE != nKey);
|
2001-07-10 11:00:37 +00:00
|
|
|
if( XML_NAMESPACE_NONE != nKey && ! ( aNameHash.count ( rPrefix ) ) )
|
|
|
|
{
|
2016-03-29 08:07:14 +02:00
|
|
|
Add_( rPrefix, rName, nKey );
|
2001-07-10 11:00:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SvXMLNamespaceMap::GetAttrNameByIndex( sal_uInt16 nIdx ) const
|
|
|
|
{
|
|
|
|
return GetAttrNameByKey( nIdx );
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SvXMLNamespaceMap::GetQNameByIndex( sal_uInt16 nIdx,
|
|
|
|
const OUString& rLocalName ) const
|
|
|
|
{
|
|
|
|
return GetQNameByKey( nIdx, rLocalName );
|
|
|
|
}
|
|
|
|
|
|
|
|
const OUString& SvXMLNamespaceMap::GetPrefixByIndex( sal_uInt16 nIdx ) const
|
|
|
|
{
|
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find (nIdx);
|
|
|
|
return (aIter != aNameMap.end()) ? (*aIter).second->sPrefix : sEmpty;
|
|
|
|
}
|
|
|
|
|
|
|
|
const OUString& SvXMLNamespaceMap::GetNameByIndex( sal_uInt16 nIdx ) const
|
|
|
|
{
|
|
|
|
NameSpaceMap::const_iterator aIter = aNameMap.find (nIdx);
|
|
|
|
return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetIndexByPrefix( const OUString& rPrefix ) const
|
|
|
|
{
|
|
|
|
NameSpaceHash::const_iterator aIter = aNameHash.find(rPrefix);
|
|
|
|
return (aIter != aNameHash.end()) ? (*aIter).second->nKey : USHRT_MAX;
|
|
|
|
}
|
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName(
|
|
|
|
const OUString& rAttrName,
|
|
|
|
OUString *pLocalName,
|
2006-06-19 17:05:24 +00:00
|
|
|
sal_uInt16 /*nIdxGuess*/) const
|
2001-07-10 11:00:37 +00:00
|
|
|
{
|
2016-03-29 08:07:14 +02:00
|
|
|
return GetKeyByAttrName_( rAttrName, nullptr, pLocalName );
|
2001-07-10 11:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName( const OUString& rAttrName,
|
|
|
|
OUString *pPrefix,
|
|
|
|
OUString *pLocalName,
|
|
|
|
OUString *pNamespace,
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_uInt16 /*nIdxGuess*/ ) const
|
2001-07-10 11:00:37 +00:00
|
|
|
{
|
2016-03-29 08:07:14 +02:00
|
|
|
return GetKeyByAttrName_ ( rAttrName, pPrefix, pLocalName, pNamespace );
|
2001-07-10 11:00:37 +00:00
|
|
|
}
|
2004-11-26 20:32:24 +00:00
|
|
|
|
2014-03-28 10:53:57 +02:00
|
|
|
bool SvXMLNamespaceMap::NormalizeURI( OUString& rName )
|
2005-03-23 10:24:03 +00:00
|
|
|
{
|
|
|
|
// try OASIS + W3 URI normalization
|
2014-03-28 10:53:57 +02:00
|
|
|
bool bSuccess = NormalizeOasisURN( rName );
|
2005-03-23 10:24:03 +00:00
|
|
|
if( ! bSuccess )
|
|
|
|
bSuccess = NormalizeW3URI( rName );
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2014-03-28 10:53:57 +02:00
|
|
|
bool SvXMLNamespaceMap::NormalizeW3URI( OUString& rName )
|
2005-03-23 10:24:03 +00:00
|
|
|
{
|
|
|
|
// check if URI matches:
|
|
|
|
// http://www.w3.org/[0-9]*/[:letter:]*
|
|
|
|
// (year)/(WG name)
|
|
|
|
// For the following WG/standards names:
|
|
|
|
// - xforms
|
|
|
|
|
2014-03-28 10:53:57 +02:00
|
|
|
bool bSuccess = false;
|
2016-04-12 16:39:03 +02:00
|
|
|
const OUString& sURIPrefix = GetXMLToken( XML_URI_W3_PREFIX );
|
2013-03-08 12:37:15 +01:00
|
|
|
if( rName.startsWith( sURIPrefix ) )
|
2005-03-23 10:24:03 +00:00
|
|
|
{
|
2016-04-12 16:39:03 +02:00
|
|
|
const OUString& sURISuffix = GetXMLToken( XML_URI_XFORMS_SUFFIX );
|
2005-03-23 10:24:03 +00:00
|
|
|
sal_Int32 nCompareFrom = rName.getLength() - sURISuffix.getLength();
|
|
|
|
if( rName.copy( nCompareFrom ).equals( sURISuffix ) )
|
|
|
|
{
|
|
|
|
// found W3 prefix, and xforms suffix
|
|
|
|
rName = GetXMLToken( XML_N_XFORMS_1_0 );
|
2014-03-28 10:53:57 +02:00
|
|
|
bSuccess = true;
|
2005-03-23 10:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2014-03-28 10:53:57 +02:00
|
|
|
bool SvXMLNamespaceMap::NormalizeOasisURN( OUString& rName )
|
2004-11-26 20:32:24 +00:00
|
|
|
{
|
2005-01-14 10:58:55 +00:00
|
|
|
// #i38644#
|
|
|
|
// we exported the wrong namespace for smil, so we correct this here on load
|
|
|
|
// for older documents
|
2005-03-08 13:54:36 +00:00
|
|
|
if( IsXMLToken( rName, ::xmloff::token::XML_N_SVG ) )
|
2005-01-14 10:58:55 +00:00
|
|
|
{
|
2005-03-08 13:54:36 +00:00
|
|
|
rName = GetXMLToken( ::xmloff::token::XML_N_SVG_COMPAT );
|
2014-03-28 10:53:57 +02:00
|
|
|
return true;
|
2005-03-08 13:54:36 +00:00
|
|
|
}
|
|
|
|
else if( IsXMLToken( rName, ::xmloff::token::XML_N_FO ) )
|
|
|
|
{
|
|
|
|
rName = GetXMLToken( ::xmloff::token::XML_N_FO_COMPAT );
|
2014-03-28 10:53:57 +02:00
|
|
|
return true;
|
2005-03-08 13:54:36 +00:00
|
|
|
}
|
|
|
|
else if( IsXMLToken( rName, ::xmloff::token::XML_N_SMIL ) ||
|
|
|
|
IsXMLToken( rName, ::xmloff::token::XML_N_SMIL_OLD ) )
|
|
|
|
{
|
|
|
|
rName = GetXMLToken( ::xmloff::token::XML_N_SMIL_COMPAT );
|
2014-03-28 10:53:57 +02:00
|
|
|
return true;
|
2005-01-14 10:58:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 23:15:32 +01:00
|
|
|
|
2004-11-26 20:32:24 +00:00
|
|
|
// Check if URN matches
|
|
|
|
// :urn:oasis:names:tc:[^:]*:xmlns:[^:]*:1.[^:]*
|
|
|
|
// |---| |---| |-----|
|
|
|
|
// TC-Id Sub-Id Version
|
|
|
|
|
|
|
|
sal_Int32 nNameLen = rName.getLength();
|
|
|
|
// :urn:oasis:names:tc.*
|
|
|
|
const OUString& rOasisURN = GetXMLToken( XML_URN_OASIS_NAMES_TC );
|
2013-03-08 12:37:15 +01:00
|
|
|
if( !rName.startsWith( rOasisURN ) )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:.*
|
|
|
|
sal_Int32 nPos = rOasisURN.getLength();
|
|
|
|
if( nPos >= nNameLen || rName[nPos] != ':' )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:[^:]:.*
|
|
|
|
sal_Int32 nTCIdStart = nPos+1;
|
|
|
|
sal_Int32 nTCIdEnd = rName.indexOf( ':', nTCIdStart );
|
|
|
|
if( -1 == nTCIdEnd )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:[^:]:xmlns.*
|
|
|
|
nPos = nTCIdEnd + 1;
|
|
|
|
OUString sTmp( rName.copy( nPos ) );
|
|
|
|
const OUString& rXMLNS = GetXMLToken( XML_XMLNS );
|
2013-03-08 12:37:15 +01:00
|
|
|
if( !sTmp.startsWith( rXMLNS ) )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:[^:]:xmlns:.*
|
|
|
|
nPos += rXMLNS.getLength();
|
|
|
|
if( nPos >= nNameLen || rName[nPos] != ':' )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:[^:]:xmlns:[^:]*:.*
|
|
|
|
nPos = rName.indexOf( ':', nPos+1 );
|
|
|
|
if( -1 == nPos )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:[^:]:xmlns:[^:]*:[^:][^:][^:][^:]*
|
|
|
|
sal_Int32 nVersionStart = nPos+1;
|
|
|
|
if( nVersionStart+2 >= nNameLen ||
|
|
|
|
-1 != rName.indexOf( ':', nVersionStart ) )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// :urn:oasis:names:tc:[^:]:xmlns:[^:]*:1\.[^:][^:]*
|
|
|
|
if( rName[nVersionStart] != '1' || rName[nVersionStart+1] != '.' )
|
2014-03-28 10:53:57 +02:00
|
|
|
return false;
|
2004-11-26 20:32:24 +00:00
|
|
|
|
|
|
|
// replace [tcid] with current TCID and version with current version.
|
|
|
|
|
2013-08-09 17:07:04 +02:00
|
|
|
rName = rName.copy( 0, nTCIdStart ) +
|
|
|
|
GetXMLToken( XML_OPENDOCUMENT ) +
|
|
|
|
rName.copy( nTCIdEnd, nVersionStart-nTCIdEnd ) +
|
|
|
|
GetXMLToken( XML_1_0 );
|
2004-11-26 20:32:24 +00:00
|
|
|
|
2014-03-28 10:53:57 +02:00
|
|
|
return true;
|
2004-11-26 20:32:24 +00:00
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|