LCOV - code coverage report
Current view: top level - xmloff/source/transform - TransformerBase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 430 704 61.1 %
Date: 2012-08-25 Functions: 31 39 79.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 446 1126 39.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <rtl/ref.hxx>
      30                 :            : #include <rtl/ustrbuf.hxx>
      31                 :            : #include <com/sun/star/i18n/XCharacterClassification.hpp>
      32                 :            : #include <com/sun/star/i18n/UnicodeType.hpp>
      33                 :            : #include <com/sun/star/util/MeasureUnit.hpp>
      34                 :            : #include <sax/tools/converter.hxx>
      35                 :            : #include <comphelper/processfactory.hxx>
      36                 :            : #include <xmloff/nmspmap.hxx>
      37                 :            : #include "xmloff/xmlnmspe.hxx"
      38                 :            : #include "IgnoreTContext.hxx"
      39                 :            : #include "RenameElemTContext.hxx"
      40                 :            : #include "ProcAttrTContext.hxx"
      41                 :            : #include "ProcAddAttrTContext.hxx"
      42                 :            : #include "MergeElemTContext.hxx"
      43                 :            : #include "CreateElemTContext.hxx"
      44                 :            : #include "MutableAttrList.hxx"
      45                 :            : #include "TransformerActions.hxx"
      46                 :            : #include "ElemTransformerAction.hxx"
      47                 :            : #include "PropertyActionsOOo.hxx"
      48                 :            : #include "TransformerTokenMap.hxx"
      49                 :            : 
      50                 :            : #include "TransformerBase.hxx"
      51                 :            : #include "TContextVector.hxx"
      52                 :            : 
      53                 :            : using ::rtl::OUString;
      54                 :            : using ::rtl::OUStringBuffer;
      55                 :            : using namespace ::osl;
      56                 :            : using namespace ::xmloff::token;
      57                 :            : using namespace ::com::sun::star;
      58                 :            : using namespace ::com::sun::star::uno;
      59                 :            : using namespace ::com::sun::star::beans;
      60                 :            : using namespace ::com::sun::star::lang;
      61                 :            : using namespace ::com::sun::star::i18n;
      62                 :            : using namespace ::com::sun::star::xml::sax;
      63                 :            : 
      64                 :            : namespace
      65                 :            : {
      66                 :         12 : bool lcl_ConvertAttr( OUString & rOutAttribute, sal_Int32 nParam )
      67                 :            : {
      68                 :         12 :     bool bResult = false;
      69                 :            :     enum XMLTokenEnum eTokenToRename =
      70                 :         12 :         static_cast< enum XMLTokenEnum >( nParam & 0xffff );
      71   [ +  -  +  + ]:         24 :     if( eTokenToRename != XML_TOKEN_INVALID &&
                 [ +  + ]
      72                 :         12 :         IsXMLToken( rOutAttribute, eTokenToRename ))
      73                 :            :     {
      74                 :            :         enum XMLTokenEnum eReplacementToken =
      75                 :          6 :             static_cast< enum XMLTokenEnum >( nParam >> 16 );
      76                 :          6 :         rOutAttribute = GetXMLToken( eReplacementToken );
      77                 :          6 :         bResult = true;
      78                 :            :     }
      79                 :         12 :     return bResult;
      80                 :            : }
      81                 :            : } // anonymous namespace
      82                 :            : 
      83                 :      13503 : XMLTransformerContext *XMLTransformerBase::CreateContext( sal_uInt16 nPrefix,
      84                 :            :     const OUString& rLocalName, const OUString& rQName )
      85                 :            : {
      86                 :      13503 :     XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
      87                 :            :     XMLTransformerActions::const_iterator aIter =
      88         [ +  - ]:      13503 :         GetElemActions().find( aKey );
      89                 :            : 
      90 [ +  + ][ +  - ]:      13503 :     if( !(aIter == GetElemActions().end()) )
      91                 :            :     {
      92         [ +  - ]:       3713 :         sal_uInt32 nActionType = (*aIter).second.m_nActionType;
      93         [ +  + ]:       3713 :         if( (nActionType & XML_ETACTION_USER_DEFINED) != 0 )
      94                 :            :         {
      95                 :            :             XMLTransformerContext *pContext =
      96         [ +  - ]:       2299 :                 CreateUserDefinedContext( (*aIter).second,
      97         [ +  - ]:       2299 :                                     rQName );
      98                 :            :             OSL_ENSURE( pContext && !pContext->IsPersistent(),
      99                 :            :                         "unknown or not persistent action" );
     100                 :       2299 :             return pContext;
     101                 :            :         }
     102                 :            : 
     103   [ +  -  +  -  :       1414 :         switch( nActionType )
          +  +  -  -  +  
             +  +  -  - ]
     104                 :            :         {
     105                 :            :         case XML_ETACTION_COPY_CONTENT:
     106                 :            :             return new XMLIgnoreTransformerContext( *this, rQName, sal_False,
     107 [ +  - ][ +  - ]:         12 :                                                 sal_False );
     108                 :            :         case XML_ETACTION_COPY:
     109 [ #  # ][ #  # ]:          0 :             return new XMLTransformerContext( *this, rQName );
     110                 :            :         case XML_ETACTION_RENAME_ELEM:
     111                 :            :             return new XMLRenameElemTransformerContext( *this, rQName,
     112         [ +  - ]:         80 :                     (*aIter).second.GetQNamePrefixFromParam1(),
     113 [ +  - ][ +  - ]:         80 :                     (*aIter).second.GetQNameTokenFromParam1() );
                 [ +  - ]
     114                 :            :         case XML_ETACTION_RENAME_ELEM_ADD_ATTR:
     115                 :            :             return new XMLRenameElemTransformerContext( *this, rQName,
     116         [ #  # ]:          0 :                     (*aIter).second.GetQNamePrefixFromParam1(),
     117         [ #  # ]:          0 :                     (*aIter).second.GetQNameTokenFromParam1(),
     118         [ #  # ]:          0 :                     (*aIter).second.GetQNamePrefixFromParam2(),
     119         [ #  # ]:          0 :                     (*aIter).second.GetQNameTokenFromParam2(),
     120 [ #  # ][ #  # ]:          0 :                        static_cast< XMLTokenEnum >( (*aIter).second.m_nParam3 ) );
                 [ #  # ]
     121                 :            :         case XML_ETACTION_RENAME_ELEM_PROC_ATTRS:
     122                 :            :             return new XMLProcAttrTransformerContext( *this, rQName,
     123         [ +  - ]:        176 :                     (*aIter).second.GetQNamePrefixFromParam1(),
     124         [ +  - ]:        176 :                     (*aIter).second.GetQNameTokenFromParam1(),
     125 [ +  - ][ +  - ]:        176 :                        static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
                 [ +  - ]
     126                 :            :         case XML_ETACTION_RENAME_ELEM_ADD_PROC_ATTR:
     127                 :            :             return new XMLProcAddAttrTransformerContext( *this, rQName,
     128         [ +  - ]:         12 :                     (*aIter).second.GetQNamePrefixFromParam1(),
     129         [ +  - ]:         12 :                     (*aIter).second.GetQNameTokenFromParam1(),
     130                 :            :                        static_cast< sal_uInt16 >(
     131         [ +  - ]:         12 :                         (*aIter).second.m_nParam3  >> 16 ),
     132         [ +  - ]:         12 :                     (*aIter).second.GetQNamePrefixFromParam2(),
     133         [ +  - ]:         12 :                     (*aIter).second.GetQNameTokenFromParam2(),
     134                 :            :                        static_cast< XMLTokenEnum >(
     135 [ +  - ][ +  - ]:         24 :                         (*aIter).second.m_nParam3 & 0xffff ) );
                 [ +  - ]
     136                 :            :         case XML_ETACTION_RENAME_ELEM_COND:
     137                 :            :             {
     138         [ #  # ]:          0 :                 const XMLTransformerContext *pCurrent = GetCurrentContext();
     139         [ #  # ]:          0 :                 if( pCurrent->HasQName(
     140         [ #  # ]:          0 :                             (*aIter).second.GetQNamePrefixFromParam2(),
     141 [ #  # ][ #  # ]:          0 :                             (*aIter).second.GetQNameTokenFromParam2() ) )
     142                 :            :                     return new XMLRenameElemTransformerContext( *this, rQName,
     143         [ #  # ]:          0 :                             (*aIter).second.GetQNamePrefixFromParam1(),
     144 [ #  # ][ #  # ]:          0 :                             (*aIter).second.GetQNameTokenFromParam1() );
                 [ #  # ]
     145                 :            :             }
     146                 :          0 :             break;
     147                 :            :         case XML_ETACTION_RENAME_ELEM_PROC_ATTRS_COND:
     148                 :            :             {
     149         [ #  # ]:          0 :                 const XMLTransformerContext *pCurrent = GetCurrentContext();
     150         [ #  # ]:          0 :                 if( pCurrent->HasQName(
     151         [ #  # ]:          0 :                             (*aIter).second.GetQNamePrefixFromParam3(),
     152 [ #  # ][ #  # ]:          0 :                             (*aIter).second.GetQNameTokenFromParam3() ) )
     153                 :            :                     return new XMLProcAttrTransformerContext( *this, rQName,
     154         [ #  # ]:          0 :                             (*aIter).second.GetQNamePrefixFromParam1(),
     155         [ #  # ]:          0 :                             (*aIter).second.GetQNameTokenFromParam1(),
     156 [ #  # ][ #  # ]:          0 :                             static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
                 [ #  # ]
     157                 :            :                 else
     158                 :            :                     return new XMLProcAttrTransformerContext( *this, rQName,
     159 [ #  # ][ #  # ]:          0 :                             static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
                 [ #  # ]
     160                 :            :             }
     161                 :            :         case XML_ETACTION_PROC_ATTRS:
     162                 :            :             return new XMLProcAttrTransformerContext( *this, rQName,
     163 [ +  - ][ +  - ]:       1093 :                        static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
                 [ +  - ]
     164                 :            :         case XML_ETACTION_PROC_ATTRS_COND:
     165                 :            :             {
     166         [ +  - ]:         36 :                 const XMLTransformerContext *pCurrent = GetCurrentContext();
     167         [ +  - ]:         36 :                 if( pCurrent->HasQName(
     168         [ +  - ]:         36 :                             (*aIter).second.GetQNamePrefixFromParam1(),
     169 [ +  - ][ +  - ]:         72 :                             (*aIter).second.GetQNameTokenFromParam1() ) )
     170                 :            :                     return new XMLProcAttrTransformerContext( *this, rQName,
     171 [ +  - ][ +  - ]:         36 :                             static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
                 [ +  - ]
     172                 :            :             }
     173                 :          0 :             break;
     174                 :            :         case XML_ETACTION_MOVE_ATTRS_TO_ELEMS:
     175                 :            :             return new XMLCreateElemTransformerContext( *this, rQName,
     176 [ +  - ][ +  - ]:          5 :                        static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
                 [ +  - ]
     177                 :            :         case XML_ETACTION_MOVE_ELEMS_TO_ATTRS:
     178                 :            :             return new XMLMergeElemTransformerContext( *this, rQName,
     179 [ #  # ][ #  # ]:          0 :                        static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
                 [ #  # ]
     180                 :            :         default:
     181                 :            :             OSL_ENSURE( !this, "unknown action" );
     182                 :          0 :             break;
     183                 :            :         }
     184                 :            :     }
     185                 :            : 
     186                 :            :     // default is copying
     187 [ +  - ][ +  - ]:      13503 :     return new XMLTransformerContext( *this, rQName );
     188                 :            : }
     189                 :            : 
     190                 :          0 : XMLTransformerActions *XMLTransformerBase::GetUserDefinedActions( sal_uInt16 )
     191                 :            : {
     192                 :          0 :     return 0;
     193                 :            : }
     194                 :            : 
     195                 :        182 : XMLTransformerBase::XMLTransformerBase( XMLTransformerActionInit *pInit,
     196                 :            :                                     ::xmloff::token::XMLTokenEnum *pTKMapInit )
     197                 :            :     throw () :
     198         [ +  - ]:        182 :     m_pNamespaceMap( new SvXMLNamespaceMap ),
     199         [ +  - ]:        182 :     m_pReplaceNamespaceMap( new SvXMLNamespaceMap ),
     200         [ +  - ]:        182 :     m_pContexts( new XMLTransformerContextVector ),
     201         [ +  - ]:        182 :     m_pElemActions( new XMLTransformerActions( pInit ) ),
     202 [ +  - ][ +  - ]:        910 :     m_pTokenMap( new XMLTransformerTokenMap( pTKMapInit ) )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     203                 :            : {
     204 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
                 [ +  - ]
     205 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
                 [ +  - ]
     206 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
                 [ +  - ]
     207 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
                 [ +  - ]
     208 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
                 [ +  - ]
     209 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_OOOW), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
                 [ +  - ]
     210 [ +  - ][ +  - ]:        182 :     GetNamespaceMap().Add( GetXMLToken(XML_NP_OOOC), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
                 [ +  - ]
     211                 :        182 : }
     212                 :            : 
     213                 :        182 : XMLTransformerBase::~XMLTransformerBase() throw ()
     214                 :            : {
     215         [ +  - ]:        182 :     ResetTokens();
     216                 :            : 
     217 [ +  - ][ +  - ]:        182 :     delete m_pNamespaceMap;
     218 [ +  - ][ +  - ]:        182 :     delete m_pReplaceNamespaceMap;
     219         [ +  - ]:        182 :     delete m_pContexts;
     220 [ +  - ][ +  - ]:        182 :     delete m_pElemActions;
     221 [ +  - ][ +  - ]:        182 :     delete m_pTokenMap;
     222         [ -  + ]:        182 : }
     223                 :            : 
     224                 :        133 : void SAL_CALL XMLTransformerBase::startDocument( void )
     225                 :            :     throw( SAXException, RuntimeException )
     226                 :            : {
     227                 :        133 :     m_xHandler->startDocument();
     228                 :        133 : }
     229                 :            : 
     230                 :        133 : void SAL_CALL XMLTransformerBase::endDocument( void )
     231                 :            :     throw( SAXException, RuntimeException)
     232                 :            : {
     233                 :        133 :     m_xHandler->endDocument();
     234                 :        133 : }
     235                 :            : 
     236                 :      15509 : void SAL_CALL XMLTransformerBase::startElement( const OUString& rName,
     237                 :            :                                          const Reference< XAttributeList >& rAttrList )
     238                 :            :     throw(SAXException, RuntimeException)
     239                 :            : {
     240                 :      15509 :     SvXMLNamespaceMap *pRewindMap = 0;
     241                 :            : 
     242                 :      15509 :     bool bRect = rName == "presentation:show-shape";
     243                 :            :     (void)bRect;
     244                 :            : 
     245                 :            :     // Process namespace attributes. This must happen before creating the
     246                 :            :     // context, because namespace decaration apply to the element name itself.
     247                 :      15509 :     XMLMutableAttributeList *pMutableAttrList = 0;
     248                 :      15509 :     Reference< XAttributeList > xAttrList( rAttrList );
     249 [ +  - ][ +  - ]:      15509 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
     250         [ +  + ]:      44669 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     251                 :            :     {
     252 [ +  - ][ +  - ]:      29160 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     253   [ +  -  +  +  :      62678 :         if( ( rAttrName.getLength() >= 5 ) &&
             +  -  +  - ]
                 [ +  + ]
     254         [ +  - ]:      29160 :             ( rAttrName.compareTo( GetXMLToken(XML_XMLNS), 5 ) == 0 ) &&
     255                 :       4358 :             ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
     256                 :            :         {
     257         [ +  + ]:       2179 :             if( !pRewindMap )
     258                 :            :             {
     259                 :        135 :                 pRewindMap = m_pNamespaceMap;
     260 [ +  - ][ +  - ]:        135 :                 m_pNamespaceMap = new SvXMLNamespaceMap( *m_pNamespaceMap );
     261                 :            :             }
     262 [ +  - ][ +  - ]:       2179 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     263                 :            : 
     264                 :       2179 :             OUString aPrefix( ( rAttrName.getLength() == 5 )
     265                 :            :                                  ? OUString()
     266         [ -  + ]:       2179 :                                  : rAttrName.copy( 6 ) );
     267                 :            :             // Add namespace, but only if it is known.
     268         [ +  - ]:       2179 :             sal_uInt16 nKey = m_pNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
     269                 :            :             // If namespace is unknown, try to match a name with similar
     270                 :            :             // TC Id an version
     271         [ +  + ]:       2179 :             if( XML_NAMESPACE_UNKNOWN == nKey  )
     272                 :            :             {
     273                 :        617 :                 OUString aTestName( rAttrValue );
     274 [ +  + ][ +  - ]:        617 :                 if( SvXMLNamespaceMap::NormalizeOasisURN( aTestName ) )
     275         [ +  - ]:        617 :                     nKey = m_pNamespaceMap->AddIfKnown( aPrefix, aTestName );
     276                 :            :             }
     277                 :            :             // If that namespace is not known, too, add it as unknown
     278         [ +  + ]:       2179 :             if( XML_NAMESPACE_UNKNOWN == nKey  )
     279         [ +  - ]:        617 :                 nKey = m_pNamespaceMap->Add( aPrefix, rAttrValue );
     280                 :            : 
     281         [ +  - ]:       2179 :             const OUString& rRepName = m_pReplaceNamespaceMap->GetNameByKey( nKey );
     282         [ +  + ]:       2179 :             if( !rRepName.isEmpty() )
     283                 :            :             {
     284         [ +  + ]:       1046 :                 if( !pMutableAttrList )
     285                 :            :                 {
     286         [ +  - ]:        129 :                     pMutableAttrList = new XMLMutableAttributeList( xAttrList );
     287 [ +  - ][ +  - ]:        129 :                     xAttrList = pMutableAttrList;
     288                 :            :                 }
     289                 :            : 
     290         [ +  - ]:       1046 :                 pMutableAttrList->SetValueByIndex( i, rRepName );
     291                 :       2179 :             }
     292                 :            :         }
     293                 :      29160 :     }
     294                 :            : 
     295                 :            :     // Get element's namespace and local name.
     296                 :      15509 :     OUString aLocalName;
     297                 :            :     sal_uInt16 nPrefix =
     298         [ +  - ]:      15509 :         m_pNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
     299                 :            : 
     300                 :            :     // If there are contexts already, call a CreateChildContext at the topmost
     301                 :            :     // context. Otherwise, create a default context.
     302                 :      15509 :     ::rtl::Reference < XMLTransformerContext > xContext;
     303         [ +  + ]:      15509 :     if( !m_pContexts->empty() )
     304                 :            :     {
     305         [ +  - ]:      15376 :         xContext = m_pContexts->back()->CreateChildContext( nPrefix,
     306                 :            :                                                           aLocalName,
     307                 :            :                                                           rName,
     308 [ +  - ][ +  - ]:      15376 :                                                           xAttrList );
     309                 :            :     }
     310                 :            :     else
     311                 :            :     {
     312 [ +  - ][ +  - ]:        133 :         xContext = CreateContext( nPrefix, aLocalName, rName );
     313                 :            :     }
     314                 :            : 
     315                 :            :     OSL_ENSURE( xContext.is(), "XMLTransformerBase::startElement: missing context" );
     316         [ -  + ]:      15509 :     if( !xContext.is() )
     317 [ #  # ][ #  # ]:          0 :         xContext = new XMLTransformerContext( *this, rName );
                 [ #  # ]
     318                 :            : 
     319                 :            :     // Remeber old namespace map.
     320         [ +  + ]:      15509 :     if( pRewindMap )
     321                 :        135 :         xContext->SetRewindMap( pRewindMap );
     322                 :            : 
     323                 :            :     // Push context on stack.
     324         [ +  - ]:      15509 :     m_pContexts->push_back( xContext );
     325                 :            : 
     326                 :            :     // Call a startElement at the new context.
     327 [ +  - ][ +  - ]:      15509 :     xContext->StartElement( xAttrList );
     328                 :      15509 : }
     329                 :            : 
     330                 :      15509 : void SAL_CALL XMLTransformerBase::endElement( const OUString&
     331                 :            : #if OSL_DEBUG_LEVEL > 0
     332                 :            : rName
     333                 :            : #endif
     334                 :            : )
     335                 :            :     throw(SAXException, RuntimeException)
     336                 :            : {
     337         [ +  - ]:      15509 :     if( !m_pContexts->empty() )
     338                 :            :     {
     339                 :            :         // Get topmost context
     340 [ +  - ][ +  - ]:      15509 :         ::rtl::Reference< XMLTransformerContext > xContext = m_pContexts->back();
     341                 :            : 
     342                 :            : #if OSL_DEBUG_LEVEL > 0
     343                 :            :         OSL_ENSURE( xContext->GetQName() == rName,
     344                 :            :                 "XMLTransformerBase::endElement: popped context has wrong lname" );
     345                 :            : #endif
     346                 :            : 
     347                 :            :         // Call a EndElement at the current context.
     348         [ +  - ]:      15509 :         xContext->EndElement();
     349                 :            : 
     350                 :            :         // and remove it from the stack.
     351         [ +  - ]:      15509 :         m_pContexts->pop_back();
     352                 :            : 
     353                 :            :         // Get a namespace map to rewind.
     354                 :      15509 :         SvXMLNamespaceMap *pRewindMap = xContext->GetRewindMap();
     355                 :            : 
     356                 :            :         // Delete the current context.
     357         [ +  - ]:      15509 :         xContext = 0;
     358                 :            : 
     359                 :            :         // Rewind a namespace map.
     360         [ +  + ]:      15509 :         if( pRewindMap )
     361                 :            :         {
     362 [ +  - ][ +  - ]:        135 :             delete m_pNamespaceMap;
     363                 :        135 :             m_pNamespaceMap = pRewindMap;
     364         [ +  - ]:      15509 :         }
     365                 :            :     }
     366                 :      15509 : }
     367                 :            : 
     368                 :      10437 : void SAL_CALL XMLTransformerBase::characters( const OUString& rChars )
     369                 :            :     throw(SAXException, RuntimeException)
     370                 :            : {
     371         [ +  + ]:      10437 :     if( !m_pContexts->empty() )
     372                 :            :     {
     373                 :      10289 :         m_pContexts->back()->Characters( rChars );
     374                 :            :     }
     375                 :      10437 : }
     376                 :            : 
     377                 :         12 : void SAL_CALL XMLTransformerBase::ignorableWhitespace( const OUString& rWhitespaces )
     378                 :            :     throw(SAXException, RuntimeException)
     379                 :            : {
     380                 :         12 :     m_xHandler->ignorableWhitespace( rWhitespaces );
     381                 :         12 : }
     382                 :            : 
     383                 :          0 : void SAL_CALL XMLTransformerBase::processingInstruction( const OUString& rTarget,
     384                 :            :                                        const OUString& rData )
     385                 :            :     throw(SAXException, RuntimeException)
     386                 :            : {
     387                 :          0 :     m_xHandler->processingInstruction( rTarget, rData );
     388                 :          0 : }
     389                 :            : 
     390                 :         87 : void SAL_CALL XMLTransformerBase::setDocumentLocator( const Reference< XLocator >& rLocator )
     391                 :            :     throw(SAXException, RuntimeException)
     392                 :            : {
     393                 :         87 :     m_xLocator = rLocator;
     394                 :         87 : }
     395                 :            : 
     396                 :            : // XExtendedDocumentHandler
     397                 :          0 : void SAL_CALL XMLTransformerBase::startCDATA( void ) throw(SAXException, RuntimeException)
     398                 :            : {
     399         [ #  # ]:          0 :     if( m_xExtHandler.is() )
     400                 :          0 :         m_xExtHandler->startCDATA();
     401                 :          0 : }
     402                 :            : 
     403                 :          0 : void SAL_CALL XMLTransformerBase::endCDATA( void ) throw(RuntimeException)
     404                 :            : {
     405         [ #  # ]:          0 :     if( m_xExtHandler.is() )
     406                 :          0 :         m_xExtHandler->endCDATA();
     407                 :          0 : }
     408                 :            : 
     409                 :         13 : void SAL_CALL XMLTransformerBase::comment( const OUString& rComment )
     410                 :            :     throw(SAXException, RuntimeException)
     411                 :            : {
     412         [ -  + ]:         13 :     if( m_xExtHandler.is() )
     413                 :          0 :         m_xExtHandler->comment( rComment );
     414                 :         13 : }
     415                 :            : 
     416                 :          0 : void SAL_CALL XMLTransformerBase::allowLineBreak( void )
     417                 :            :     throw(SAXException, RuntimeException)
     418                 :            : {
     419         [ #  # ]:          0 :     if( m_xExtHandler.is() )
     420                 :          0 :         m_xExtHandler->allowLineBreak();
     421                 :          0 : }
     422                 :            : 
     423                 :        440 : void SAL_CALL XMLTransformerBase::unknown( const OUString& rString )
     424                 :            :     throw(SAXException, RuntimeException)
     425                 :            : {
     426         [ -  + ]:        440 :     if( m_xExtHandler.is() )
     427                 :          0 :         m_xExtHandler->unknown( rString );
     428                 :        440 : }
     429                 :            : 
     430                 :            : // XInitialize
     431                 :        176 : void SAL_CALL XMLTransformerBase::initialize( const Sequence< Any >& aArguments )
     432                 :            :     throw(Exception, RuntimeException)
     433                 :            : {
     434                 :        176 :     const sal_Int32 nAnyCount = aArguments.getLength();
     435                 :        176 :     const Any* pAny = aArguments.getConstArray();
     436                 :            : 
     437         [ +  + ]:        708 :     for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
     438                 :            :     {
     439                 :            :         // use isAssignableFrom instead of comparing the types to
     440                 :            :         // allow XExtendedDocumentHandler instead of XDocumentHandler (used in
     441                 :            :         // writeOasis2OOoLibraryElement in sfx2).
     442                 :            :         // The Any shift operator can't be used to query the type because it
     443                 :            :         // uses queryInterface, and the model also has a XPropertySet interface.
     444                 :            : 
     445                 :            :         // document handler
     446         [ +  + ]:        532 :         if( ::getCppuType( (const Reference< XDocumentHandler >*) 0 ).isAssignableFrom( pAny->getValueType() ) )
     447                 :        176 :             m_xHandler.set( *pAny, UNO_QUERY );
     448                 :            : 
     449                 :            :         // property set to transport data across
     450         [ +  + ]:        532 :         if( ::getCppuType( (const Reference< XPropertySet >*) 0 ).isAssignableFrom( pAny->getValueType() ) )
     451                 :        128 :             m_xPropSet.set( *pAny, UNO_QUERY );
     452                 :            : 
     453                 :            :         // xmodel
     454         [ +  + ]:        532 :         if( ::getCppuType( (const Reference< ::com::sun::star::frame::XModel >*) 0 ).isAssignableFrom( pAny->getValueType() ) )
     455                 :         44 :             mxModel.set( *pAny, UNO_QUERY );
     456                 :            :     }
     457                 :            : 
     458         [ +  + ]:        176 :     if( m_xPropSet.is() )
     459                 :            :     {
     460                 :        128 :         Any aAny;
     461                 :        128 :         OUString sRelPath, sName;
     462                 :            :         Reference< XPropertySetInfo > xPropSetInfo =
     463 [ +  - ][ +  - ]:        128 :             m_xPropSet->getPropertySetInfo();
     464                 :        128 :         OUString sPropName( "StreamRelPath"  );
     465 [ +  - ][ +  + ]:        128 :         if( xPropSetInfo->hasPropertyByName(sPropName) )
                 [ +  - ]
     466                 :            :         {
     467 [ +  - ][ +  - ]:        124 :             aAny = m_xPropSet->getPropertyValue(sPropName);
     468                 :        124 :             aAny >>= sRelPath;
     469                 :            :         }
     470                 :        128 :         sPropName = OUString( "StreamName"  );
     471 [ +  - ][ +  + ]:        128 :         if( xPropSetInfo->hasPropertyByName(sPropName) )
                 [ +  - ]
     472                 :            :         {
     473 [ +  - ][ +  - ]:        124 :             aAny = m_xPropSet->getPropertyValue(sPropName);
     474                 :        124 :             aAny >>= sName;
     475                 :            :         }
     476         [ +  + ]:        128 :         if( !sName.isEmpty() )
     477                 :            :         {
     478                 :        124 :             m_aExtPathPrefix = OUString( "../"  );
     479                 :            : 
     480                 :            :             // If there is a rel path within a package, then append
     481                 :            :             // additional '../'. If the rel path contains an ':', then it is
     482                 :            :             // an absolute URI (or invalid URI, because zip files don't
     483                 :            :             // permit ':'), and it will be ignored.
     484         [ -  + ]:        124 :             if( !sRelPath.isEmpty() )
     485                 :            :             {
     486                 :          0 :                 sal_Int32 nColPos = sRelPath.indexOf( ':' );
     487                 :            :                 OSL_ENSURE( -1 == nColPos,
     488                 :            :                             "StreamRelPath contains ':', absolute URI?" );
     489                 :            : 
     490         [ #  # ]:          0 :                 if( -1 == nColPos )
     491                 :            :                 {
     492                 :          0 :                     OUString sTmp = m_aExtPathPrefix;
     493                 :          0 :                     sal_Int32 nPos = 0;
     494         [ #  # ]:          0 :                     do
     495                 :            :                     {
     496                 :          0 :                         m_aExtPathPrefix += sTmp;
     497                 :          0 :                         nPos = sRelPath.indexOf( '/', nPos + 1 );
     498                 :            :                     }
     499                 :          0 :                     while( -1 != nPos );
     500                 :            :                 }
     501                 :            :             }
     502                 :            : 
     503                 :        128 :         }
     504                 :            :     }
     505                 :        176 : }
     506                 :            : 
     507                 :        294 : static sal_Int16 lcl_getUnit( const OUString& rValue )
     508                 :            : {
     509         [ +  - ]:        294 :     if( rValue.endsWithIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "cm" ) ) )
     510                 :        294 :         return util::MeasureUnit::CM;
     511         [ #  # ]:          0 :     else if ( rValue.endsWithIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "mm" ) ) )
     512                 :          0 :         return util::MeasureUnit::MM;
     513                 :            :     else
     514                 :        294 :         return util::MeasureUnit::INCH;
     515                 :            : }
     516                 :            : 
     517                 :       1448 : XMLMutableAttributeList *XMLTransformerBase::ProcessAttrList(
     518                 :            :         Reference< XAttributeList >& rAttrList, sal_uInt16 nActionMap,
     519                 :            :            sal_Bool bClone  )
     520                 :            : {
     521                 :       1448 :     XMLMutableAttributeList *pMutableAttrList = 0;
     522                 :       1448 :     XMLTransformerActions *pActions = GetUserDefinedActions( nActionMap );
     523                 :            :     OSL_ENSURE( pActions, "go no actions" );
     524         [ +  - ]:       1448 :     if( pActions )
     525                 :            :     {
     526         [ +  - ]:       1448 :         sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
     527         [ +  + ]:       4701 :         for( sal_Int16 i=0; i < nAttrCount; ++i )
     528                 :            :         {
     529 [ +  - ][ +  - ]:       3253 :             const OUString& rAttrName = rAttrList->getNameByIndex( i );
     530 [ +  - ][ +  - ]:       3253 :             const OUString& rAttrValue = rAttrList->getValueByIndex( i );
     531                 :       3253 :             OUString aLocalName;
     532                 :       3253 :             sal_uInt16 nPrefix = GetNamespaceMap().GetKeyByAttrName( rAttrName,
     533         [ +  - ]:       3253 :                                                            &aLocalName );
     534                 :            : 
     535                 :       3253 :             XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
     536                 :            :             XMLTransformerActions::const_iterator aIter =
     537         [ +  - ]:       3253 :                     pActions->find( aKey );
     538 [ +  + ][ +  - ]:       3253 :             if( !(aIter == pActions->end() ) )
     539                 :            :             {
     540         [ +  + ]:       1826 :                 if( !pMutableAttrList )
     541                 :            :                 {
     542                 :            :                     pMutableAttrList = new XMLMutableAttributeList( rAttrList,
     543         [ +  - ]:        969 :                                                                     bClone );
     544 [ +  - ][ +  - ]:        969 :                     rAttrList = pMutableAttrList;
     545                 :            :                 }
     546                 :            : 
     547         [ +  - ]:       1826 :                 sal_uInt32 nAction = (*aIter).second.m_nActionType;
     548                 :       1826 :                 sal_Bool bRename = sal_False;
     549   [ +  -  -  -  :       1826 :                 switch( nAction )
          +  -  -  +  -  
          -  -  +  +  +  
          +  -  -  +  +  
          -  -  +  -  +  
          -  +  +  -  -  
          +  +  -  -  -  
                      - ]
     550                 :            :                 {
     551                 :            :                 case XML_ATACTION_RENAME:
     552                 :        460 :                     bRename = sal_True;
     553                 :        460 :                     break;
     554                 :            :                 case XML_ATACTION_COPY:
     555                 :          0 :                     break;
     556                 :            :                 case XML_ATACTION_REMOVE:
     557                 :            :                 case XML_ATACTION_STYLE_DISPLAY_NAME:
     558         [ #  # ]:          0 :                     pMutableAttrList->RemoveAttributeByIndex( i );
     559                 :          0 :                     --i;
     560                 :          0 :                     --nAttrCount;
     561                 :          0 :                     break;
     562                 :            :                 case XML_ATACTION_RENAME_IN2INCH:
     563                 :          0 :                     bRename = sal_True;
     564                 :            :                 case XML_ATACTION_IN2INCH:
     565                 :            :                     {
     566                 :        104 :                         OUString aAttrValue( rAttrValue );
     567 [ +  + ][ +  - ]:        104 :                         if( ReplaceSingleInWithInch( aAttrValue ) )
     568         [ +  - ]:        104 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     569                 :            :                     }
     570                 :        104 :                     break;
     571                 :            :                 case XML_ATACTION_INS2INCHS:
     572                 :            :                     {
     573                 :          0 :                         OUString aAttrValue( rAttrValue );
     574 [ #  # ][ #  # ]:          0 :                         if( ReplaceInWithInch( aAttrValue ) )
     575         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     576                 :            :                     }
     577                 :          0 :                     break;
     578                 :            :                 case XML_ATACTION_RENAME_INCH2IN:
     579                 :          0 :                     bRename = sal_True;
     580                 :            :                 case XML_ATACTION_INCH2IN:
     581                 :            :                     {
     582                 :        286 :                         OUString aAttrValue( rAttrValue );
     583         [ +  + ]:        286 :                         if( ReplaceSingleInchWithIn( aAttrValue ) )
     584         [ +  - ]:        286 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     585                 :            :                     }
     586                 :        286 :                     break;
     587                 :            :                 case XML_ATACTION_INCHS2INS:
     588                 :            :                     {
     589                 :          0 :                         OUString aAttrValue( rAttrValue );
     590 [ #  # ][ #  # ]:          0 :                         if( ReplaceInchWithIn( aAttrValue ) )
     591         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     592                 :            :                     }
     593                 :          0 :                     break;
     594                 :            :                 case XML_ATACTION_TWIPS2IN:
     595                 :            :                     {
     596                 :          0 :                         OUString aAttrValue( rAttrValue );
     597                 :            : 
     598                 :          0 :                         XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue );
     599 [ #  # ][ #  # ]:          0 :                         if( isWriter() )
     600                 :            :                         {
     601         [ #  # ]:          0 :                             sal_Int16 const nDestUnit = lcl_getUnit(aAttrValue);
     602                 :            : 
     603                 :            :                             // convert twips value to inch
     604                 :            :                             sal_Int32 nMeasure;
     605 [ #  # ][ #  # ]:          0 :                             if (::sax::Converter::convertMeasure(nMeasure,
     606                 :            :                                     aAttrValue, util::MeasureUnit::MM_100TH))
     607                 :            :                             {
     608                 :            : 
     609                 :            :                                 // #i13778#,#i36248# apply correct twip-to-1/100mm
     610                 :            :                                 nMeasure = (sal_Int32)( nMeasure >= 0
     611                 :            :                                                         ? ((nMeasure*127+36)/72)
     612         [ #  # ]:          0 :                                                         : ((nMeasure*127-36)/72) );
     613                 :            : 
     614                 :          0 :                                 rtl::OUStringBuffer aBuffer;
     615                 :            :                                 ::sax::Converter::convertMeasure(aBuffer,
     616                 :            :                                         nMeasure, util::MeasureUnit::MM_100TH,
     617         [ #  # ]:          0 :                                         nDestUnit );
     618         [ #  # ]:          0 :                                 aAttrValue = aBuffer.makeStringAndClear();
     619                 :            :                             }
     620                 :            :                         }
     621                 :            : 
     622         [ #  # ]:          0 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     623                 :            :                     }
     624                 :          0 :                     break;
     625                 :            :                 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF:
     626                 :          0 :                     bRename = sal_True;
     627                 :            :                 case XML_ATACTION_DECODE_STYLE_NAME:
     628                 :            :                 case XML_ATACTION_DECODE_STYLE_NAME_REF:
     629                 :            :                     {
     630                 :        120 :                         OUString aAttrValue( rAttrValue );
     631 [ -  + ][ +  - ]:        120 :                         if( DecodeStyleName(aAttrValue) )
     632         [ #  # ]:        120 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     633                 :            :                     }
     634                 :        120 :                     break;
     635                 :            :                 case XML_ATACTION_ENCODE_STYLE_NAME:
     636                 :            :                     {
     637                 :         32 :                         OUString aAttrValue( rAttrValue );
     638 [ -  + ][ +  - ]:         32 :                         if( EncodeStyleName(aAttrValue) )
     639                 :            :                         {
     640         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     641                 :            :                             OUString aNewAttrQName(
     642                 :          0 :                                 GetNamespaceMap().GetQNameByKey(
     643                 :            :                                     nPrefix,
     644                 :            :                                 ::xmloff::token::GetXMLToken(
     645   [ #  #  #  # ]:          0 :                                 XML_DISPLAY_NAME ) ) );
     646                 :            :                             pMutableAttrList->AddAttribute( aNewAttrQName,
     647         [ #  # ]:          0 :                                                             rAttrValue );
     648                 :         32 :                         }
     649                 :            :                     }
     650                 :         32 :                     break;
     651                 :            :                 case XML_ATACTION_RENAME_ENCODE_STYLE_NAME_REF:
     652                 :         28 :                     bRename = sal_True;
     653                 :            :                 case XML_ATACTION_ENCODE_STYLE_NAME_REF:
     654                 :            :                     {
     655                 :        404 :                         OUString aAttrValue( rAttrValue );
     656 [ +  + ][ +  - ]:        404 :                         if( EncodeStyleName(aAttrValue) )
     657         [ +  - ]:        404 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     658                 :            :                     }
     659                 :        404 :                     break;
     660                 :            :                 case XML_ATACTION_RENAME_NEG_PERCENT:
     661                 :          0 :                     bRename = sal_True;
     662                 :            :                 case XML_ATACTION_NEG_PERCENT:
     663                 :            :                     {
     664                 :          0 :                         OUString aAttrValue( rAttrValue );
     665 [ #  # ][ #  # ]:          0 :                         if( NegPercent( aAttrValue ) )
     666         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     667                 :            :                     }
     668                 :          0 :                     break;
     669                 :            :                 case XML_ATACTION_RENAME_ADD_NAMESPACE_PREFIX:
     670                 :         33 :                     bRename = sal_True;
     671                 :            :                 case XML_ATACTION_ADD_NAMESPACE_PREFIX:
     672                 :            :                     {
     673                 :         69 :                         OUString aAttrValue( rAttrValue );
     674                 :            :                         sal_uInt16 nValPrefix =
     675                 :            :                             static_cast<sal_uInt16>(
     676         [ +  - ]:         33 :                                     bRename ? (*aIter).second.m_nParam2
     677 [ +  - ][ +  + ]:        102 :                                             : (*aIter).second.m_nParam1);
     678 [ +  - ][ +  - ]:         69 :                         if( AddNamespacePrefix( aAttrValue, nValPrefix ) )
     679         [ +  - ]:         69 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     680                 :            :                     }
     681                 :         69 :                     break;
     682                 :            :                 case XML_ATACTION_ADD_APP_NAMESPACE_PREFIX:
     683                 :            :                     {
     684                 :          0 :                         OUString aAttrValue( rAttrValue );
     685                 :            :                         sal_uInt16 nValPrefix =
     686         [ #  # ]:          0 :                             static_cast<sal_uInt16>((*aIter).second.m_nParam1);
     687 [ #  # ][ #  # ]:          0 :                         if( IsXMLToken( GetClass(), XML_SPREADSHEET  ) )
     688                 :          0 :                             nValPrefix = XML_NAMESPACE_OOOC;
     689 [ #  # ][ #  # ]:          0 :                         else if( IsXMLToken( GetClass(), XML_TEXT  ) )
     690                 :          0 :                             nValPrefix = XML_NAMESPACE_OOOW;
     691 [ #  # ][ #  # ]:          0 :                         if( AddNamespacePrefix( aAttrValue, nValPrefix ) )
     692         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     693                 :            :                     }
     694                 :          0 :                     break;
     695                 :            :                 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX:
     696                 :          0 :                     bRename = sal_True;
     697                 :            :                 case XML_ATACTION_REMOVE_NAMESPACE_PREFIX:
     698                 :            :                     {
     699                 :         26 :                         OUString aAttrValue( rAttrValue );
     700                 :            :                         sal_uInt16 nValPrefix =
     701                 :            :                             static_cast<sal_uInt16>(
     702         [ #  # ]:          0 :                                     bRename ? (*aIter).second.m_nParam2
     703 [ +  - ][ -  + ]:         26 :                                             : (*aIter).second.m_nParam1);
     704 [ +  - ][ +  - ]:         26 :                         if( RemoveNamespacePrefix( aAttrValue, nValPrefix ) )
     705         [ +  - ]:         26 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     706                 :            :                     }
     707                 :         26 :                     break;
     708                 :            :                 case XML_ATACTION_REMOVE_ANY_NAMESPACE_PREFIX:
     709                 :            :                     {
     710                 :          0 :                         OUString aAttrValue( rAttrValue );
     711 [ #  # ][ #  # ]:          0 :                         if( RemoveNamespacePrefix( aAttrValue ) )
     712         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     713                 :            :                     }
     714                 :          0 :                     break;
     715                 :            :                 case XML_ATACTION_URI_OOO:
     716                 :            :                     {
     717                 :         23 :                         OUString aAttrValue( rAttrValue );
     718         [ +  + ]:         23 :                         if( ConvertURIToOASIS( aAttrValue,
     719         [ +  - ]:         23 :                             static_cast< sal_Bool >((*aIter).second.m_nParam1)))
     720         [ +  - ]:         23 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     721                 :            :                     }
     722                 :         23 :                     break;
     723                 :            :                 case XML_ATACTION_URI_OASIS:
     724                 :            :                     {
     725                 :          0 :                         OUString aAttrValue( rAttrValue );
     726         [ #  # ]:          0 :                         if( ConvertURIToOOo( aAttrValue,
     727         [ #  # ]:          0 :                             static_cast< sal_Bool >((*aIter).second.m_nParam1)))
     728         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     729                 :            :                     }
     730                 :          0 :                     break;
     731                 :            :                 case XML_ATACTION_RENAME_ATTRIBUTE:
     732                 :            :                     {
     733                 :          6 :                         OUString aAttrValue( rAttrValue );
     734                 :            :                         RenameAttributeValue(
     735                 :            :                             aAttrValue,
     736         [ +  - ]:          6 :                             (*aIter).second.m_nParam1,
     737         [ +  - ]:          6 :                             (*aIter).second.m_nParam2,
     738 [ +  - ][ +  - ]:         12 :                             (*aIter).second.m_nParam3 );
     739         [ +  - ]:          6 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     740                 :            :                     }
     741                 :          6 :                     break;
     742                 :            :                 case XML_ATACTION_RNG2ISO_DATETIME:
     743                 :            :                     {
     744                 :          2 :                         OUString aAttrValue( rAttrValue );
     745         [ -  + ]:          2 :                         if( ConvertRNGDateTimeToISO( aAttrValue ))
     746         [ #  # ]:          2 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     747                 :            :                     }
     748                 :          2 :                     break;
     749                 :            :                 case XML_ATACTION_RENAME_RNG2ISO_DATETIME:
     750                 :            :                     {
     751                 :          0 :                         OUString aAttrValue( rAttrValue );
     752         [ #  # ]:          0 :                         if( ConvertRNGDateTimeToISO( aAttrValue ))
     753         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     754                 :          0 :                         bRename = sal_True;
     755                 :            :                     }
     756                 :          0 :                     break;
     757                 :            :                 case XML_ATACTION_IN2TWIPS:
     758                 :            :                     {
     759                 :          0 :                         OUString aAttrValue( rAttrValue );
     760         [ #  # ]:          0 :                         XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
     761                 :            : 
     762 [ #  # ][ #  # ]:          0 :                         if( isWriter() )
     763                 :            :                         {
     764         [ #  # ]:          0 :                             sal_Int16 const nDestUnit = lcl_getUnit(aAttrValue);
     765                 :            : 
     766                 :            :                             // convert inch value to twips and export as faked inch
     767                 :            :                             sal_Int32 nMeasure;
     768 [ #  # ][ #  # ]:          0 :                             if (::sax::Converter::convertMeasure(nMeasure,
     769                 :            :                                     aAttrValue, util::MeasureUnit::MM_100TH))
     770                 :            :                             {
     771                 :            : 
     772                 :            :                                 // #i13778#,#i36248#/ apply correct 1/100mm-to-twip conversion
     773                 :            :                                 nMeasure = (sal_Int32)( nMeasure >= 0
     774                 :            :                                                         ? ((nMeasure*72+63)/127)
     775         [ #  # ]:          0 :                                                         : ((nMeasure*72-63)/127) );
     776                 :            : 
     777                 :          0 :                                 OUStringBuffer aBuffer;
     778                 :            :                                 ::sax::Converter::convertMeasure( aBuffer,
     779                 :            :                                         nMeasure, util::MeasureUnit::MM_100TH,
     780         [ #  # ]:          0 :                                         nDestUnit );
     781         [ #  # ]:          0 :                                 aAttrValue = aBuffer.makeStringAndClear();
     782                 :            :                             }
     783                 :            :                         }
     784                 :            : 
     785         [ #  # ]:          0 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     786                 :            :                     }
     787                 :          0 :                     break;
     788                 :            :                 case XML_ATACTION_SVG_WIDTH_HEIGHT_OOO:
     789                 :            :                     {
     790                 :        206 :                         OUString aAttrValue( rAttrValue );
     791                 :        206 :                         ReplaceSingleInchWithIn( aAttrValue );
     792                 :            : 
     793         [ +  - ]:        206 :                         sal_Int16 const nDestUnit = lcl_getUnit( aAttrValue );
     794                 :            : 
     795                 :            :                         sal_Int32 nMeasure;
     796 [ +  - ][ +  - ]:        206 :                         if (::sax::Converter::convertMeasure(nMeasure,
     797                 :            :                                     aAttrValue, util::MeasureUnit::MM_100TH))
     798                 :            :                         {
     799                 :            : 
     800         [ +  + ]:        206 :                             if( nMeasure > 0 )
     801                 :        194 :                                 nMeasure -= 1;
     802         [ +  - ]:         12 :                             else if( nMeasure < 0 )
     803                 :         12 :                                 nMeasure += 1;
     804                 :            : 
     805                 :            : 
     806                 :        206 :                             OUStringBuffer aBuffer;
     807                 :            :                             ::sax::Converter::convertMeasure(aBuffer, nMeasure,
     808         [ +  - ]:        206 :                                    util::MeasureUnit::MM_100TH, nDestUnit);
     809         [ +  - ]:        206 :                             aAttrValue = aBuffer.makeStringAndClear();
     810                 :            :                         }
     811                 :            : 
     812         [ +  - ]:        206 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     813                 :            :                     }
     814                 :        206 :                     break;
     815                 :            :                 case XML_ATACTION_SVG_WIDTH_HEIGHT_OASIS:
     816                 :            :                     {
     817                 :         88 :                         OUString aAttrValue( rAttrValue );
     818         [ +  - ]:         88 :                         ReplaceSingleInWithInch( aAttrValue );
     819                 :            : 
     820         [ +  - ]:         88 :                         sal_Int16 const nDestUnit = lcl_getUnit( aAttrValue );
     821                 :            : 
     822                 :            :                         sal_Int32 nMeasure;
     823 [ +  - ][ +  - ]:         88 :                         if (::sax::Converter::convertMeasure(nMeasure,
     824                 :            :                                 aAttrValue, util::MeasureUnit::MM_100TH))
     825                 :            :                         {
     826                 :            : 
     827         [ +  + ]:         88 :                             if( nMeasure > 0 )
     828                 :         76 :                                 nMeasure += 1;
     829         [ +  - ]:         12 :                             else if( nMeasure < 0 )
     830                 :         12 :                                 nMeasure -= 1;
     831                 :            : 
     832                 :            : 
     833                 :         88 :                             OUStringBuffer aBuffer;
     834                 :            :                             ::sax::Converter::convertMeasure(aBuffer, nMeasure,
     835         [ +  - ]:         88 :                                     util::MeasureUnit::MM_100TH, nDestUnit );
     836         [ +  - ]:         88 :                             aAttrValue = aBuffer.makeStringAndClear();
     837                 :            :                         }
     838                 :            : 
     839         [ +  - ]:         88 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     840                 :            :                     }
     841                 :         88 :                     break;
     842                 :            :                 case XML_ATACTION_DECODE_ID:
     843                 :            :                     {
     844                 :          0 :                         OUString aAttrValue;
     845                 :            : 
     846                 :          0 :                         const sal_Int32 nLen = rAttrValue.getLength();
     847                 :          0 :                         OUStringBuffer aBuffer;
     848                 :            : 
     849                 :            :                         sal_Int32 pos;
     850         [ #  # ]:          0 :                         for( pos = 0; pos < nLen; pos++ )
     851                 :            :                         {
     852                 :          0 :                             sal_Unicode c = rAttrValue[pos];
     853 [ #  # ][ #  # ]:          0 :                             if( (c >= '0') && (c <= '9') )
     854         [ #  # ]:          0 :                                 aBuffer.append( c );
     855                 :            :                             else
     856         [ #  # ]:          0 :                                 aBuffer.append( (sal_Int32)c );
     857                 :            :                         }
     858                 :            : 
     859 [ #  # ][ #  # ]:          0 :                         pMutableAttrList->SetValueByIndex( i, aBuffer.makeStringAndClear() );
     860                 :            :                     }
     861                 :          0 :                     break;
     862                 :            :                 // #i50322# - special handling for the
     863                 :            :                 // transparency of writer background graphics.
     864                 :            :                 case XML_ATACTION_WRITER_BACK_GRAPHIC_TRANSPARENCY:
     865                 :            :                     {
     866                 :            :                         // determine, if it's the transparency of a document style
     867                 :          0 :                         XMLTransformerContext* pFirstContext = (*m_pContexts)[0].get();
     868                 :          0 :                         OUString aFirstContextLocalName;
     869                 :            :                         /* sal_uInt16 nFirstContextPrefix = */
     870                 :          0 :                             GetNamespaceMap().GetKeyByAttrName( pFirstContext->GetQName(),
     871         [ #  # ]:          0 :                                                                 &aFirstContextLocalName );
     872                 :            :                         bool bIsDocumentStyle(
     873                 :            :                             ::xmloff::token::IsXMLToken( aFirstContextLocalName,
     874         [ #  # ]:          0 :                                                          XML_DOCUMENT_STYLES ) );
     875                 :            :                         // no conversion of transparency value for document
     876                 :            :                         // styles, because former OpenOffice.org version writes
     877                 :            :                         // writes always a transparency value of 100% and doesn't
     878                 :            :                         // read the value. Thus, it's intepreted as 0%
     879         [ #  # ]:          0 :                         if ( !bIsDocumentStyle )
     880                 :            :                         {
     881                 :          0 :                             OUString aAttrValue( rAttrValue );
     882         [ #  # ]:          0 :                             NegPercent(aAttrValue);
     883         [ #  # ]:          0 :                             pMutableAttrList->SetValueByIndex( i, aAttrValue );
     884                 :            :                         }
     885                 :          0 :                         bRename = sal_True;
     886                 :            :                     }
     887                 :          0 :                     break;
     888                 :            :                 case XML_ATACTION_SHAPEID:
     889                 :            :                 {
     890                 :          0 :                     OUString sNewValue( "shape"  );
     891                 :          0 :                     sNewValue += rAttrValue;
     892         [ #  # ]:          0 :                     pMutableAttrList->SetValueByIndex( i, sNewValue );
     893                 :          0 :                     break;
     894                 :            :                 }
     895                 :            : 
     896                 :            :                 default:
     897                 :            :                     OSL_ENSURE( !this, "unknown action" );
     898                 :          0 :                     break;
     899                 :            :                 }
     900                 :            : 
     901         [ +  + ]:       1826 :                 if( bRename )
     902                 :            :                 {
     903                 :            :                     OUString aNewAttrQName(
     904                 :        521 :                         GetNamespaceMap().GetQNameByKey(
     905         [ +  - ]:        521 :                             (*aIter).second.GetQNamePrefixFromParam1(),
     906                 :            :                             ::xmloff::token::GetXMLToken(
     907         [ +  - ]:       1042 :                                 (*aIter).second.GetQNameTokenFromParam1()) ) );
           [ +  -  +  - ]
     908                 :            :                     pMutableAttrList->RenameAttributeByIndex( i,
     909         [ +  - ]:        521 :                                                               aNewAttrQName );
     910                 :            :                 }
     911                 :            :             }
     912                 :       3253 :         }
     913                 :            :     }
     914                 :            : 
     915                 :       1448 :     return pMutableAttrList;
     916                 :            : }
     917                 :            : 
     918                 :       1910 : sal_Bool XMLTransformerBase::ReplaceSingleInchWithIn( OUString& rValue )
     919                 :            : {
     920                 :       1910 :     sal_Bool bRet = sal_False;
     921                 :       1910 :     sal_Int32 nPos = rValue.getLength();
     922 [ +  - ][ -  + ]:       1910 :     while( nPos && rValue[nPos-1] <= ' ' )
                 [ -  + ]
     923                 :          0 :         --nPos;
     924   [ +  -  +  +  :       7106 :     if( nPos > 2 &&
          -  +  +  +  -  
              + ][ +  + ]
     925                 :       2306 :         ('c'==rValue[nPos-2] || 'C'==rValue[nPos-2]) &&
     926                 :       2890 :         ('h'==rValue[nPos-1] || 'H'==rValue[nPos-1]) )
     927                 :            :     {
     928                 :        138 :         rValue =rValue.copy( 0, nPos-2 );
     929                 :        138 :         bRet = sal_True;
     930                 :            :     }
     931                 :            : 
     932                 :       1910 :     return bRet;
     933                 :            : }
     934                 :            : 
     935                 :         34 : sal_Bool XMLTransformerBase::ReplaceInchWithIn( OUString& rValue )
     936                 :            : {
     937                 :         34 :     sal_Bool bRet = sal_False;
     938                 :         34 :     sal_Int32 nPos = 1;
     939         [ +  + ]:        387 :     while( nPos < rValue.getLength()-3 )
     940                 :            :     {
     941                 :        353 :         sal_Unicode c = rValue[nPos];
     942 [ -  + ][ +  + ]:        353 :         if( 'i'==c || 'I'==c )
     943                 :            :         {
     944                 :         16 :             c = rValue[nPos-1];
     945 [ +  - ][ -  + ]:         16 :             if( (c >= '0' && c <= '9') || '.' == c )
                 [ +  - ]
     946                 :            :             {
     947                 :          0 :                 c = rValue[nPos+1];
     948 [ #  # ][ #  # ]:          0 :                 if( 'n'==c || 'N'==c )
     949                 :            :                 {
     950                 :          0 :                     c = rValue[nPos+2];
     951 [ #  # ][ #  # ]:          0 :                     if( 'c'==c || 'C'==c )
     952                 :            :                     {
     953                 :          0 :                         c = rValue[nPos+3];
     954 [ #  # ][ #  # ]:          0 :                         if( 'h'==c || 'H'==c )
     955                 :            :                         {
     956                 :            :                             rValue = rValue.replaceAt( nPos,
     957                 :          0 :                                 4, GetXMLToken(XML_UNIT_INCH) );
     958                 :          0 :                             nPos += 2;
     959                 :          0 :                             bRet = sal_True;
     960                 :          0 :                             continue;
     961                 :            :                         }
     962                 :            :                     }
     963                 :            :                 }
     964                 :            :             }
     965                 :            :         }
     966                 :        353 :         ++nPos;
     967                 :            :     }
     968                 :            : 
     969                 :         34 :     return bRet;
     970                 :            : }
     971                 :            : 
     972                 :       1352 : sal_Bool XMLTransformerBase::ReplaceSingleInWithInch( OUString& rValue )
     973                 :            : {
     974                 :       1352 :     sal_Bool bRet = sal_False;
     975                 :            : 
     976                 :       1352 :     sal_Int32 nPos = rValue.getLength();
     977 [ +  - ][ -  + ]:       1352 :     while( nPos && rValue[nPos-1] <= ' ' )
                 [ -  + ]
     978                 :          0 :         --nPos;
     979   [ +  -  +  +  :       4056 :     if( nPos > 2 &&
          -  +  -  +  #  
              # ][ +  + ]
     980                 :       1352 :         ('i'==rValue[nPos-2] ||
     981                 :       1214 :             'I'==rValue[nPos-2]) &&
     982                 :        138 :         ('n'==rValue[nPos-1] ||
     983                 :          0 :             'N'==rValue[nPos-1]) )
     984                 :            :     {
     985                 :        138 :         nPos -= 2;
     986                 :        138 :         rValue = rValue.replaceAt( nPos, rValue.getLength() - nPos,
     987                 :        276 :                                            GetXMLToken(XML_INCH) );
     988                 :        138 :         bRet = sal_True;
     989                 :            :     }
     990                 :            : 
     991                 :       1352 :     return bRet;
     992                 :            : }
     993                 :            : 
     994                 :         18 : sal_Bool XMLTransformerBase::ReplaceInWithInch( OUString& rValue )
     995                 :            : {
     996                 :         18 :     sal_Bool bRet = sal_False;
     997                 :         18 :     sal_Int32 nPos = 1;
     998         [ +  + ]:        118 :     while( nPos < rValue.getLength()-1 )
     999                 :            :     {
    1000                 :        100 :         sal_Unicode c = rValue[nPos];
    1001 [ -  + ][ +  + ]:        100 :         if( 'i'==c || 'I'==c )
    1002                 :            :         {
    1003                 :          4 :             c = rValue[nPos-1];
    1004 [ +  - ][ -  + ]:          4 :             if( (c >= '0' && c <= '9') || '.' == c )
                 [ +  - ]
    1005                 :            :             {
    1006                 :          0 :                 c = rValue[nPos+1];
    1007 [ #  # ][ #  # ]:          0 :                 if( 'n'==c || 'N'==c )
    1008                 :            :                 {
    1009                 :            :                     rValue = rValue.replaceAt( nPos,
    1010                 :          0 :                                     2, GetXMLToken(XML_INCH) );
    1011                 :          0 :                     nPos += 4;
    1012                 :          0 :                     bRet = sal_True;
    1013                 :          0 :                     continue;
    1014                 :            :                 }
    1015                 :            :             }
    1016                 :            :         }
    1017                 :        100 :         ++nPos;
    1018                 :            :     }
    1019                 :            : 
    1020                 :         18 :     return bRet;
    1021                 :            : }
    1022                 :            : 
    1023                 :       1198 : sal_Bool XMLTransformerBase::EncodeStyleName( OUString& rName ) const
    1024                 :            : {
    1025                 :            :     static sal_Char aHexTab[] = "0123456789abcdef";
    1026                 :            : 
    1027                 :       1198 :     sal_Bool bEncoded = sal_False;
    1028                 :            : 
    1029                 :       1198 :     sal_Int32 nLen = rName.getLength();
    1030                 :       1198 :     OUStringBuffer aBuffer( nLen );
    1031                 :            : 
    1032         [ +  + ]:       8462 :     for( sal_Int32 i = 0; i < nLen; i++ )
    1033                 :            :     {
    1034                 :       7264 :         sal_Unicode c = rName[i];
    1035                 :       7264 :         sal_Bool bValidChar = sal_False;
    1036         [ +  - ]:       7264 :         if( c < 0x00ffU )
    1037                 :            :         {
    1038                 :            :             bValidChar =
    1039                 :            :                 (c >= 0x0041 && c <= 0x005a) ||
    1040                 :            :                 (c >= 0x0061 && c <= 0x007a) ||
    1041                 :            :                 (c >= 0x00c0 && c <= 0x00d6) ||
    1042                 :            :                 (c >= 0x00d8 && c <= 0x00f6) ||
    1043                 :            :                 (c >= 0x00f8 && c <= 0x00ff) ||
    1044                 :            :                 ( i > 0 && ( (c >= 0x0030 && c <= 0x0039) ||
    1045 [ +  + ][ +  + ]:       7264 :                              c == 0x00b7 || c == '-' || c == '.') );
         [ +  + ][ -  + ]
         [ -  + ][ #  # ]
         [ -  + ][ #  # ]
         [ -  + ][ #  # ]
         [ +  - ][ +  + ]
         [ -  + ][ +  - ]
         [ +  + ][ -  + ]
    1046                 :            :         }
    1047                 :            :         else
    1048                 :            :         {
    1049 [ #  # ][ #  # ]:          0 :             if( (c >= 0xf900U && c <= 0xfffeU) ||
         [ #  # ][ #  # ]
    1050                 :            :                  (c >= 0x20ddU && c <= 0x20e0U))
    1051                 :            :             {
    1052                 :          0 :                 bValidChar = sal_False;
    1053                 :            :             }
    1054 [ #  # ][ #  # ]:          0 :             else if( (c >= 0x02bbU && c <= 0x02c1U) || c == 0x0559 ||
         [ #  # ][ #  # ]
                 [ #  # ]
    1055                 :            :                      c == 0x06e5 || c == 0x06e6 )
    1056                 :            :             {
    1057                 :          0 :                 bValidChar = sal_True;
    1058                 :            :             }
    1059         [ #  # ]:          0 :             else if( c == 0x0387 )
    1060                 :            :             {
    1061                 :          0 :                 bValidChar = i > 0;
    1062                 :            :             }
    1063                 :            :             else
    1064                 :            :             {
    1065         [ #  # ]:          0 :                 if( !xCharClass.is() )
    1066                 :            :                 {
    1067                 :            :                     Reference< XMultiServiceFactory > xFactory =
    1068         [ #  # ]:          0 :                         comphelper::getProcessServiceFactory();
    1069         [ #  # ]:          0 :                     if( xFactory.is() )
    1070                 :            :                     {
    1071                 :            :                         try
    1072                 :            :                         {
    1073                 :            :                             const_cast < XMLTransformerBase * >(this)
    1074                 :            :                                 ->xCharClass =
    1075                 :            :                                     Reference < XCharacterClassification >(
    1076         [ #  # ]:          0 :                                 xFactory->createInstance(
    1077                 :            :                                     OUString(
    1078                 :          0 :                         "com.sun.star.i18n.CharacterClassification_Unicode") ),
    1079 [ #  # ][ #  # ]:          0 :                                 UNO_QUERY );
         [ #  # ][ #  # ]
    1080                 :            : 
    1081                 :            :                             OSL_ENSURE( xCharClass.is(),
    1082                 :            :                     "can't instantiate character clossification component" );
    1083                 :            :                         }
    1084         [ #  # ]:          0 :                         catch( com::sun::star::uno::Exception& )
    1085                 :            :                         {
    1086                 :            :                         }
    1087                 :          0 :                     }
    1088                 :            :                 }
    1089         [ #  # ]:          0 :                 if( xCharClass.is() )
    1090                 :            :                 {
    1091 [ #  # ][ #  # ]:          0 :                     sal_Int16 nType = xCharClass->getType( rName, i );
    1092                 :            : 
    1093      [ #  #  # ]:          0 :                     switch( nType )
    1094                 :            :                     {
    1095                 :            :                     case UnicodeType::UPPERCASE_LETTER:     // Lu
    1096                 :            :                     case UnicodeType::LOWERCASE_LETTER:     // Ll
    1097                 :            :                     case UnicodeType::TITLECASE_LETTER:     // Lt
    1098                 :            :                     case UnicodeType::OTHER_LETTER:         // Lo
    1099                 :            :                     case UnicodeType::LETTER_NUMBER:        // Nl
    1100                 :          0 :                         bValidChar = sal_True;
    1101                 :          0 :                         break;
    1102                 :            :                     case UnicodeType::NON_SPACING_MARK:     // Ms
    1103                 :            :                     case UnicodeType::ENCLOSING_MARK:       // Me
    1104                 :            :                     case UnicodeType::COMBINING_SPACING_MARK:   //Mc
    1105                 :            :                     case UnicodeType::MODIFIER_LETTER:      // Lm
    1106                 :            :                     case UnicodeType::DECIMAL_DIGIT_NUMBER: // Nd
    1107                 :          0 :                         bValidChar = i > 0;
    1108                 :          0 :                         break;
    1109                 :            :                     }
    1110                 :            :                 }
    1111                 :            :             }
    1112                 :            :         }
    1113         [ +  + ]:       7264 :         if( bValidChar )
    1114                 :            :         {
    1115         [ +  - ]:       7113 :             aBuffer.append( c );
    1116                 :            :         }
    1117                 :            :         else
    1118                 :            :         {
    1119         [ +  - ]:        151 :             aBuffer.append( static_cast< sal_Unicode >( '_' ) );
    1120         [ -  + ]:        151 :             if( c > 0x0fff )
    1121                 :            :                 aBuffer.append( static_cast< sal_Unicode >(
    1122         [ #  # ]:          0 :                             aHexTab[ (c >> 12) & 0x0f ]  ) );
    1123         [ -  + ]:        151 :             if( c > 0x00ff )
    1124                 :            :                 aBuffer.append( static_cast< sal_Unicode >(
    1125         [ #  # ]:          0 :                         aHexTab[ (c >> 8) & 0x0f ] ) );
    1126         [ +  - ]:        151 :             if( c > 0x000f )
    1127                 :            :                 aBuffer.append( static_cast< sal_Unicode >(
    1128         [ +  - ]:        151 :                         aHexTab[ (c >> 4) & 0x0f ] ) );
    1129                 :            :             aBuffer.append( static_cast< sal_Unicode >(
    1130         [ +  - ]:        151 :                         aHexTab[ c & 0x0f ] ) );
    1131         [ +  - ]:        151 :             aBuffer.append( static_cast< sal_Unicode >( '_' ) );
    1132                 :        151 :             bEncoded = sal_True;
    1133                 :            :         }
    1134                 :            :     }
    1135                 :            : 
    1136         [ -  + ]:       1198 :     if( aBuffer.getLength() > (1<<15)-1 )
    1137                 :          0 :         bEncoded = sal_False;
    1138                 :            : 
    1139         [ +  + ]:       1198 :     if( bEncoded )
    1140         [ +  - ]:        127 :         rName = aBuffer.makeStringAndClear();
    1141                 :       1198 :     return bEncoded;
    1142                 :            : }
    1143                 :            : 
    1144                 :        536 : sal_Bool XMLTransformerBase::DecodeStyleName( OUString& rName )
    1145                 :            : {
    1146                 :        536 :     sal_Bool bEncoded = sal_False;
    1147                 :            : 
    1148                 :        536 :     sal_Int32 nLen = rName.getLength();
    1149                 :        536 :     OUStringBuffer aBuffer( nLen );
    1150                 :            : 
    1151                 :        536 :     sal_Bool bWithinHex = sal_False;
    1152                 :        536 :     sal_Unicode cEnc = 0;
    1153         [ +  + ]:       4654 :     for( sal_Int32 i = 0; i < nLen; i++ )
    1154                 :            :     {
    1155                 :       4118 :         sal_Unicode c = rName[i];
    1156         [ +  + ]:       4118 :         if( '_' == c )
    1157                 :            :         {
    1158         [ +  + ]:         24 :             if( bWithinHex )
    1159                 :            :             {
    1160         [ +  - ]:         12 :                 aBuffer.append( cEnc );
    1161                 :         12 :                 cEnc = 0;
    1162                 :            :             }
    1163                 :            :             else
    1164                 :            :             {
    1165                 :         12 :                 bEncoded = sal_True;
    1166                 :            :             }
    1167                 :         24 :             bWithinHex = !bWithinHex;
    1168                 :            :         }
    1169         [ +  + ]:       4094 :         else if( bWithinHex )
    1170                 :            :         {
    1171                 :            :             sal_Unicode cDigit;
    1172 [ +  - ][ +  - ]:         24 :             if( c >= '0' && c <= '9' )
    1173                 :            :             {
    1174                 :         24 :                 cDigit = c - '0';
    1175                 :            :             }
    1176 [ #  # ][ #  # ]:          0 :             else if( c >= 'a' && c <= 'f' )
    1177                 :            :             {
    1178                 :          0 :                 cDigit = c - 'a' + 10;
    1179                 :            :             }
    1180 [ #  # ][ #  # ]:          0 :             else if( c >= 'A' && c <= 'F' )
    1181                 :            :             {
    1182                 :          0 :                 cDigit = c - 'A' + 10;
    1183                 :            :             }
    1184                 :            :             else
    1185                 :            :             {
    1186                 :            :                 // error
    1187                 :          0 :                 bEncoded = sal_False;
    1188                 :          0 :                 break;
    1189                 :            :             }
    1190                 :         24 :             cEnc = (cEnc << 4) + cDigit;
    1191                 :            :         }
    1192                 :            :         else
    1193                 :            :         {
    1194         [ +  - ]:       4070 :             aBuffer.append( c );
    1195                 :            :         }
    1196                 :            :     }
    1197                 :            : 
    1198         [ +  + ]:        536 :     if( bEncoded )
    1199         [ +  - ]:         12 :         rName = aBuffer.makeStringAndClear();
    1200                 :        536 :     return bEncoded;
    1201                 :            : }
    1202                 :            : 
    1203                 :         33 : sal_Bool XMLTransformerBase::NegPercent( OUString& rValue )
    1204                 :            : {
    1205                 :         33 :     sal_Bool bRet = sal_False;
    1206                 :         33 :     sal_Bool bNeg = sal_False;
    1207                 :         33 :     double nVal = 0;
    1208                 :            : 
    1209                 :         33 :     sal_Int32 nPos = 0;
    1210                 :         33 :     sal_Int32 nLen = rValue.getLength();
    1211                 :            : 
    1212                 :            :     // skip white space
    1213 [ +  - ][ -  + ]:         33 :     while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
                 [ -  + ]
    1214                 :          0 :         nPos++;
    1215                 :            : 
    1216 [ +  - ][ -  + ]:         33 :     if( nPos < nLen && sal_Unicode('-') == rValue[nPos] )
                 [ -  + ]
    1217                 :            :     {
    1218                 :          0 :         bNeg = sal_True;
    1219                 :          0 :         nPos++;
    1220                 :            :     }
    1221                 :            : 
    1222                 :            :     // get number
    1223   [ +  -  +  +  :        252 :     while( nPos < nLen &&
           +  - ][ +  + ]
    1224                 :         95 :            sal_Unicode('0') <= rValue[nPos] &&
    1225                 :         62 :            sal_Unicode('9') >= rValue[nPos] )
    1226                 :            :     {
    1227                 :            :         // TODO: check overflow!
    1228                 :         62 :         nVal *= 10;
    1229                 :         62 :         nVal += (rValue[nPos] - sal_Unicode('0'));
    1230                 :         62 :         nPos++;
    1231                 :            :     }
    1232                 :         33 :     double nDiv = 1.;
    1233 [ +  - ][ -  + ]:         33 :     if( nPos < nLen && sal_Unicode('.') == rValue[nPos] )
                 [ -  + ]
    1234                 :            :     {
    1235                 :          0 :         nPos++;
    1236                 :            : 
    1237   [ #  #  #  #  :          0 :         while( nPos < nLen &&
           #  # ][ #  # ]
    1238                 :          0 :                sal_Unicode('0') <= rValue[nPos] &&
    1239                 :          0 :                sal_Unicode('9') >= rValue[nPos] )
    1240                 :            :         {
    1241                 :            :             // TODO: check overflow!
    1242                 :          0 :             nDiv *= 10;
    1243                 :          0 :             nVal += ( static_cast<double>(rValue[nPos] - sal_Unicode('0')) / nDiv );
    1244                 :          0 :             nPos++;
    1245                 :            :         }
    1246                 :            :     }
    1247                 :            : 
    1248                 :            :     // skip white space
    1249 [ +  - ][ -  + ]:         33 :     while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
                 [ -  + ]
    1250                 :          0 :         nPos++;
    1251                 :            : 
    1252 [ +  - ][ +  - ]:         33 :     if( nPos < nLen &&  sal_Unicode('%') == rValue[nPos] )
                 [ +  - ]
    1253                 :            :     {
    1254         [ -  + ]:         33 :         if( bNeg )
    1255                 :          0 :                nVal = -nVal;
    1256                 :         33 :         nVal += .5;
    1257                 :            : 
    1258                 :         33 :         sal_Int32 nIntVal = 100 - static_cast<sal_Int32>( nVal );
    1259                 :            : 
    1260                 :         33 :         OUStringBuffer aNewValBuffer;
    1261         [ +  - ]:         33 :         aNewValBuffer.append( nIntVal );
    1262         [ +  - ]:         33 :         aNewValBuffer.append( sal_Unicode('%' ) );
    1263                 :            : 
    1264         [ +  - ]:         33 :         rValue = aNewValBuffer.makeStringAndClear();
    1265                 :         33 :         bRet = sal_True;
    1266                 :            :     }
    1267                 :            : 
    1268                 :         33 :     return bRet;
    1269                 :            : }
    1270                 :            : 
    1271                 :         81 : sal_Bool XMLTransformerBase::AddNamespacePrefix( ::rtl::OUString& rName,
    1272                 :            :                              sal_uInt16 nPrefix ) const
    1273                 :            : {
    1274                 :         81 :     rName = GetNamespaceMap().GetQNameByKey( nPrefix, rName, sal_False );
    1275                 :         81 :     return sal_True;
    1276                 :            : }
    1277                 :            : 
    1278                 :         26 : sal_Bool XMLTransformerBase::RemoveNamespacePrefix( ::rtl::OUString& rName,
    1279                 :            :                             sal_uInt16 nPrefixOnly ) const
    1280                 :            : {
    1281                 :         26 :     OUString aLocalName;
    1282                 :            :     sal_uInt16 nPrefix =
    1283         [ +  - ]:         26 :         GetNamespaceMap()._GetKeyByAttrName( rName, &aLocalName, sal_False );
    1284                 :            :     sal_Bool bRet = XML_NAMESPACE_UNKNOWN != nPrefix &&
    1285 [ +  - ][ +  - ]:         26 :                     (USHRT_MAX == nPrefixOnly || nPrefix == nPrefixOnly);
                 [ +  - ]
    1286         [ +  - ]:         26 :     if( bRet )
    1287                 :         26 :         rName = aLocalName;
    1288                 :            : 
    1289                 :         26 :     return bRet;
    1290                 :            : }
    1291                 :            : 
    1292                 :         35 : sal_Bool XMLTransformerBase::ConvertURIToOASIS( ::rtl::OUString& rURI,
    1293                 :            :                                         sal_Bool bSupportPackage ) const
    1294                 :            : {
    1295                 :         35 :     sal_Bool bRet = sal_False;
    1296 [ +  - ][ +  + ]:         35 :     if( !m_aExtPathPrefix.isEmpty() && !rURI.isEmpty() )
                 [ +  + ]
    1297                 :            :     {
    1298                 :         17 :         sal_Bool bRel = sal_False;
    1299   [ +  -  -  - ]:         17 :         switch( rURI[0] )
    1300                 :            :         {
    1301                 :            :         case '#':
    1302                 :            :             // no rel path, but
    1303                 :            :             // for package URIs, the '#' has to be removed
    1304         [ +  - ]:         17 :             if( bSupportPackage )
    1305                 :            :             {
    1306                 :         17 :                 rURI = rURI.copy( 1 );
    1307                 :         17 :                 bRet = sal_True;
    1308                 :            :             }
    1309                 :         17 :             break;
    1310                 :            :         case '/':
    1311                 :            :             // no rel path; nothing to do
    1312                 :          0 :             break;
    1313                 :            :         case '.':
    1314                 :            :             // a rel path; to keep URI simple, remove './', if there
    1315                 :          0 :             bRel = sal_True;
    1316 [ #  # ][ #  # ]:          0 :             if( rURI.getLength() > 1 && '/' == rURI[1] )
                 [ #  # ]
    1317                 :            :             {
    1318                 :          0 :                 rURI = rURI.copy( 2 );
    1319                 :          0 :                 bRet = sal_True;
    1320                 :            :             }
    1321                 :          0 :             break;
    1322                 :            :         default:
    1323                 :            :             // check for a RFC2396 schema
    1324                 :            :             {
    1325                 :          0 :                 bRel = sal_True;
    1326                 :          0 :                 sal_Int32 nPos = 1;
    1327                 :          0 :                 sal_Int32 nLen = rURI.getLength();
    1328         [ #  # ]:          0 :                 while( nPos < nLen )
    1329                 :            :                 {
    1330      [ #  #  # ]:          0 :                     switch( rURI[nPos] )
    1331                 :            :                     {
    1332                 :            :                     case '/':
    1333                 :            :                         // a relative path segement
    1334                 :          0 :                         nPos = nLen;    // leave loop
    1335                 :          0 :                         break;
    1336                 :            :                     case ':':
    1337                 :            :                         // a schema
    1338                 :          0 :                         bRel = sal_False;
    1339                 :          0 :                         nPos = nLen;    // leave loop
    1340                 :          0 :                         break;
    1341                 :            :                     default:
    1342                 :            :                         // we don't care about any other characters
    1343                 :          0 :                         break;
    1344                 :            :                     }
    1345                 :          0 :                     ++nPos;
    1346                 :            :                 }
    1347                 :            :             }
    1348                 :            :         }
    1349                 :            : 
    1350         [ -  + ]:         17 :         if( bRel )
    1351                 :            :         {
    1352                 :          0 :             OUString sTmp( m_aExtPathPrefix );
    1353                 :          0 :             sTmp += rURI;
    1354                 :          0 :             rURI = sTmp;
    1355                 :          0 :             bRet = sal_True;
    1356                 :            :         }
    1357                 :            :     }
    1358                 :            : 
    1359                 :         35 :     return bRet;
    1360                 :            : }
    1361                 :            : 
    1362                 :          0 : sal_Bool XMLTransformerBase::ConvertURIToOOo( ::rtl::OUString& rURI,
    1363                 :            :                                         sal_Bool bSupportPackage ) const
    1364                 :            : {
    1365                 :          0 :     sal_Bool bRet = sal_False;
    1366         [ #  # ]:          0 :     if( !rURI.isEmpty() )
    1367                 :            :     {
    1368                 :          0 :         sal_Bool bPackage = sal_False;
    1369      [ #  #  # ]:          0 :         switch( rURI[0] )
    1370                 :            :         {
    1371                 :            :         case '/':
    1372                 :            :             // no rel path; nothing to to
    1373                 :          0 :             break;
    1374                 :            :         case '.':
    1375                 :            :             // a rel path
    1376         [ #  # ]:          0 :             if( 0 == rURI.compareTo( m_aExtPathPrefix,
    1377                 :          0 :                                      m_aExtPathPrefix.getLength() ) )
    1378                 :            :             {
    1379                 :            :                 // an external URI; remove '../'
    1380                 :          0 :                 rURI = rURI.copy( m_aExtPathPrefix.getLength() );
    1381                 :          0 :                 bRet = sal_True;
    1382                 :            :             }
    1383                 :            :             else
    1384                 :            :             {
    1385                 :          0 :                 bPackage = sal_True;
    1386                 :            :             }
    1387                 :          0 :             break;
    1388                 :            :         default:
    1389                 :            :             // check for a RFC2396 schema
    1390                 :            :             {
    1391                 :          0 :                 bPackage = sal_True;
    1392                 :          0 :                 sal_Int32 nPos = 1;
    1393                 :          0 :                 sal_Int32 nLen = rURI.getLength();
    1394         [ #  # ]:          0 :                 while( nPos < nLen )
    1395                 :            :                 {
    1396      [ #  #  # ]:          0 :                     switch( rURI[nPos] )
    1397                 :            :                     {
    1398                 :            :                     case '/':
    1399                 :            :                         // a relative path segement within the package
    1400                 :          0 :                         nPos = nLen;    // leave loop
    1401                 :          0 :                         break;
    1402                 :            :                     case ':':
    1403                 :            :                         // a schema
    1404                 :          0 :                         bPackage = sal_False;
    1405                 :          0 :                         nPos = nLen;    // leave loop
    1406                 :          0 :                         break;
    1407                 :            :                     default:
    1408                 :            :                         // we don't care about any other characters
    1409                 :          0 :                         break;
    1410                 :            :                     }
    1411                 :          0 :                     ++nPos;
    1412                 :            :                 }
    1413                 :            :             }
    1414                 :            :         }
    1415                 :            : 
    1416 [ #  # ][ #  # ]:          0 :         if( bPackage && bSupportPackage )
    1417                 :            :         {
    1418                 :          0 :             OUString sTmp( OUString::valueOf( sal_Unicode( '#' ) ) );
    1419         [ #  # ]:          0 :             if( 0 == rURI.compareToAscii( "./", 2 ) )
    1420                 :          0 :                 rURI = rURI.copy( 2 );
    1421                 :          0 :             sTmp += rURI;
    1422                 :          0 :             rURI = sTmp;
    1423                 :          0 :             bRet = sal_True;
    1424                 :            :         }
    1425                 :            :     }
    1426                 :            : 
    1427                 :          0 :     return bRet;
    1428                 :            : }
    1429                 :            : 
    1430                 :          6 : sal_Bool XMLTransformerBase::RenameAttributeValue(
    1431                 :            :     OUString& rOutAttributeValue,
    1432                 :            :     sal_Int32 nParam1,
    1433                 :            :     sal_Int32 nParam2,
    1434                 :            :     sal_Int32 nParam3 )
    1435                 :            : {
    1436                 :          6 :     return ( lcl_ConvertAttr( rOutAttributeValue, nParam1) ||
    1437                 :          6 :              lcl_ConvertAttr( rOutAttributeValue, nParam2) ||
    1438         [ #  # ]:         12 :              lcl_ConvertAttr( rOutAttributeValue, nParam3) );
           [ +  -  -  + ]
    1439                 :            : }
    1440                 :            : 
    1441                 :            : // static
    1442                 :          2 : bool XMLTransformerBase::ConvertRNGDateTimeToISO( ::rtl::OUString& rDateTime )
    1443                 :            : {
    1444   [ +  -  -  + ]:          4 :     if( !rDateTime.isEmpty() &&
                 [ -  + ]
    1445                 :          2 :         rDateTime.indexOf( sal_Unicode('.')) != -1 )
    1446                 :            :     {
    1447                 :          0 :         rDateTime = rDateTime.replace( sal_Unicode('.'), sal_Unicode(','));
    1448                 :          0 :         return true;
    1449                 :            :     }
    1450                 :            : 
    1451                 :          2 :     return false;
    1452                 :            : }
    1453                 :            : 
    1454                 :         64 : XMLTokenEnum XMLTransformerBase::GetToken( const OUString& rStr ) const
    1455                 :            : {
    1456                 :            :     XMLTransformerTokenMap::const_iterator aIter =
    1457         [ +  - ]:         64 :         m_pTokenMap->find( rStr );
    1458 [ -  + ][ +  - ]:         64 :     if( aIter == m_pTokenMap->end() )
    1459                 :          0 :         return XML_TOKEN_END;
    1460                 :            :     else
    1461         [ +  - ]:         64 :         return (*aIter).second;
    1462                 :            : }
    1463                 :            : 
    1464                 :            : 
    1465                 :            : 
    1466                 :         36 : const XMLTransformerContext *XMLTransformerBase::GetCurrentContext() const
    1467                 :            : {
    1468                 :            :     OSL_ENSURE( !m_pContexts->empty(), "empty stack" );
    1469                 :            : 
    1470                 :            : 
    1471         [ -  + ]:         36 :     return m_pContexts->empty() ? 0 : m_pContexts->back().get();
    1472                 :            : }
    1473                 :            : 
    1474                 :          0 : const XMLTransformerContext *XMLTransformerBase::GetAncestorContext(
    1475                 :            :                                                         sal_uInt32 n ) const
    1476                 :            : {
    1477                 :            :     XMLTransformerContextVector::size_type nSize =
    1478                 :          0 :         m_pContexts->size();
    1479                 :            :     XMLTransformerContextVector::size_type nPos =
    1480                 :          0 :         static_cast<XMLTransformerContextVector::size_type>( n );
    1481                 :            : 
    1482                 :            :     OSL_ENSURE( nSize >nPos+2 , "invalid context" );
    1483                 :            : 
    1484         [ #  # ]:          0 :     return nSize > nPos+2 ? (*m_pContexts)[nSize-(nPos+2)].get() : 0;
    1485                 :            : }
    1486                 :            : 
    1487                 :          8 : bool XMLTransformerBase::isWriter() const
    1488                 :            : {
    1489         [ +  - ]:          8 :     Reference< XServiceInfo > xSI( mxModel, UNO_QUERY );
    1490                 :          8 :     return  xSI.is() &&
    1491 [ +  - ][ +  - ]:         16 :         (   xSI->supportsService( OUString( "com.sun.star.text.TextDocument"  ) ) ||
         [ +  - ][ +  - ]
           [ #  #  #  # ]
    1492 [ +  - ][ +  - ]:         16 :             xSI->supportsService( OUString( "com.sun.star.text.WebDocument"  ) ) ||
         [ +  - ][ +  - ]
           [ #  #  #  # ]
    1493 [ +  - ][ +  - ]:         32 :             xSI->supportsService( OUString( "com.sun.star.text.GlobalDocument"  ) ) );
         [ +  - ][ +  - ]
         [ -  + ][ +  - ]
                 [ +  - ]
           [ #  #  #  # ]
                 [ +  - ]
    1494                 :            : }
    1495                 :            : 
    1496                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10