LCOV - code coverage report
Current view: top level - xmloff/source/core - nmspmap.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 207 249 83.1 %
Date: 2014-04-11 Functions: 25 32 78.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <tools/debug.hxx>
      23             : #include <rtl/ustring.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : 
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <xmloff/nmspmap.hxx>
      28             : 
      29             : #include <xmloff/xmlnmspe.hxx>
      30             : 
      31             : 
      32             : using namespace ::xmloff::token;
      33             : 
      34             : /* The basic idea of this class is that we have two two ways to search our
      35             :  * data...by prefix and by key. We use an STL boost::unordered_map for fast prefix
      36             :  * searching and an STL map for fast key searching.
      37             :  *
      38             :  * The references to an 'Index' refer to an earlier implementation of the
      39             :  * name space map and remain to support code which uses these interfaces.
      40             :  *
      41             :  * In this implementation, key and index should always be the same number.
      42             :  *
      43             :  * All references to Indices are now deprecated and the corresponding
      44             :  * 'Key' methods should be used instead
      45             :  *
      46             :  * Martin 13/06/01
      47             :  */
      48             : 
      49        8442 : SvXMLNamespaceMap::SvXMLNamespaceMap()
      50        8442 : : sXMLNS( GetXMLToken ( XML_XMLNS ) )
      51             : {
      52        8442 : }
      53             : 
      54        4171 : SvXMLNamespaceMap::SvXMLNamespaceMap( const SvXMLNamespaceMap& rMap )
      55        4171 : : sXMLNS( GetXMLToken ( XML_XMLNS ) )
      56             : {
      57        4171 :     aNameHash = rMap.aNameHash;
      58        4171 :     aNameMap  = rMap.aNameMap;
      59        4171 : }
      60             : 
      61           0 : void SvXMLNamespaceMap::operator=( const SvXMLNamespaceMap& rMap )
      62             : {
      63           0 :     aNameHash = rMap.aNameHash;
      64           0 :     aNameMap = rMap.aNameMap;
      65           0 : }
      66             : 
      67       12177 : SvXMLNamespaceMap::~SvXMLNamespaceMap()
      68             : {
      69       12177 : }
      70             : 
      71        4182 : bool SvXMLNamespaceMap::operator ==( const SvXMLNamespaceMap& rCmp ) const
      72             : {
      73        4182 :     return aNameHash == rCmp.aNameHash;
      74             : }
      75             : 
      76      117002 : sal_uInt16 SvXMLNamespaceMap::_Add( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey )
      77             : {
      78      117002 :     if( XML_NAMESPACE_UNKNOWN == nKey )
      79             :     {
      80             :         // create a new unique key with UNKNOWN flag set
      81        3354 :         nKey = XML_NAMESPACE_UNKNOWN_FLAG;
      82             :         do
      83             :         {
      84       14367 :             NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
      85       14367 :             if( aIter == aNameMap.end() )
      86        3354 :                 break;
      87       11013 :             nKey++;
      88             :         }
      89       11013 :         while ( true );
      90             :     }
      91      117002 :     ::rtl::Reference<NameSpaceEntry> pEntry(new NameSpaceEntry);
      92      117002 :     pEntry->sName   = rName;
      93      117002 :     pEntry->nKey    = nKey;
      94      117002 :     pEntry->sPrefix = rPrefix;
      95      117002 :     aNameHash[ rPrefix ] = pEntry;
      96      117002 :     aNameMap [ nKey ]    = pEntry;
      97      117002 :     return nKey;
      98             : }
      99             : 
     100       96851 : sal_uInt16 SvXMLNamespaceMap::Add( const OUString& rPrefix, const OUString& rName,
     101             :                                sal_uInt16 nKey )
     102             : {
     103       96851 :     if( XML_NAMESPACE_UNKNOWN == nKey )
     104        3358 :         nKey = GetKeyByName( rName );
     105             : 
     106             :     DBG_ASSERT( XML_NAMESPACE_NONE != nKey,
     107             :                 "SvXMLNamespaceMap::Add: invalid namespace key" );
     108             : 
     109       96851 :     if( XML_NAMESPACE_NONE == nKey )
     110           0 :         return USHRT_MAX;
     111             : 
     112       96851 :     if ( aNameHash.find ( rPrefix ) == aNameHash.end() )
     113       94666 :         nKey = _Add( rPrefix, rName, nKey );
     114             : 
     115       96851 :     return nKey;
     116             : }
     117             : 
     118       27646 : sal_uInt16 SvXMLNamespaceMap::AddIfKnown( const OUString& rPrefix, const OUString& rName )
     119             : {
     120       27646 :     sal_uInt16 nKey = GetKeyByName( rName );
     121             : 
     122             :     DBG_ASSERT( XML_NAMESPACE_NONE != nKey,
     123             :                 "SvXMLNamespaceMap::AddIfKnown: invalid namespace key" );
     124             : 
     125       27646 :     if( XML_NAMESPACE_NONE == nKey )
     126           0 :         return XML_NAMESPACE_UNKNOWN;
     127             : 
     128       27646 :     if( XML_NAMESPACE_UNKNOWN != nKey )
     129             :     {
     130       23938 :         NameSpaceHash::const_iterator aIter = aNameHash.find( rPrefix );
     131       23938 :         if( aIter == aNameHash.end() || (*aIter).second->sName != rName )
     132       22336 :             nKey = _Add( rPrefix, rName, nKey );
     133             :     }
     134             : 
     135       27646 :     return nKey;
     136             : }
     137             : 
     138             : 
     139          17 : sal_uInt16 SvXMLNamespaceMap::GetKeyByPrefix( const OUString& rPrefix ) const
     140             : {
     141          17 :     NameSpaceHash::const_iterator aIter = aNameHash.find(rPrefix);
     142          17 :     return (aIter != aNameHash.end()) ? (*aIter).second->nKey : USHRT_MAX;
     143             : }
     144             : 
     145       31029 : sal_uInt16 SvXMLNamespaceMap::GetKeyByName( const OUString& rName ) const
     146             : {
     147       31029 :     sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN;
     148       31029 :     NameSpaceHash::const_iterator aIter = aNameHash.begin(), aEnd = aNameHash.end();
     149      950293 :     while (aIter != aEnd )
     150             :     {
     151      912181 :         if ((*aIter).second->sName == rName)
     152             :         {
     153       23946 :             nKey = (*aIter).second->nKey;
     154       23946 :             break;
     155             :         }
     156      888235 :         ++aIter;
     157             :     }
     158       31029 :     return nKey;
     159             : }
     160             : 
     161          10 : const OUString& SvXMLNamespaceMap::GetPrefixByKey( sal_uInt16 nKey ) const
     162             : {
     163          10 :     NameSpaceMap::const_iterator aIter = aNameMap.find (nKey);
     164          10 :     return (aIter != aNameMap.end()) ? (*aIter).second->sPrefix : sEmpty;
     165             : }
     166             : 
     167       25322 : const OUString& SvXMLNamespaceMap::GetNameByKey( sal_uInt16 nKey ) const
     168             : {
     169       25322 :     NameSpaceMap::const_iterator aIter = aNameMap.find (nKey);
     170       25322 :     return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty;
     171             : }
     172             : 
     173       32111 : OUString SvXMLNamespaceMap::GetAttrNameByKey( sal_uInt16 nKey ) const
     174             : {
     175       32111 :     OUStringBuffer sAttrName;
     176       32111 :     NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
     177       32111 :     if (aIter != aNameMap.end())
     178             :     {
     179       32111 :         sAttrName.append( sXMLNS  );
     180       32111 :         const OUString & prefix( (*aIter).second->sPrefix );
     181       32111 :         if (!prefix.isEmpty()) // not default namespace
     182             :         {
     183       31554 :             sAttrName.append( ':' );
     184       31554 :             sAttrName.append( prefix );
     185             :         }
     186             :     }
     187       32111 :     return sAttrName.makeStringAndClear();
     188             : }
     189             : 
     190      256758 : OUString SvXMLNamespaceMap::GetQNameByKey( sal_uInt16 nKey,
     191             :                             const OUString& rLocalName,
     192             :                             bool bCache) const
     193             : {
     194             :     // We always want to return at least the rLocalName...
     195             : 
     196      256758 :     switch ( nKey )
     197             :     {
     198             :         case XML_NAMESPACE_UNKNOWN:
     199             :             // ...if it's a completely unknown namespace, assert and return the local name
     200             :             DBG_ASSERT( false, "SvXMLNamespaceMap::GetQNameByKey: invalid namespace key" );
     201             :         case XML_NAMESPACE_NONE:
     202             :             // ...if there isn't one, return the local name
     203          37 :             return rLocalName;
     204             :         case XML_NAMESPACE_XMLNS:
     205             :         {
     206             :             // ...if it's in the xmlns namespace, make the prefix
     207             :             // don't bother caching this, it rarely happens
     208           0 :             OUStringBuffer sQName;
     209           0 :             sQName.append ( sXMLNS );
     210           0 :             if (!rLocalName.isEmpty()) // not default namespace
     211             :             {
     212           0 :                 sQName.append ( ':' );
     213           0 :                 sQName.append ( rLocalName );
     214             :             }
     215           0 :             return sQName.makeStringAndClear();
     216             :         }
     217             :         case XML_NAMESPACE_XML:
     218             :         {
     219             :             // this namespace is reserved, and needs not to be declared
     220          56 :             OUStringBuffer sQName;
     221          56 :             sQName.append ( GetXMLToken(XML_XML) );
     222          56 :             sQName.append ( ':' );
     223          56 :             sQName.append ( rLocalName );
     224          56 :             return sQName.makeStringAndClear();
     225             :         }
     226             :         default:
     227             :         {
     228      256665 :             QNameCache::const_iterator aQCacheIter;
     229      256665 :             if (bCache)
     230      256613 :                 aQCacheIter = aQNameCache.find ( QNamePair ( nKey, rLocalName ) );
     231             :             else
     232          52 :                 aQCacheIter = aQNameCache.end();
     233      256665 :             if ( aQCacheIter != aQNameCache.end() )
     234      209209 :                 return (*aQCacheIter).second;
     235             :             else
     236             :             {
     237       47456 :                 NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
     238       47456 :                 if ( aIter != aNameMap.end() )
     239             :                 {
     240       47456 :                     OUStringBuffer sQName;
     241             :                     // ...if it's in our map, make the prefix
     242       47456 :                     const OUString & prefix( (*aIter).second->sPrefix );
     243       47456 :                     if (!prefix.isEmpty()) // not default namespace
     244             :                     {
     245       41796 :                         sQName.append( prefix );
     246       41796 :                         sQName.append( ':' );
     247             :                     }
     248       47456 :                     sQName.append ( rLocalName );
     249       47456 :                     if (bCache)
     250             :                     {
     251       47404 :                         OUString sString(sQName.makeStringAndClear());
     252             :                         aQNameCache.insert(
     253             :                             QNameCache::value_type(
     254       47404 :                                 QNamePair(nKey, rLocalName), sString));
     255       47404 :                         return sString;
     256             :                     }
     257             :                     else
     258          52 :                         return sQName.makeStringAndClear();
     259             :                 }
     260             :                 else
     261             :                 {
     262             :                     // ... if it isn't, this is a Bad Thing, assert and return the local name
     263             :                     DBG_ASSERT( false, "SvXMLNamespaceMap::GetQNameByKey: invalid namespace key" );
     264           0 :                     return rLocalName;
     265             :                 }
     266             :             }
     267             :         }
     268             :     }
     269             : }
     270             : 
     271           7 : sal_uInt16 SvXMLNamespaceMap::_GetKeyByAttrName(
     272             :                             const OUString& rAttrName,
     273             :                             OUString *pLocalName,
     274             :                             bool bCache) const
     275             : {
     276           7 :     return _GetKeyByAttrName( rAttrName, 0, pLocalName, 0, bCache );
     277             : }
     278             : 
     279      444130 : sal_uInt16 SvXMLNamespaceMap::_GetKeyByAttrName( const OUString& rAttrName,
     280             :                                             OUString *pPrefix,
     281             :                                             OUString *pLocalName,
     282             :                                             OUString *pNamespace,
     283             :                                             bool bCache) const
     284             : {
     285      444130 :     sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN;
     286             : 
     287      444130 :     NameSpaceHash::const_iterator it;
     288      444130 :     if (bCache)
     289      443333 :         it = aNameCache.find ( rAttrName );
     290             :     else
     291         797 :         it = aNameCache.end();
     292      444130 :     if ( it != aNameCache.end() )
     293             :     {
     294      382352 :         const NameSpaceEntry &rEntry = *((*it).second);
     295      382352 :         if ( pPrefix )
     296       34470 :             *pPrefix = rEntry.sPrefix;
     297      382352 :         if ( pLocalName )
     298      382349 :             *pLocalName = rEntry.sName;
     299      382352 :         nKey = rEntry.nKey;
     300      382352 :         if ( pNamespace )
     301             :         {
     302       34470 :             NameSpaceMap::const_iterator aMapIter = aNameMap.find (nKey);
     303       34470 :             *pNamespace = aMapIter != aNameMap.end() ? (*aMapIter).second->sName : sEmpty;
     304             :         }
     305             :     }
     306             :     else
     307             :     {
     308       61778 :     rtl::Reference<NameSpaceEntry> xEntry(new NameSpaceEntry());
     309             : 
     310       61778 :         sal_Int32 nColonPos = rAttrName.indexOf( ':' );
     311       61778 :         if( -1L == nColonPos )
     312             :         {
     313             :             // case: no ':' found -> default namespace
     314         438 :             xEntry->sPrefix = OUString();
     315         438 :             xEntry->sName = rAttrName;
     316             :         }
     317             :         else
     318             :         {
     319             :             // normal case: ':' found -> get prefix/suffix
     320       61340 :             xEntry->sPrefix = rAttrName.copy( 0L, nColonPos );
     321       61340 :             xEntry->sName = rAttrName.copy( nColonPos + 1L );
     322             :         }
     323             : 
     324       61778 :         if( pPrefix )
     325       19190 :             *pPrefix = xEntry->sPrefix;
     326       61778 :         if( pLocalName )
     327       61778 :             *pLocalName = xEntry->sName;
     328             : 
     329       61778 :         NameSpaceHash::const_iterator aIter = aNameHash.find( xEntry->sPrefix );
     330       61778 :         if ( aIter != aNameHash.end() )
     331             :         {
     332             :             // found: retrieve namespace key
     333       61217 :             nKey = xEntry->nKey = (*aIter).second->nKey;
     334       61217 :             if ( pNamespace )
     335       19879 :                 *pNamespace = (*aIter).second->sName;
     336             :         }
     337         561 :         else if ( xEntry->sPrefix == sXMLNS )
     338             :             // not found, but xmlns prefix: return xmlns 'namespace'
     339         459 :             nKey = xEntry->nKey = XML_NAMESPACE_XMLNS;
     340         102 :         else if( nColonPos == -1L )
     341             :             // not found, and no namespace: 'namespace' none
     342          80 :             nKey = xEntry->nKey = XML_NAMESPACE_NONE;
     343             : 
     344       61778 :         if (bCache)
     345             :         {
     346       60981 :             aNameCache.insert(NameSpaceHash::value_type(rAttrName, xEntry));
     347       61778 :         }
     348             :     }
     349             : 
     350      444130 :     return nKey;
     351             : }
     352             : 
     353        3142 : sal_uInt16 SvXMLNamespaceMap::GetFirstKey() const
     354             : {
     355        3142 :     return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey;
     356             : }
     357             : 
     358       29893 : sal_uInt16 SvXMLNamespaceMap::GetNextKey( sal_uInt16 nLastKey ) const
     359             : {
     360       29893 :     NameSpaceMap::const_iterator aIter = aNameMap.find ( nLastKey );
     361       29893 :     return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second->nKey;
     362             : }
     363             : 
     364             : 
     365             : // All methods after this are deprecated...
     366             : 
     367           0 : sal_uInt16 SvXMLNamespaceMap::GetIndexByKey( sal_uInt16 nKey ) const
     368             : {
     369           0 :     return nKey;
     370             : }
     371           0 : sal_uInt16 SvXMLNamespaceMap::GetFirstIndex() const
     372             : {
     373           0 :     return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey;
     374             : }
     375             : 
     376           0 : sal_uInt16 SvXMLNamespaceMap::GetNextIndex( sal_uInt16 nOldIdx ) const
     377             : {
     378           0 :     NameSpaceMap::const_iterator aIter = aNameMap.find ( nOldIdx );
     379           0 :     return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second->nKey;
     380             : }
     381             : 
     382           0 : bool SvXMLNamespaceMap::AddAtIndex( sal_uInt16 /*nIdx*/, const OUString& rPrefix,
     383             :                                     const OUString& rName, sal_uInt16 nKey )
     384             : {
     385           0 :     bool bRet = false;
     386             : 
     387           0 :     if( XML_NAMESPACE_UNKNOWN == nKey )
     388           0 :         nKey = GetKeyByName( rName );
     389             : 
     390             :     DBG_ASSERT( XML_NAMESPACE_NONE != nKey,
     391             :                 "SvXMLNamespaceMap::AddAtIndex: invalid namespace key" );
     392           0 :     if( XML_NAMESPACE_NONE != nKey && ! ( aNameHash.count ( rPrefix ) ) )
     393             :     {
     394           0 :         _Add( rPrefix, rName, nKey );
     395           0 :         bRet = true;
     396             :     }
     397           0 :     return bRet;
     398             : }
     399             : 
     400           0 : OUString SvXMLNamespaceMap::GetAttrNameByIndex( sal_uInt16 nIdx ) const
     401             : {
     402           0 :     return GetAttrNameByKey( nIdx );
     403             : }
     404             : 
     405          86 : OUString SvXMLNamespaceMap::GetQNameByIndex( sal_uInt16 nIdx,
     406             :                                            const OUString& rLocalName ) const
     407             : {
     408          86 :     return GetQNameByKey( nIdx, rLocalName );
     409             : }
     410             : 
     411          24 : const OUString& SvXMLNamespaceMap::GetPrefixByIndex( sal_uInt16 nIdx ) const
     412             : {
     413          24 :     NameSpaceMap::const_iterator aIter = aNameMap.find (nIdx);
     414          24 :     return (aIter != aNameMap.end()) ? (*aIter).second->sPrefix : sEmpty;
     415             : }
     416             : 
     417           8 : const OUString& SvXMLNamespaceMap::GetNameByIndex( sal_uInt16 nIdx ) const
     418             : {
     419           8 :     NameSpaceMap::const_iterator aIter = aNameMap.find (nIdx);
     420           8 :     return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty;
     421             : }
     422             : 
     423           0 : sal_uInt16 SvXMLNamespaceMap::GetIndexByPrefix( const OUString& rPrefix ) const
     424             : {
     425           0 :     NameSpaceHash::const_iterator aIter = aNameHash.find(rPrefix);
     426           0 :     return (aIter != aNameHash.end()) ? (*aIter).second->nKey : USHRT_MAX;
     427             : }
     428      389673 : sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName(
     429             :                             const OUString& rAttrName,
     430             :                             OUString *pLocalName,
     431             :                             sal_uInt16 /*nIdxGuess*/) const
     432             : {
     433      389673 :     return _GetKeyByAttrName( rAttrName, 0, pLocalName, 0 );
     434             : }
     435             : 
     436       53599 : sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName( const OUString& rAttrName,
     437             :                                             OUString *pPrefix,
     438             :                                             OUString *pLocalName,
     439             :                                             OUString *pNamespace,
     440             :                                             sal_uInt16 /*nIdxGuess*/ ) const
     441             : {
     442       53599 :     return _GetKeyByAttrName ( rAttrName, pPrefix, pLocalName, pNamespace );
     443             : }
     444             : 
     445        3403 : bool SvXMLNamespaceMap::NormalizeURI( OUString& rName )
     446             : {
     447             :     // try OASIS + W3 URI normalization
     448        3403 :     bool bSuccess = NormalizeOasisURN( rName );
     449        3403 :     if( ! bSuccess )
     450        3033 :         bSuccess = NormalizeW3URI( rName );
     451        3403 :     return bSuccess;
     452             : }
     453             : 
     454        3033 : bool SvXMLNamespaceMap::NormalizeW3URI( OUString& rName )
     455             : {
     456             :     // check if URI matches:
     457             :     // http://www.w3.org/[0-9]*/[:letter:]*
     458             :     //                   (year)/(WG name)
     459             :     // For the following WG/standards names:
     460             :     // - xforms
     461             : 
     462        3033 :     bool bSuccess = false;
     463        3033 :     const OUString sURIPrefix = GetXMLToken( XML_URI_W3_PREFIX );
     464        3033 :     if( rName.startsWith( sURIPrefix ) )
     465             :     {
     466        1053 :         const OUString sURISuffix = GetXMLToken( XML_URI_XFORMS_SUFFIX );
     467        1053 :         sal_Int32 nCompareFrom = rName.getLength() - sURISuffix.getLength();
     468        1053 :         if( rName.copy( nCompareFrom ).equals( sURISuffix ) )
     469             :         {
     470             :             // found W3 prefix, and xforms suffix
     471           0 :             rName = GetXMLToken( XML_N_XFORMS_1_0 );
     472           0 :             bSuccess = true;
     473        1053 :         }
     474             :     }
     475        3033 :     return bSuccess;
     476             : }
     477             : 
     478        3435 : bool SvXMLNamespaceMap::NormalizeOasisURN( OUString& rName )
     479             : {
     480             :     // #i38644#
     481             :     // we exported the wrong namespace for smil, so we correct this here on load
     482             :     // for older documents
     483        3435 :     if( IsXMLToken( rName, ::xmloff::token::XML_N_SVG ) )
     484             :     {
     485         180 :         rName = GetXMLToken( ::xmloff::token::XML_N_SVG_COMPAT );
     486         180 :         return true;
     487             :     }
     488        3255 :     else if( IsXMLToken( rName, ::xmloff::token::XML_N_FO ) )
     489             :     {
     490         134 :         rName = GetXMLToken( ::xmloff::token::XML_N_FO_COMPAT );
     491         134 :         return true;
     492             :     }
     493        6242 :     else if( IsXMLToken( rName, ::xmloff::token::XML_N_SMIL ) ||
     494        3121 :                IsXMLToken( rName, ::xmloff::token::XML_N_SMIL_OLD )  )
     495             :     {
     496           4 :         rName = GetXMLToken( ::xmloff::token::XML_N_SMIL_COMPAT );
     497           4 :         return true;
     498             :     }
     499             : 
     500             : 
     501             :     // Check if URN matches
     502             :     // :urn:oasis:names:tc:[^:]*:xmlns:[^:]*:1.[^:]*
     503             :     //                     |---|       |---| |-----|
     504             :     //                     TC-Id      Sub-Id Version
     505             : 
     506        3117 :     sal_Int32 nNameLen = rName.getLength();
     507             :     // :urn:oasis:names:tc.*
     508        3117 :     const OUString& rOasisURN = GetXMLToken( XML_URN_OASIS_NAMES_TC );
     509        3117 :     if( !rName.startsWith( rOasisURN ) )
     510        3060 :         return false;
     511             : 
     512             :     // :urn:oasis:names:tc:.*
     513          57 :     sal_Int32 nPos = rOasisURN.getLength();
     514          57 :     if( nPos >= nNameLen || rName[nPos] != ':' )
     515           0 :         return false;
     516             : 
     517             :     // :urn:oasis:names:tc:[^:]:.*
     518          57 :     sal_Int32 nTCIdStart = nPos+1;
     519          57 :     sal_Int32 nTCIdEnd = rName.indexOf( ':', nTCIdStart );
     520          57 :     if( -1 == nTCIdEnd )
     521           0 :         return false;
     522             : 
     523             :     // :urn:oasis:names:tc:[^:]:xmlns.*
     524          57 :     nPos = nTCIdEnd + 1;
     525          57 :     OUString sTmp( rName.copy( nPos ) );
     526          57 :     const OUString& rXMLNS = GetXMLToken( XML_XMLNS );
     527          57 :     if( !sTmp.startsWith( rXMLNS ) )
     528           0 :         return false;
     529             : 
     530             :     // :urn:oasis:names:tc:[^:]:xmlns:.*
     531          57 :     nPos += rXMLNS.getLength();
     532          57 :     if( nPos >= nNameLen || rName[nPos] != ':' )
     533           0 :         return false;
     534             : 
     535             :     // :urn:oasis:names:tc:[^:]:xmlns:[^:]*:.*
     536          57 :     nPos = rName.indexOf( ':', nPos+1 );
     537          57 :     if( -1 == nPos )
     538           0 :         return false;
     539             : 
     540             :     // :urn:oasis:names:tc:[^:]:xmlns:[^:]*:[^:][^:][^:][^:]*
     541          57 :     sal_Int32 nVersionStart = nPos+1;
     542         114 :     if( nVersionStart+2 >= nNameLen ||
     543          57 :         -1 != rName.indexOf( ':', nVersionStart ) )
     544           0 :         return false;
     545             : 
     546             :     // :urn:oasis:names:tc:[^:]:xmlns:[^:]*:1\.[^:][^:]*
     547          57 :     if( rName[nVersionStart] != '1' || rName[nVersionStart+1] != '.' )
     548           0 :         return false;
     549             : 
     550             :     // replace [tcid] with current TCID and version with current version.
     551             : 
     552         228 :     rName = rName.copy( 0, nTCIdStart ) +
     553         228 :             GetXMLToken( XML_OPENDOCUMENT ) +
     554         228 :             rName.copy( nTCIdEnd, nVersionStart-nTCIdEnd ) +
     555         114 :             GetXMLToken( XML_1_0 );
     556             : 
     557          57 :     return true;
     558             : }
     559             : 
     560             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10