LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/core - nmspmap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 209 251 83.3 %
Date: 2013-07-09 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        4570 : SvXMLNamespaceMap::SvXMLNamespaceMap()
      50        4570 : : sXMLNS( GetXMLToken ( XML_XMLNS ) )
      51             : {
      52        4570 : }
      53             : 
      54        3387 : SvXMLNamespaceMap::SvXMLNamespaceMap( const SvXMLNamespaceMap& rMap )
      55        3387 : : sXMLNS( GetXMLToken ( XML_XMLNS ) )
      56             : {
      57        3387 :     aNameHash = rMap.aNameHash;
      58        3387 :     aNameMap  = rMap.aNameMap;
      59        3387 : }
      60             : 
      61           0 : void SvXMLNamespaceMap::operator=( const SvXMLNamespaceMap& rMap )
      62             : {
      63           0 :     aNameHash = rMap.aNameHash;
      64           0 :     aNameMap = rMap.aNameMap;
      65           0 : }
      66             : 
      67        7759 : SvXMLNamespaceMap::~SvXMLNamespaceMap()
      68             : {
      69        7759 : }
      70             : 
      71        3603 : int SvXMLNamespaceMap::operator ==( const SvXMLNamespaceMap& rCmp ) const
      72             : {
      73        3603 :     return static_cast < int > (aNameHash == rCmp.aNameHash);
      74             : }
      75             : 
      76       58975 : sal_uInt16 SvXMLNamespaceMap::_Add( const OUString& rPrefix, const OUString &rName, sal_uInt16 nKey )
      77             : {
      78       58975 :     if( XML_NAMESPACE_UNKNOWN == nKey )
      79             :     {
      80             :         // create a new unique key with UNKNOWN flag set
      81        3011 :         nKey = XML_NAMESPACE_UNKNOWN_FLAG;
      82             :         do
      83             :         {
      84       15955 :             NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
      85       15955 :             if( aIter == aNameMap.end() )
      86        3011 :                 break;
      87       12944 :             nKey++;
      88             :         }
      89       12944 :         while ( true );
      90             :     }
      91       58975 :     ::rtl::Reference<NameSpaceEntry> pEntry(new NameSpaceEntry);
      92       58975 :     pEntry->sName   = rName;
      93       58975 :     pEntry->nKey    = nKey;
      94       58975 :     pEntry->sPrefix = rPrefix;
      95       58975 :     aNameHash[ rPrefix ] = pEntry;
      96       58975 :     aNameMap [ nKey ]    = pEntry;
      97       58975 :     return nKey;
      98             : }
      99             : 
     100       49814 : sal_uInt16 SvXMLNamespaceMap::Add( const OUString& rPrefix, const OUString& rName,
     101             :                                sal_uInt16 nKey )
     102             : {
     103       49814 :     if( XML_NAMESPACE_UNKNOWN == nKey )
     104        3013 :         nKey = GetKeyByName( rName );
     105             : 
     106             :     DBG_ASSERT( XML_NAMESPACE_NONE != nKey,
     107             :                 "SvXMLNamespaceMap::Add: invalid namespace key" );
     108             : 
     109       49814 :     if( XML_NAMESPACE_NONE == nKey )
     110           0 :         return USHRT_MAX;
     111             : 
     112       49814 :     if ( aNameHash.find ( rPrefix ) == aNameHash.end() )
     113       48211 :         nKey = _Add( rPrefix, rName, nKey );
     114             : 
     115       49814 :     return nKey;
     116             : }
     117             : 
     118       15473 : sal_uInt16 SvXMLNamespaceMap::AddIfKnown( const OUString& rPrefix, const OUString& rName )
     119             : {
     120       15473 :     sal_uInt16 nKey = GetKeyByName( rName );
     121             : 
     122             :     DBG_ASSERT( XML_NAMESPACE_NONE != nKey,
     123             :                 "SvXMLNamespaceMap::AddIfKnown: invalid namespace key" );
     124             : 
     125       15473 :     if( XML_NAMESPACE_NONE == nKey )
     126           0 :         return XML_NAMESPACE_UNKNOWN;
     127             : 
     128       15473 :     if( XML_NAMESPACE_UNKNOWN != nKey )
     129             :     {
     130       12003 :         NameSpaceHash::const_iterator aIter = aNameHash.find( rPrefix );
     131       12003 :         if( aIter == aNameHash.end() || (*aIter).second->sName != rName )
     132       10764 :             nKey = _Add( rPrefix, rName, nKey );
     133             :     }
     134             : 
     135       15473 :     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       18511 : sal_uInt16 SvXMLNamespaceMap::GetKeyByName( const OUString& rName ) const
     146             : {
     147       18511 :     sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN;
     148       18511 :     NameSpaceHash::const_iterator aIter = aNameHash.begin(), aEnd = aNameHash.end();
     149      503080 :     while (aIter != aEnd )
     150             :     {
     151      478069 :         if ((*aIter).second->sName == rName)
     152             :         {
     153       12011 :             nKey = (*aIter).second->nKey;
     154       12011 :             break;
     155             :         }
     156      466058 :         ++aIter;
     157             :     }
     158       18511 :     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        9309 : const OUString& SvXMLNamespaceMap::GetNameByKey( sal_uInt16 nKey ) const
     168             : {
     169        9309 :     NameSpaceMap::const_iterator aIter = aNameMap.find (nKey);
     170        9309 :     return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty;
     171             : }
     172             : 
     173       10442 : OUString SvXMLNamespaceMap::GetAttrNameByKey( sal_uInt16 nKey ) const
     174             : {
     175       10442 :     OUStringBuffer sAttrName;
     176       10442 :     NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
     177       10442 :     if (aIter != aNameMap.end())
     178             :     {
     179       10442 :         sAttrName.append( sXMLNS  );
     180       10442 :         const OUString & prefix( (*aIter).second->sPrefix );
     181       10442 :         if (!prefix.isEmpty()) // not default namespace
     182             :         {
     183       10145 :             sAttrName.append( sal_Unicode(':') );
     184       10145 :             sAttrName.append( prefix );
     185             :         }
     186             :     }
     187       10442 :     return sAttrName.makeStringAndClear();
     188             : }
     189             : 
     190      107749 : OUString SvXMLNamespaceMap::GetQNameByKey( sal_uInt16 nKey,
     191             :                             const OUString& rLocalName,
     192             :                             sal_Bool bCache) const
     193             : {
     194             :     // We always want to return at least the rLocalName...
     195             : 
     196      107749 :     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( sal_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 ( sal_Unicode(':') );
     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 ( sal_Unicode(':') );
     223          56 :             sQName.append ( rLocalName );
     224          56 :             return sQName.makeStringAndClear();
     225             :         }
     226             :         default:
     227             :         {
     228      107656 :             QNameCache::const_iterator aQCacheIter;
     229      107656 :             if (bCache)
     230      107597 :                 aQCacheIter = aQNameCache.find ( QNamePair ( nKey, rLocalName ) );
     231             :             else
     232          59 :                 aQCacheIter = aQNameCache.end();
     233      107656 :             if ( aQCacheIter != aQNameCache.end() )
     234       91688 :                 return (*aQCacheIter).second;
     235             :             else
     236             :             {
     237       15968 :                 NameSpaceMap::const_iterator aIter = aNameMap.find ( nKey );
     238       15968 :                 if ( aIter != aNameMap.end() )
     239             :                 {
     240       15968 :                     OUStringBuffer sQName;
     241             :                     // ...if it's in our map, make the prefix
     242       15968 :                     const OUString & prefix( (*aIter).second->sPrefix );
     243       15968 :                     if (!prefix.isEmpty()) // not default namespace
     244             :                     {
     245       12772 :                         sQName.append( prefix );
     246       12772 :                         sQName.append( sal_Unicode(':') );
     247             :                     }
     248       15968 :                     sQName.append ( rLocalName );
     249       15968 :                     if (bCache)
     250             :                     {
     251       15909 :                         OUString sString(sQName.makeStringAndClear());
     252             :                         aQNameCache.insert(
     253             :                             QNameCache::value_type(
     254       15909 :                                 QNamePair(nKey, rLocalName), sString));
     255       15909 :                         return sString;
     256             :                     }
     257             :                     else
     258          59 :                         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( sal_False, "SvXMLNamespaceMap::GetQNameByKey: invalid namespace key" );
     264           0 :                     return rLocalName;
     265             :                 }
     266             :             }
     267             :         }
     268             :     }
     269             : }
     270             : 
     271          15 : sal_uInt16 SvXMLNamespaceMap::_GetKeyByAttrName(
     272             :                             const OUString& rAttrName,
     273             :                             OUString *pLocalName,
     274             :                             sal_Bool bCache) const
     275             : {
     276          15 :     return _GetKeyByAttrName( rAttrName, 0, pLocalName, 0, bCache );
     277             : }
     278             : 
     279      235365 : sal_uInt16 SvXMLNamespaceMap::_GetKeyByAttrName( const OUString& rAttrName,
     280             :                                             OUString *pPrefix,
     281             :                                             OUString *pLocalName,
     282             :                                             OUString *pNamespace,
     283             :                                             sal_Bool bCache) const
     284             : {
     285      235365 :     sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN;
     286             : 
     287      235365 :     NameSpaceHash::const_iterator it;
     288      235365 :     if (bCache)
     289      234929 :         it = aNameCache.find ( rAttrName );
     290             :     else
     291         436 :         it = aNameCache.end();
     292      235365 :     if ( it != aNameCache.end() )
     293             :     {
     294      203500 :         const NameSpaceEntry &rEntry = *((*it).second);
     295      203500 :         if ( pPrefix )
     296        9456 :             *pPrefix = rEntry.sPrefix;
     297      203500 :         if ( pLocalName )
     298      203497 :             *pLocalName = rEntry.sName;
     299      203500 :         nKey = rEntry.nKey;
     300      203500 :         if ( pNamespace )
     301             :         {
     302        9456 :             NameSpaceMap::const_iterator aMapIter = aNameMap.find (nKey);
     303        9456 :             *pNamespace = aMapIter != aNameMap.end() ? (*aMapIter).second->sName : sEmpty;
     304             :         }
     305             :     }
     306             :     else
     307             :     {
     308       31865 :     rtl::Reference<NameSpaceEntry> xEntry(new NameSpaceEntry());
     309             : 
     310       31865 :         sal_Int32 nColonPos = rAttrName.indexOf( sal_Unicode(':') );
     311       31865 :         if( -1L == nColonPos )
     312             :         {
     313             :             // case: no ':' found -> default namespace
     314         245 :             xEntry->sPrefix = OUString();
     315         245 :             xEntry->sName = rAttrName;
     316             :         }
     317             :         else
     318             :         {
     319             :             // normal case: ':' found -> get prefix/suffix
     320       31620 :             xEntry->sPrefix = rAttrName.copy( 0L, nColonPos );
     321       31620 :             xEntry->sName = rAttrName.copy( nColonPos + 1L );
     322             :         }
     323             : 
     324       31865 :         if( pPrefix )
     325        7851 :             *pPrefix = xEntry->sPrefix;
     326       31865 :         if( pLocalName )
     327       31865 :             *pLocalName = xEntry->sName;
     328             : 
     329       31865 :         NameSpaceHash::const_iterator aIter = aNameHash.find( xEntry->sPrefix );
     330       31865 :         if ( aIter != aNameHash.end() )
     331             :         {
     332             :             // found: retrieve namespace key
     333       30855 :             nKey = xEntry->nKey = (*aIter).second->nKey;
     334       30855 :             if ( pNamespace )
     335        8238 :                 *pNamespace = (*aIter).second->sName;
     336             :         }
     337        1010 :         else if ( xEntry->sPrefix == sXMLNS )
     338             :             // not found, but xmlns prefix: return xmlns 'namespace'
     339         975 :             nKey = xEntry->nKey = XML_NAMESPACE_XMLNS;
     340          35 :         else if( nColonPos == -1L )
     341             :             // not found, and no namespace: 'namespace' none
     342          21 :             nKey = xEntry->nKey = XML_NAMESPACE_NONE;
     343             : 
     344       31865 :         if (bCache)
     345             :         {
     346       31429 :             aNameCache.insert(NameSpaceHash::value_type(rAttrName, xEntry));
     347       31865 :         }
     348             :     }
     349             : 
     350      235365 :     return nKey;
     351             : }
     352             : 
     353         913 : sal_uInt16 SvXMLNamespaceMap::GetFirstKey() const
     354             : {
     355         913 :     return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey;
     356             : }
     357             : 
     358        9641 : sal_uInt16 SvXMLNamespaceMap::GetNextKey( sal_uInt16 nLastKey ) const
     359             : {
     360        9641 :     NameSpaceMap::const_iterator aIter = aNameMap.find ( nLastKey );
     361        9641 :     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 : sal_Bool SvXMLNamespaceMap::AddAtIndex( sal_uInt16 /*nIdx*/, const OUString& rPrefix,
     383             :                                     const OUString& rName, sal_uInt16 nKey )
     384             : {
     385           0 :     sal_Bool bRet = sal_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 = sal_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          52 : OUString SvXMLNamespaceMap::GetQNameByIndex( sal_uInt16 nIdx,
     406             :                                            const OUString& rLocalName ) const
     407             : {
     408          52 :     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      217622 : sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName(
     429             :                             const OUString& rAttrName,
     430             :                             OUString *pLocalName,
     431             :                             sal_uInt16 /*nIdxGuess*/) const
     432             : {
     433      217622 :     return _GetKeyByAttrName( rAttrName, 0, pLocalName, 0 );
     434             : }
     435             : 
     436       17246 : sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName( const OUString& rAttrName,
     437             :                                             OUString *pPrefix,
     438             :                                             OUString *pLocalName,
     439             :                                             OUString *pNamespace,
     440             :                                             sal_uInt16 /*nIdxGuess*/ ) const
     441             : {
     442       17246 :     return _GetKeyByAttrName ( rAttrName, pPrefix, pLocalName, pNamespace );
     443             : }
     444             : 
     445        2762 : sal_Bool SvXMLNamespaceMap::NormalizeURI( OUString& rName )
     446             : {
     447             :     // try OASIS + W3 URI normalization
     448        2762 :     sal_Bool bSuccess = NormalizeOasisURN( rName );
     449        2762 :     if( ! bSuccess )
     450        2337 :         bSuccess = NormalizeW3URI( rName );
     451        2762 :     return bSuccess;
     452             : }
     453             : 
     454        2337 : sal_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        2337 :     sal_Bool bSuccess = sal_False;
     463        2337 :     const OUString sURIPrefix = GetXMLToken( XML_URI_W3_PREFIX );
     464        2337 :     if( rName.startsWith( sURIPrefix ) )
     465             :     {
     466         598 :         const OUString sURISuffix = GetXMLToken( XML_URI_XFORMS_SUFFIX );
     467         598 :         sal_Int32 nCompareFrom = rName.getLength() - sURISuffix.getLength();
     468         598 :         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 = sal_True;
     473         598 :         }
     474             :     }
     475        2337 :     return bSuccess;
     476             : }
     477             : 
     478        3069 : sal_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        3069 :     if( IsXMLToken( rName, ::xmloff::token::XML_N_SVG ) )
     484             :     {
     485         196 :         rName = GetXMLToken( ::xmloff::token::XML_N_SVG_COMPAT );
     486         196 :         return sal_True;
     487             :     }
     488        2873 :     else if( IsXMLToken( rName, ::xmloff::token::XML_N_FO ) )
     489             :     {
     490         141 :         rName = GetXMLToken( ::xmloff::token::XML_N_FO_COMPAT );
     491         141 :         return sal_True;
     492             :     }
     493        5464 :     else if( IsXMLToken( rName, ::xmloff::token::XML_N_SMIL ) ||
     494        2732 :                IsXMLToken( rName, ::xmloff::token::XML_N_SMIL_OLD )  )
     495             :     {
     496           2 :         rName = GetXMLToken( ::xmloff::token::XML_N_SMIL_COMPAT );
     497           2 :         return sal_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        2730 :     sal_Int32 nNameLen = rName.getLength();
     507             :     // :urn:oasis:names:tc.*
     508        2730 :     const OUString& rOasisURN = GetXMLToken( XML_URN_OASIS_NAMES_TC );
     509        2730 :     if( !rName.startsWith( rOasisURN ) )
     510        2587 :         return sal_False;
     511             : 
     512             :     // :urn:oasis:names:tc:.*
     513         143 :     sal_Int32 nPos = rOasisURN.getLength();
     514         143 :     if( nPos >= nNameLen || rName[nPos] != ':' )
     515           0 :         return sal_False;
     516             : 
     517             :     // :urn:oasis:names:tc:[^:]:.*
     518         143 :     sal_Int32 nTCIdStart = nPos+1;
     519         143 :     sal_Int32 nTCIdEnd = rName.indexOf( ':', nTCIdStart );
     520         143 :     if( -1 == nTCIdEnd )
     521           0 :         return sal_False;
     522             : 
     523             :     // :urn:oasis:names:tc:[^:]:xmlns.*
     524         143 :     nPos = nTCIdEnd + 1;
     525         143 :     OUString sTmp( rName.copy( nPos ) );
     526         143 :     const OUString& rXMLNS = GetXMLToken( XML_XMLNS );
     527         143 :     if( !sTmp.startsWith( rXMLNS ) )
     528           0 :         return sal_False;
     529             : 
     530             :     // :urn:oasis:names:tc:[^:]:xmlns:.*
     531         143 :     nPos += rXMLNS.getLength();
     532         143 :     if( nPos >= nNameLen || rName[nPos] != ':' )
     533           0 :         return sal_False;
     534             : 
     535             :     // :urn:oasis:names:tc:[^:]:xmlns:[^:]*:.*
     536         143 :     nPos = rName.indexOf( ':', nPos+1 );
     537         143 :     if( -1 == nPos )
     538           0 :         return sal_False;
     539             : 
     540             :     // :urn:oasis:names:tc:[^:]:xmlns:[^:]*:[^:][^:][^:][^:]*
     541         143 :     sal_Int32 nVersionStart = nPos+1;
     542         286 :     if( nVersionStart+2 >= nNameLen ||
     543         143 :         -1 != rName.indexOf( ':', nVersionStart ) )
     544           0 :         return sal_False;
     545             : 
     546             :     // :urn:oasis:names:tc:[^:]:xmlns:[^:]*:1\.[^:][^:]*
     547         143 :     if( rName[nVersionStart] != '1' || rName[nVersionStart+1] != '.' )
     548           0 :         return sal_False;
     549             : 
     550             :     // replace [tcid] with current TCID and version with current version.
     551         286 :     OUStringBuffer aNewName( nNameLen +20 );
     552         143 :     aNewName.append( rName.copy( 0, nTCIdStart ) );
     553         143 :     aNewName.append( GetXMLToken( XML_OPENDOCUMENT ) );
     554         143 :     aNewName.append( rName.copy( nTCIdEnd, nVersionStart-nTCIdEnd ) );
     555         143 :     aNewName.append( GetXMLToken( XML_1_0 ) );
     556             : 
     557         143 :     rName = aNewName.makeStringAndClear();
     558             : 
     559         286 :     return sal_True;
     560             : }
     561             : 
     562             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10