LCOV - code coverage report
Current view: top level - sax/source/fastparser - fastparser.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 317 443 71.6 %
Date: 2012-08-25 Functions: 50 60 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 281 679 41.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <boost/scoped_ptr.hpp>
      21                 :            : 
      22                 :            : #include <osl/diagnose.h>
      23                 :            : #include <rtl/ustrbuf.hxx>
      24                 :            : 
      25                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      26                 :            : #include <com/sun/star/xml/sax/XFastContextHandler.hpp>
      27                 :            : #include <com/sun/star/xml/sax/SAXParseException.hpp>
      28                 :            : #include <com/sun/star/xml/sax/FastToken.hpp>
      29                 :            : 
      30                 :            : #include "fastparser.hxx"
      31                 :            : 
      32                 :            : #include <string.h>
      33                 :            : 
      34                 :            : using ::rtl::OString;
      35                 :            : using ::rtl::OUString;
      36                 :            : using ::rtl::OUStringBuffer;
      37                 :            : using namespace ::std;
      38                 :            : using namespace ::osl;
      39                 :            : using namespace ::cppu;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::lang;
      42                 :            : using namespace ::com::sun::star::xml::sax;
      43                 :            : using namespace ::com::sun::star::io;
      44                 :            : 
      45                 :            : namespace sax_fastparser {
      46                 :            : 
      47                 :            : // --------------------------------------------------------------------
      48                 :            : 
      49                 :      90706 : struct SaxContextImpl
      50                 :            : {
      51                 :            :     Reference< XFastContextHandler >    mxContext;
      52                 :            :     sal_uInt32      mnNamespaceCount;
      53                 :            :     sal_Int32       mnElementToken;
      54                 :            :     OUString        maNamespace;
      55                 :            :     OUString        maElementName;
      56                 :            : 
      57                 :       2004 :     SaxContextImpl() { mnNamespaceCount = 0; mnElementToken = 0; }
      58                 :      88702 :     SaxContextImpl( const SaxContextImplPtr& p ) { mnNamespaceCount = p->mnNamespaceCount; mnElementToken = p->mnElementToken; maNamespace = p->maNamespace; }
      59                 :            : };
      60                 :            : 
      61                 :            : // --------------------------------------------------------------------
      62                 :            : 
      63                 :       7395 : struct NamespaceDefine
      64                 :            : {
      65                 :            :     OString     maPrefix;
      66                 :            :     sal_Int32   mnToken;
      67                 :            :     OUString    maNamespaceURL;
      68                 :            : 
      69                 :       7395 :     NamespaceDefine( const OString& rPrefix, sal_Int32 nToken, const OUString& rNamespaceURL ) : maPrefix( rPrefix ), mnToken( nToken ), maNamespaceURL( rNamespaceURL ) {}
      70                 :            : };
      71                 :            : 
      72                 :            : // --------------------------------------------------------------------
      73                 :            : // FastLocatorImpl
      74                 :            : // --------------------------------------------------------------------
      75                 :            : 
      76                 :            : class FastSaxParser;
      77                 :            : 
      78         [ -  + ]:       1550 : class FastLocatorImpl : public WeakImplHelper1< XLocator >
      79                 :            : {
      80                 :            : public:
      81                 :        775 :     FastLocatorImpl( FastSaxParser *p ) : mpParser(p) {}
      82                 :            : 
      83                 :        775 :     void dispose() { mpParser = 0; }
      84 [ -  + ][ #  # ]:         18 :     void checkDispose() throw (RuntimeException) { if( !mpParser ) throw DisposedException(); }
      85                 :            : 
      86                 :            :     //XLocator
      87                 :            :     virtual sal_Int32 SAL_CALL getColumnNumber(void) throw (RuntimeException);
      88                 :            :     virtual sal_Int32 SAL_CALL getLineNumber(void) throw (RuntimeException);
      89                 :            :     virtual OUString SAL_CALL getPublicId(void) throw (RuntimeException);
      90                 :            :     virtual OUString SAL_CALL getSystemId(void) throw (RuntimeException);
      91                 :            : 
      92                 :            : private:
      93                 :            :     FastSaxParser *mpParser;
      94                 :            : };
      95                 :            : 
      96                 :            : // --------------------------------------------------------------------
      97                 :            : // FastSaxParser
      98                 :            : // --------------------------------------------------------------------
      99                 :            : 
     100                 :            : //---------------------------------------------
     101                 :            : // the implementation part
     102                 :            : //---------------------------------------------
     103                 :            : 
     104                 :            : extern "C" {
     105                 :            : 
     106                 :      90706 : static void call_callbackStartElement(void *userData, const XML_Char *name , const XML_Char **atts)
     107                 :            : {
     108                 :      90706 :     FastSaxParser* pFastParser = reinterpret_cast< FastSaxParser* >( userData );
     109                 :      90706 :     pFastParser->callbackStartElement( name, atts );
     110                 :      90706 : }
     111                 :            : 
     112                 :      90688 : static void call_callbackEndElement(void *userData, const XML_Char *name)
     113                 :            : {
     114                 :      90688 :     FastSaxParser* pFastParser = reinterpret_cast< FastSaxParser* >( userData );
     115                 :      90688 :     pFastParser->callbackEndElement( name );
     116                 :      90688 : }
     117                 :            : 
     118                 :      11174 : static void call_callbackCharacters( void *userData , const XML_Char *s , int nLen )
     119                 :            : {
     120                 :      11174 :     FastSaxParser* pFastParser = reinterpret_cast< FastSaxParser* >( userData );
     121                 :      11174 :     pFastParser->callbackCharacters( s, nLen );
     122                 :      11174 : }
     123                 :            : 
     124                 :          0 : static void call_callbackEntityDecl(void *userData, const XML_Char *entityName,
     125                 :            :         int is_parameter_entity, const XML_Char *value, int value_length,
     126                 :            :         const XML_Char *base, const XML_Char *systemId,
     127                 :            :         const XML_Char *publicId, const XML_Char *notationName)
     128                 :            : {
     129                 :          0 :     FastSaxParser* pFastParser = reinterpret_cast<FastSaxParser*>(userData);
     130                 :            :     pFastParser->callbackEntityDecl(entityName, is_parameter_entity, value,
     131                 :          0 :             value_length, base, systemId, publicId, notationName);
     132                 :          0 : }
     133                 :            : 
     134                 :          0 : static int call_callbackExternalEntityRef( XML_Parser parser,
     135                 :            :         const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId )
     136                 :            : {
     137                 :          0 :     FastSaxParser* pFastParser = reinterpret_cast< FastSaxParser* >( XML_GetUserData( parser ) );
     138                 :          0 :     return pFastParser->callbackExternalEntityRef( parser, openEntityNames, base, systemId, publicId );
     139                 :            : }
     140                 :            : 
     141                 :            : } // extern "C"
     142                 :            : 
     143                 :            : // --------------------------------------------------------------------
     144                 :            : // FastLocatorImpl implementation
     145                 :            : // --------------------------------------------------------------------
     146                 :            : 
     147                 :          3 : sal_Int32 SAL_CALL FastLocatorImpl::getColumnNumber(void) throw (RuntimeException)
     148                 :            : {
     149                 :          3 :     checkDispose();
     150                 :          3 :     return XML_GetCurrentColumnNumber( mpParser->getEntity().mpParser );
     151                 :            : }
     152                 :            : 
     153                 :            : // --------------------------------------------------------------------
     154                 :            : 
     155                 :          6 : sal_Int32 SAL_CALL FastLocatorImpl::getLineNumber(void) throw (RuntimeException)
     156                 :            : {
     157                 :          6 :     checkDispose();
     158                 :          6 :     return XML_GetCurrentLineNumber( mpParser->getEntity().mpParser );
     159                 :            : }
     160                 :            : 
     161                 :            : // --------------------------------------------------------------------
     162                 :            : 
     163                 :          3 : OUString SAL_CALL FastLocatorImpl::getPublicId(void) throw (RuntimeException)
     164                 :            : {
     165                 :          3 :     checkDispose();
     166                 :          3 :     return mpParser->getEntity().maStructSource.sPublicId;
     167                 :            : }
     168                 :            : // --------------------------------------------------------------------
     169                 :            : 
     170                 :          6 : OUString SAL_CALL FastLocatorImpl::getSystemId(void) throw (RuntimeException)
     171                 :            : {
     172                 :          6 :     checkDispose();
     173                 :          6 :     return mpParser->getEntity().maStructSource.sSystemId;
     174                 :            : }
     175                 :            : 
     176                 :            : // --------------------------------------------------------------------
     177                 :            : 
     178                 :        775 : ParserData::ParserData()
     179                 :            : {
     180                 :        775 : }
     181                 :            : 
     182                 :       4802 : ParserData::~ParserData()
     183                 :            : {
     184                 :       4802 : }
     185                 :            : 
     186                 :            : // --------------------------------------------------------------------
     187                 :            : 
     188                 :       2023 : Entity::Entity( const ParserData& rData ) :
     189 [ +  - ][ +  - ]:       2023 :     ParserData( rData )
         [ +  - ][ +  - ]
                 [ +  - ]
     190                 :            : {
     191                 :            :     // performance-Improvment. Reference is needed when calling the startTag callback.
     192                 :            :     // Handing out the same object with every call is allowed (see sax-specification)
     193         [ +  - ]:       2023 :     mxAttributes.set( new FastAttributeList( mxTokenHandler ) );
     194                 :       2023 : }
     195                 :            : 
     196 [ +  - ][ +  - ]:       4027 : Entity::~Entity()
     197                 :            : {
     198                 :       4027 : }
     199                 :            : 
     200                 :            : // --------------------------------------------------------------------
     201                 :            : // FastSaxParser implementation
     202                 :            : // --------------------------------------------------------------------
     203                 :            : 
     204 [ +  - ][ +  - ]:        775 : FastSaxParser::FastSaxParser()
         [ +  - ][ +  - ]
                 [ +  - ]
     205                 :            : {
     206         [ +  - ]:        775 :     mxDocumentLocator.set( new FastLocatorImpl( this ) );
     207                 :        775 : }
     208                 :            : 
     209                 :            : // --------------------------------------------------------------------
     210                 :            : 
     211 [ +  - ][ +  - ]:        775 : FastSaxParser::~FastSaxParser()
                 [ +  - ]
     212                 :            : {
     213         [ +  - ]:        775 :     if( mxDocumentLocator.is() )
     214                 :        775 :         mxDocumentLocator->dispose();
     215         [ -  + ]:       1550 : }
     216                 :            : 
     217                 :            : // --------------------------------------------------------------------
     218                 :            : 
     219                 :      90706 : void FastSaxParser::pushContext()
     220                 :            : {
     221                 :      90706 :     Entity& rEntity = getEntity();
     222         [ +  + ]:      90706 :     if( rEntity.maContextStack.empty() )
     223                 :            :     {
     224 [ +  - ][ +  - ]:       2004 :         rEntity.maContextStack.push( SaxContextImplPtr( new SaxContextImpl ) );
     225         [ +  - ]:       2004 :         DefineNamespace( OString("xml"), "http://www.w3.org/XML/1998/namespace");
     226                 :            :     }
     227                 :            :     else
     228                 :            :     {
     229 [ +  - ][ +  - ]:      88702 :         rEntity.maContextStack.push( SaxContextImplPtr( new SaxContextImpl( rEntity.maContextStack.top() ) ) );
     230                 :            :     }
     231                 :      90706 : }
     232                 :            : 
     233                 :            : // --------------------------------------------------------------------
     234                 :            : 
     235                 :      90688 : void FastSaxParser::popContext()
     236                 :            : {
     237                 :      90688 :     Entity& rEntity = getEntity();
     238                 :            :     OSL_ENSURE( !rEntity.maContextStack.empty(), "sax::FastSaxParser::popContext(), pop without push?" );
     239         [ +  - ]:      90688 :     if( !rEntity.maContextStack.empty() )
     240                 :      90688 :         rEntity.maContextStack.pop();
     241                 :      90688 : }
     242                 :            : 
     243                 :            : // --------------------------------------------------------------------
     244                 :            : 
     245                 :       7395 : void FastSaxParser::DefineNamespace( const OString& rPrefix, const sal_Char* pNamespaceURL )
     246                 :            : {
     247                 :       7395 :     Entity& rEntity = getEntity();
     248                 :            :     OSL_ENSURE( !rEntity.maContextStack.empty(), "sax::FastSaxParser::DefineNamespace(), I need a context!" );
     249         [ +  - ]:       7395 :     if( !rEntity.maContextStack.empty() )
     250                 :            :     {
     251         [ +  - ]:       7395 :         sal_uInt32 nOffset = rEntity.maContextStack.top()->mnNamespaceCount++;
     252                 :            : 
     253         [ +  + ]:       7395 :         if( rEntity.maNamespaceDefines.size() <= nOffset )
     254         [ +  - ]:       2004 :             rEntity.maNamespaceDefines.resize( rEntity.maNamespaceDefines.size() + 64 );
     255                 :            : 
     256         [ +  - ]:       7395 :         const OUString aNamespaceURL( pNamespaceURL, strlen( pNamespaceURL ), RTL_TEXTENCODING_UTF8 );
     257 [ +  - ][ +  - ]:       7395 :         rEntity.maNamespaceDefines[nOffset].reset( new NamespaceDefine( rPrefix, GetNamespaceToken( aNamespaceURL ), aNamespaceURL ) );
                 [ +  - ]
     258                 :            :     }
     259                 :       7395 : }
     260                 :            : 
     261                 :            : // --------------------------------------------------------------------
     262                 :            : 
     263                 :      41971 : sal_Int32 FastSaxParser::GetToken( const OString& rToken )
     264                 :            : {
     265         [ +  - ]:      41971 :     Sequence< sal_Int8 > aSeq( (sal_Int8*)rToken.getStr(), rToken.getLength() );
     266                 :            : 
     267 [ +  - ][ +  - ]:      41971 :     return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
         [ +  - ][ +  - ]
     268                 :            : }
     269                 :            : 
     270                 :     116330 : sal_Int32 FastSaxParser::GetToken( const sal_Char* pToken, sal_Int32 nLen /* = 0 */ )
     271                 :            : {
     272         [ +  + ]:     116330 :     if( !nLen )
     273                 :         12 :         nLen = strlen( pToken );
     274                 :            : 
     275         [ +  - ]:     116330 :     Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen );
     276                 :            : 
     277 [ +  - ][ +  - ]:     116330 :     return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
         [ +  - ][ +  - ]
     278                 :            : }
     279                 :            : 
     280                 :            : // --------------------------------------------------------------------
     281                 :            : 
     282                 :      44610 : sal_Int32 FastSaxParser::GetTokenWithPrefix( const OString& rPrefix, const OString& rName ) throw (SAXException)
     283                 :            : {
     284                 :      44610 :     sal_Int32 nNamespaceToken = FastToken::DONTKNOW;
     285                 :            : 
     286                 :      44610 :     Entity& rEntity = getEntity();
     287                 :      44610 :     sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
     288         [ +  - ]:      91163 :     while( nNamespace-- )
     289                 :            :     {
     290         [ +  + ]:      91163 :         if( rEntity.maNamespaceDefines[nNamespace]->maPrefix == rPrefix )
     291                 :            :         {
     292                 :      44610 :             nNamespaceToken = rEntity.maNamespaceDefines[nNamespace]->mnToken;
     293                 :      44610 :             break;
     294                 :            :         }
     295                 :            : 
     296         [ -  + ]:      46553 :         if( !nNamespace )
     297         [ #  # ]:          0 :             throw SAXException(); // prefix that has no defined namespace url
     298                 :            :     }
     299                 :            : 
     300         [ +  + ]:      44610 :     if( nNamespaceToken != FastToken::DONTKNOW )
     301                 :            :     {
     302                 :      43991 :         sal_Int32 nNameToken = GetToken( rName.getStr(), rName.getLength() );
     303         [ +  - ]:      43991 :         if( nNameToken != FastToken::DONTKNOW )
     304                 :      43991 :             return nNamespaceToken | nNameToken;
     305                 :            :     }
     306                 :            : 
     307                 :      44610 :     return FastToken::DONTKNOW;
     308                 :            : }
     309                 :            : 
     310                 :      62590 : sal_Int32 FastSaxParser::GetTokenWithPrefix( const sal_Char*pPrefix, int nPrefixLen, const sal_Char* pName, int nNameLen ) throw (SAXException)
     311                 :            : {
     312                 :      62590 :     sal_Int32 nNamespaceToken = FastToken::DONTKNOW;
     313                 :            : 
     314                 :      62590 :     Entity& rEntity = getEntity();
     315                 :      62590 :     sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
     316         [ +  - ]:     118195 :     while( nNamespace-- )
     317                 :            :     {
     318                 :     118195 :         const OString& rPrefix( rEntity.maNamespaceDefines[nNamespace]->maPrefix );
     319         [ +  + ]:     194649 :         if( (rPrefix.getLength() == nPrefixLen) &&
           [ +  +  +  + ]
     320                 :      76454 :             (strncmp( rPrefix.getStr(), pPrefix, nPrefixLen ) == 0 ) )
     321                 :            :         {
     322                 :      62590 :             nNamespaceToken = rEntity.maNamespaceDefines[nNamespace]->mnToken;
     323                 :      62590 :             break;
     324                 :            :         }
     325                 :            : 
     326         [ -  + ]:      55605 :         if( !nNamespace )
     327         [ #  # ]:          0 :             throw SAXException(); // prefix that has no defined namespace url
     328                 :            :     }
     329                 :            : 
     330         [ +  + ]:      62590 :     if( nNamespaceToken != FastToken::DONTKNOW )
     331                 :            :     {
     332                 :      62569 :         sal_Int32 nNameToken = GetToken( pName, nNameLen );
     333         [ +  - ]:      62569 :         if( nNameToken != FastToken::DONTKNOW )
     334                 :      62569 :             return nNamespaceToken | nNameToken;
     335                 :            :     }
     336                 :            : 
     337                 :      62590 :     return FastToken::DONTKNOW;
     338                 :            : }
     339                 :            : 
     340                 :            : // --------------------------------------------------------------------
     341                 :            : 
     342                 :      24834 : sal_Int32 FastSaxParser::GetNamespaceToken( const OUString& rNamespaceURL )
     343                 :            : {
     344         [ +  - ]:      24834 :     NamespaceMap::iterator aIter( maNamespaceMap.find( rNamespaceURL ) );
     345 [ +  - ][ +  + ]:      24834 :     if( aIter != maNamespaceMap.end() )
     346         [ +  - ]:      15238 :         return (*aIter).second;
     347                 :            :     else
     348                 :      24834 :         return FastToken::DONTKNOW;
     349                 :            : }
     350                 :            : 
     351                 :            : // --------------------------------------------------------------------
     352                 :            : 
     353                 :        631 : OUString FastSaxParser::GetNamespaceURL( const OString& rPrefix ) throw (SAXException)
     354                 :            : {
     355                 :        631 :     Entity& rEntity = getEntity();
     356         [ +  - ]:        631 :     if( !rEntity.maContextStack.empty() )
     357                 :            :     {
     358                 :        631 :         sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
     359         [ +  - ]:       1936 :         while( nNamespace-- )
     360         [ +  + ]:       1936 :             if( rEntity.maNamespaceDefines[nNamespace]->maPrefix == rPrefix )
     361                 :        631 :                 return rEntity.maNamespaceDefines[nNamespace]->maNamespaceURL;
     362                 :            :     }
     363                 :            : 
     364         [ #  # ]:          0 :     throw SAXException(); // prefix that has no defined namespace url
     365                 :            : }
     366                 :            : 
     367                 :         21 : OUString FastSaxParser::GetNamespaceURL( const sal_Char*pPrefix, int nPrefixLen ) throw(SAXException)
     368                 :            : {
     369                 :         21 :     Entity& rEntity = getEntity();
     370 [ +  - ][ +  - ]:         21 :     if( pPrefix && !rEntity.maContextStack.empty() )
                 [ +  - ]
     371                 :            :     {
     372                 :         21 :         sal_uInt32 nNamespace = rEntity.maContextStack.top()->mnNamespaceCount;
     373         [ +  - ]:         30 :         while( nNamespace-- )
     374                 :            :         {
     375                 :         30 :             const OString& rPrefix( rEntity.maNamespaceDefines[nNamespace]->maPrefix );
     376         [ +  + ]:         51 :             if( (rPrefix.getLength() == nPrefixLen) &&
           [ +  +  +  - ]
     377                 :         21 :                 (strncmp( rPrefix.getStr(), pPrefix, nPrefixLen ) == 0 ) )
     378                 :            :             {
     379                 :         21 :                 return rEntity.maNamespaceDefines[nNamespace]->maNamespaceURL;
     380                 :            :             }
     381                 :            :         }
     382                 :            :     }
     383                 :            : 
     384         [ #  # ]:          0 :     throw SAXException(); // prefix that has no defined namespace url
     385                 :            : }
     386                 :            : 
     387                 :            : // --------------------------------------------------------------------
     388                 :            : 
     389                 :       9758 : sal_Int32 FastSaxParser::GetTokenWithNamespaceURL( const OUString& rNamespaceURL, const sal_Char* pName, int nNameLen )
     390                 :            : {
     391                 :       9758 :     sal_Int32 nNamespaceToken = GetNamespaceToken( rNamespaceURL );
     392                 :            : 
     393         [ +  - ]:       9758 :     if( nNamespaceToken != FastToken::DONTKNOW )
     394                 :            :     {
     395                 :       9758 :         sal_Int32 nNameToken = GetToken( pName, nNameLen );
     396         [ +  - ]:       9758 :         if( nNameToken != FastToken::DONTKNOW )
     397                 :       9758 :             return nNamespaceToken | nNameToken;
     398                 :            :     }
     399                 :            : 
     400                 :       9758 :     return FastToken::DONTKNOW;
     401                 :            : }
     402                 :            : 
     403                 :            : // --------------------------------------------------------------------
     404                 :            : 
     405                 :     165199 : void FastSaxParser::splitName( const XML_Char *pwName, const XML_Char *&rpPrefix, sal_Int32 &rPrefixLen, const XML_Char *&rpName, sal_Int32 &rNameLen )
     406                 :            : {
     407                 :            :     XML_Char *p;
     408         [ +  + ]:    1314851 :     for( p = const_cast< XML_Char* >( pwName ), rNameLen = 0, rPrefixLen = 0; *p; p++ )
     409                 :            :     {
     410         [ +  + ]:    1149652 :         if( *p == ':' )
     411                 :            :         {
     412                 :     112591 :             rPrefixLen = p - pwName;
     413                 :     112591 :             rNameLen = 0;
     414                 :            :         }
     415                 :            :         else
     416                 :            :         {
     417                 :    1037061 :             rNameLen++;
     418                 :            :         }
     419                 :            :     }
     420         [ +  + ]:     165199 :     if( rPrefixLen )
     421                 :            :     {
     422                 :     112591 :         rpPrefix = pwName;
     423                 :     112591 :         rpName = &pwName[ rPrefixLen + 1 ];
     424                 :            :     }
     425                 :            :     else
     426                 :            :     {
     427                 :      52608 :         rpPrefix = 0;
     428                 :      52608 :         rpName = pwName;
     429                 :            :     }
     430                 :     165199 : }
     431                 :            : 
     432                 :            : /***************
     433                 :            : *
     434                 :            : * parseStream does Parser-startup initializations. The FastSaxParser::parse() method does
     435                 :            : * the file-specific initialization work. (During a parser run, external files may be opened)
     436                 :            : *
     437                 :            : ****************/
     438                 :       2023 : void FastSaxParser::parseStream( const InputSource& maStructSource) throw (SAXException, IOException, RuntimeException)
     439                 :            : {
     440                 :            :     // Only one text at one time
     441         [ +  - ]:       2023 :     MutexGuard guard( maMutex );
     442                 :            : 
     443         [ +  - ]:       2023 :     Entity entity( maData );
     444         [ +  - ]:       2023 :     entity.maStructSource = maStructSource;
     445                 :            : 
     446         [ +  + ]:       2023 :     if( !entity.maStructSource.aInputStream.is() )
     447         [ +  - ]:         19 :         throw SAXException( OUString(  "No input source" ), Reference< XInterface >(), Any() );
     448                 :            : 
     449         [ +  - ]:       2004 :     entity.maConverter.setInputStream( entity.maStructSource.aInputStream );
     450         [ -  + ]:       2004 :     if( !entity.maStructSource.sEncoding.isEmpty() )
     451         [ #  # ]:          0 :         entity.maConverter.setEncoding( OUStringToOString( entity.maStructSource.sEncoding, RTL_TEXTENCODING_ASCII_US ) );
     452                 :            : 
     453                 :            :     // create parser with proper encoding
     454         [ +  - ]:       2004 :     entity.mpParser = XML_ParserCreate( 0 );
     455         [ -  + ]:       2004 :     if( !entity.mpParser )
     456         [ #  # ]:          0 :         throw SAXException( OUString( "Couldn't create parser" ), Reference< XInterface >(), Any() );
     457                 :            : 
     458                 :            :     // set all necessary C-Callbacks
     459         [ +  - ]:       2004 :     XML_SetUserData( entity.mpParser, this );
     460         [ +  - ]:       2004 :     XML_SetElementHandler( entity.mpParser, call_callbackStartElement, call_callbackEndElement );
     461         [ +  - ]:       2004 :     XML_SetCharacterDataHandler( entity.mpParser, call_callbackCharacters );
     462         [ +  - ]:       2004 :     XML_SetEntityDeclHandler(entity.mpParser, call_callbackEntityDecl);
     463         [ +  - ]:       2004 :     XML_SetExternalEntityRefHandler( entity.mpParser, call_callbackExternalEntityRef );
     464                 :            : 
     465         [ +  - ]:       2004 :     pushEntity( entity );
     466                 :            :     try
     467                 :            :     {
     468                 :            :         // start the document
     469         [ +  - ]:       2004 :         if( entity.mxDocumentHandler.is() )
     470                 :            :         {
     471 [ +  - ][ +  - ]:       2004 :             Reference< XLocator > xLoc( mxDocumentLocator.get() );
     472 [ +  - ][ +  - ]:       2004 :             entity.mxDocumentHandler->setDocumentLocator( xLoc );
     473 [ +  - ][ +  - ]:       2004 :             entity.mxDocumentHandler->startDocument();
     474                 :            :         }
     475                 :            : 
     476         [ +  + ]:       2004 :         parse();
     477                 :            : 
     478                 :            :         // finish document
     479         [ +  - ]:       2001 :         if( entity.mxDocumentHandler.is() )
     480                 :            :         {
     481 [ +  - ][ +  - ]:       2001 :             entity.mxDocumentHandler->endDocument();
     482                 :            :         }
     483                 :            :     }
     484                 :          6 :     catch (const SAXException&)
     485                 :            :     {
     486         [ -  + ]:          3 :         popEntity();
     487         [ -  + ]:          3 :         XML_ParserFree( entity.mpParser );
     488                 :          3 :           throw;
     489                 :            :     }
     490                 :          0 :     catch (const IOException&)
     491                 :            :     {
     492         [ #  # ]:          0 :         popEntity();
     493         [ #  # ]:          0 :         XML_ParserFree( entity.mpParser );
     494                 :          0 :         throw;
     495                 :            :     }
     496   [ -  +  -  - ]:          3 :     catch (const RuntimeException&)
     497                 :            :     {
     498         [ #  # ]:          0 :         popEntity();
     499         [ #  # ]:          0 :         XML_ParserFree( entity.mpParser );
     500                 :          0 :         throw;
     501                 :            :     }
     502                 :            : 
     503         [ +  - ]:       2001 :     popEntity();
     504 [ +  - ][ +  - ]:       2023 :     XML_ParserFree( entity.mpParser );
                 [ +  - ]
     505                 :       2001 : }
     506                 :            : 
     507                 :       2120 : void FastSaxParser::setFastDocumentHandler( const Reference< XFastDocumentHandler >& Handler ) throw (RuntimeException)
     508                 :            : {
     509                 :       2120 :     maData.mxDocumentHandler = Handler;
     510                 :       2120 : }
     511                 :            : 
     512                 :       1910 : void SAL_CALL FastSaxParser::setTokenHandler( const Reference< XFastTokenHandler >& Handler ) throw (RuntimeException)
     513                 :            : {
     514                 :       1910 :     maData.mxTokenHandler = Handler;
     515                 :       1910 : }
     516                 :            : 
     517                 :       7681 : void SAL_CALL FastSaxParser::registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken ) throw (IllegalArgumentException, RuntimeException)
     518                 :            : {
     519         [ +  - ]:       7681 :     if( NamespaceToken >= FastToken::NAMESPACE )
     520                 :            :     {
     521         [ +  - ]:       7681 :         if( GetNamespaceToken( NamespaceURL ) == FastToken::DONTKNOW )
     522                 :            :         {
     523                 :       7681 :             maNamespaceMap[ NamespaceURL ] = NamespaceToken;
     524                 :       7681 :             return;
     525                 :            :         }
     526                 :            :     }
     527         [ #  # ]:          0 :     throw IllegalArgumentException();
     528                 :            : }
     529                 :            : 
     530                 :         12 : OUString SAL_CALL FastSaxParser::getNamespaceURL( const OUString& rPrefix ) throw(IllegalArgumentException, RuntimeException)
     531                 :            : {
     532                 :            :     try
     533                 :            :     {
     534 [ +  - ][ +  - ]:         12 :         return GetNamespaceURL( OUStringToOString( rPrefix, RTL_TEXTENCODING_UTF8 ) );
                 [ #  # ]
     535                 :            :     }
     536                 :          0 :     catch (const Exception&)
     537                 :            :     {
     538                 :            :     }
     539         [ #  # ]:          0 :     throw IllegalArgumentException();
     540                 :            : }
     541                 :            : 
     542                 :          0 : void FastSaxParser::setErrorHandler(const Reference< XErrorHandler > & Handler) throw (RuntimeException)
     543                 :            : {
     544                 :          0 :     maData.mxErrorHandler = Handler;
     545                 :          0 : }
     546                 :            : 
     547                 :          0 : void FastSaxParser::setEntityResolver(const Reference < XEntityResolver > & Resolver) throw (RuntimeException)
     548                 :            : {
     549                 :          0 :     maData.mxEntityResolver = Resolver;
     550                 :          0 : }
     551                 :            : 
     552                 :          0 : void FastSaxParser::setLocale( const Locale & Locale ) throw (RuntimeException)
     553                 :            : {
     554                 :          0 :     maData.maLocale = Locale;
     555                 :          0 : }
     556                 :            : 
     557                 :         26 : Sequence< OUString > FastSaxParser::getSupportedServiceNames_Static(void)
     558                 :            : {
     559                 :         26 :     Sequence<OUString> aRet(1);
     560         [ +  - ]:         26 :     aRet.getArray()[0] = ::rtl::OUString( PARSER_SERVICE_NAME );
     561                 :         26 :     return aRet;
     562                 :            : }
     563                 :            : 
     564                 :            : // XServiceInfo
     565                 :          0 : OUString FastSaxParser::getImplementationName() throw (RuntimeException)
     566                 :            : {
     567                 :          0 :     return OUString( PARSER_IMPLEMENTATION_NAME );
     568                 :            : }
     569                 :            : 
     570                 :            : // XServiceInfo
     571                 :          0 : sal_Bool FastSaxParser::supportsService(const OUString& ServiceName) throw (RuntimeException)
     572                 :            : {
     573         [ #  # ]:          0 :     Sequence< OUString > aSNL = getSupportedServiceNames();
     574                 :          0 :     const OUString * pArray = aSNL.getConstArray();
     575                 :            : 
     576         [ #  # ]:          0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
     577         [ #  # ]:          0 :         if( pArray[i] == ServiceName )
     578                 :          0 :             return sal_True;
     579                 :            : 
     580         [ #  # ]:          0 :     return sal_False;
     581                 :            : }
     582                 :            : 
     583                 :            : // XServiceInfo
     584                 :          0 : Sequence< OUString > FastSaxParser::getSupportedServiceNames(void) throw (RuntimeException)
     585                 :            : {
     586                 :            : 
     587                 :          0 :     Sequence<OUString> seq(1);
     588         [ #  # ]:          0 :     seq.getArray()[0] = OUString( PARSER_SERVICE_NAME );
     589                 :          0 :     return seq;
     590                 :            : }
     591                 :            : 
     592                 :            : 
     593                 :            : /*---------------------------------------
     594                 :            : *
     595                 :            : * Helper functions and classes
     596                 :            : *
     597                 :            : *-------------------------------------------*/
     598                 :            : 
     599                 :            : namespace {
     600                 :            : 
     601                 :          3 : OUString lclGetErrorMessage( XML_Error xmlE, const OUString& sSystemId, sal_Int32 nLine )
     602                 :            : {
     603                 :          3 :     const sal_Char* pMessage = "";
     604   [ -  -  -  -  :          3 :     switch( xmlE )
          -  -  -  +  -  
          -  -  -  -  -  
          -  -  -  -  -  
             -  -  -  -  
                      - ]
     605                 :            :     {
     606                 :          0 :         case XML_ERROR_NONE:                            pMessage = "No";                                    break;
     607                 :          0 :         case XML_ERROR_NO_MEMORY:                       pMessage = "no memory";                             break;
     608                 :          0 :         case XML_ERROR_SYNTAX:                          pMessage = "syntax";                                break;
     609                 :          0 :         case XML_ERROR_NO_ELEMENTS:                     pMessage = "no elements";                           break;
     610                 :          0 :         case XML_ERROR_INVALID_TOKEN:                   pMessage = "invalid token";                         break;
     611                 :          0 :         case XML_ERROR_UNCLOSED_TOKEN:                  pMessage = "unclosed token";                        break;
     612                 :          0 :         case XML_ERROR_PARTIAL_CHAR:                    pMessage = "partial char";                          break;
     613                 :          3 :         case XML_ERROR_TAG_MISMATCH:                    pMessage = "tag mismatch";                          break;
     614                 :          0 :         case XML_ERROR_DUPLICATE_ATTRIBUTE:             pMessage = "duplicate attribute";                   break;
     615                 :          0 :         case XML_ERROR_JUNK_AFTER_DOC_ELEMENT:          pMessage = "junk after doc element";                break;
     616                 :          0 :         case XML_ERROR_PARAM_ENTITY_REF:                pMessage = "parameter entity reference";            break;
     617                 :          0 :         case XML_ERROR_UNDEFINED_ENTITY:                pMessage = "undefined entity";                      break;
     618                 :          0 :         case XML_ERROR_RECURSIVE_ENTITY_REF:            pMessage = "recursive entity reference";            break;
     619                 :          0 :         case XML_ERROR_ASYNC_ENTITY:                    pMessage = "async entity";                          break;
     620                 :          0 :         case XML_ERROR_BAD_CHAR_REF:                    pMessage = "bad char reference";                    break;
     621                 :          0 :         case XML_ERROR_BINARY_ENTITY_REF:               pMessage = "binary entity reference";               break;
     622                 :          0 :         case XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF:   pMessage = "attribute external entity reference";   break;
     623                 :          0 :         case XML_ERROR_MISPLACED_XML_PI:                pMessage = "misplaced xml processing instruction";  break;
     624                 :          0 :         case XML_ERROR_UNKNOWN_ENCODING:                pMessage = "unknown encoding";                      break;
     625                 :          0 :         case XML_ERROR_INCORRECT_ENCODING:              pMessage = "incorrect encoding";                    break;
     626                 :          0 :         case XML_ERROR_UNCLOSED_CDATA_SECTION:          pMessage = "unclosed cdata section";                break;
     627                 :          0 :         case XML_ERROR_EXTERNAL_ENTITY_HANDLING:        pMessage = "external entity reference";             break;
     628                 :          0 :         case XML_ERROR_NOT_STANDALONE:                  pMessage = "not standalone";                        break;
     629                 :            :         default:;
     630                 :            :     }
     631                 :            : 
     632                 :          3 :     OUStringBuffer aBuffer( sal_Unicode( '[' ) );
     633         [ +  - ]:          3 :     aBuffer.append( sSystemId );
     634         [ +  - ]:          3 :     aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " line " ) );
     635         [ +  - ]:          3 :     aBuffer.append( nLine );
     636         [ +  - ]:          3 :     aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "]: " ) );
     637         [ +  - ]:          3 :     aBuffer.appendAscii( pMessage );
     638         [ +  - ]:          3 :     aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " error" ) );
     639         [ +  - ]:          3 :     return aBuffer.makeStringAndClear();
     640                 :            : }
     641                 :            : 
     642                 :            : } // namespace
     643                 :            : 
     644                 :            : // starts parsing with actual parser !
     645                 :       2004 : void FastSaxParser::parse()
     646                 :            : {
     647                 :       2004 :     const int BUFFER_SIZE = 16 * 1024;
     648         [ +  - ]:       2004 :     Sequence< sal_Int8 > seqOut( BUFFER_SIZE );
     649                 :            : 
     650         [ +  - ]:       2004 :     Entity& rEntity = getEntity();
     651                 :       2004 :     int nRead = 0;
     652         [ +  - ]:       2034 :     do
     653                 :            :     {
     654         [ +  - ]:       4038 :         nRead = rEntity.maConverter.readAndConvert( seqOut, BUFFER_SIZE );
     655         [ +  + ]:       4038 :         if( nRead <= 0 )
     656                 :            :         {
     657         [ +  - ]:       2001 :             XML_Parse( rEntity.mpParser, (const char*) seqOut.getConstArray(), 0, 1 );
     658                 :       2001 :             break;
     659                 :            :         }
     660                 :            : 
     661                 :            :         bool const bContinue = XML_STATUS_ERROR != XML_Parse(rEntity.mpParser,
     662         [ +  - ]:       2037 :             reinterpret_cast<const char*>(seqOut.getConstArray()), nRead, 0);
     663                 :            :         // callbacks used inside XML_Parse may have caught an exception
     664 [ +  + ][ -  + ]:       2037 :         if( !bContinue || rEntity.maSavedException.hasValue() )
                 [ +  + ]
     665                 :            :         {
     666                 :            :             // Error during parsing !
     667         [ +  - ]:          3 :             XML_Error xmlE = XML_GetErrorCode( rEntity.mpParser );
     668         [ +  - ]:          3 :             OUString sSystemId = mxDocumentLocator->getSystemId();
     669         [ +  - ]:          3 :             sal_Int32 nLine = mxDocumentLocator->getLineNumber();
     670                 :            : 
     671                 :            :             SAXParseException aExcept(
     672                 :            :                 lclGetErrorMessage( xmlE, sSystemId, nLine ),
     673                 :            :                 Reference< XInterface >(),
     674         [ +  - ]:          3 :                 Any( &rEntity.maSavedException, getCppuType( &rEntity.maSavedException ) ),
     675                 :          3 :                 mxDocumentLocator->getPublicId(),
     676                 :          3 :                 mxDocumentLocator->getSystemId(),
     677         [ +  - ]:          3 :                 mxDocumentLocator->getLineNumber(),
     678         [ +  - ]:          3 :                 mxDocumentLocator->getColumnNumber()
     679 [ +  - ][ +  - ]:          9 :             );
           [ +  -  +  - ]
     680                 :            : 
     681                 :            :             // error handler is set, it may throw the exception
     682         [ -  + ]:          3 :             if( rEntity.mxErrorHandler.is() )
     683 [ #  # ][ #  # ]:          0 :                 rEntity.mxErrorHandler->fatalError( Any( aExcept ) );
                 [ #  # ]
     684                 :            : 
     685                 :            :             // error handler has not thrown, but parsing cannot go on, the
     686                 :            :             // exception MUST be thrown
     687         [ +  - ]:          3 :             throw aExcept;
     688                 :            :         }
     689                 :            :     }
     690         [ +  - ]:       2004 :     while( nRead > 0 );
     691                 :       2001 : }
     692                 :            : 
     693                 :            : //------------------------------------------
     694                 :            : //
     695                 :            : // The C-Callbacks
     696                 :            : //
     697                 :            : //-----------------------------------------
     698                 :            : 
     699                 :            : namespace {
     700                 :            : 
     701                 :     268236 : struct AttributeData
     702                 :            : {
     703                 :            :     OString             maPrefix;
     704                 :            :     OString             maName;
     705                 :            :     OString             maValue;
     706                 :            : };
     707                 :            : 
     708                 :            : } // namespace
     709                 :            : 
     710                 :      90706 : void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char** awAttributes )
     711                 :            : {
     712                 :      90706 :     Reference< XFastContextHandler > xParentContext;
     713         [ +  - ]:      90706 :     Entity& rEntity = getEntity();
     714         [ +  + ]:      90706 :     if( !rEntity.maContextStack.empty() )
     715                 :            :     {
     716 [ +  - ][ +  - ]:      88702 :         xParentContext = rEntity.maContextStack.top()->mxContext;
     717         [ +  + ]:      88702 :         if( !xParentContext.is() )
     718                 :            :         {
     719                 :            :             // we ignore current elements, so no processing needed
     720         [ +  - ]:      18346 :             pushContext();
     721                 :      90706 :             return;
     722                 :            :         }
     723                 :            :     }
     724                 :            : 
     725         [ +  - ]:      72360 :     pushContext();
     726                 :            : 
     727         [ +  - ]:      72360 :     rEntity.mxAttributes->clear();
     728                 :            : 
     729                 :            :     // create attribute map and process namespace instructions
     730                 :      72360 :     int i = 0;
     731                 :            :     sal_Int32 nNameLen, nPrefixLen;
     732                 :            :     const XML_Char *pName;
     733                 :            :     const XML_Char *pPrefix;
     734                 :            : 
     735                 :            :     try
     736                 :            :     {
     737                 :            :         /*  #158414# Each element may define new namespaces, also for attribues.
     738                 :            :             First, process all namespace attributes and cache other attributes in a
     739                 :            :             vector. Second, process the attributes after namespaces have been
     740                 :            :             initialized. */
     741         [ +  - ]:      72360 :         ::std::vector< AttributeData > aAttribs;
     742                 :            : 
     743                 :            :         // #158414# first: get namespaces
     744         [ +  + ]:     165199 :         for( ; awAttributes[i]; i += 2 )
     745                 :            :         {
     746                 :            :             OSL_ASSERT( awAttributes[i+1] );
     747                 :            : 
     748                 :      92839 :             splitName( awAttributes[i], pPrefix, nPrefixLen, pName, nNameLen );
     749         [ +  + ]:      92839 :             if( nPrefixLen )
     750                 :            :             {
     751 [ +  + ][ +  + ]:      50001 :                 if( (nPrefixLen == 5) && (strncmp( pPrefix, "xmlns", 5 ) == 0) )
     752                 :            :                 {
     753         [ +  - ]:       5391 :                     DefineNamespace( OString( pName, nNameLen ), awAttributes[i+1] );
     754                 :            :                 }
     755                 :            :                 else
     756                 :            :                 {
     757         [ +  - ]:      44610 :                     aAttribs.resize( aAttribs.size() + 1 );
     758         [ +  - ]:      44610 :                     aAttribs.back().maPrefix = OString( pPrefix, nPrefixLen );
     759         [ +  - ]:      44610 :                     aAttribs.back().maName = OString( pName, nNameLen );
     760         [ +  - ]:      50001 :                     aAttribs.back().maValue = OString( awAttributes[i+1] );
     761                 :            :                 }
     762                 :            :             }
     763                 :            :             else
     764                 :            :             {
     765 [ +  + ][ +  + ]:      42838 :                 if( (nNameLen == 5) && (strcmp( pName, "xmlns" ) == 0) )
     766                 :            :                 {
     767                 :            :                     // namespace of the element found
     768 [ +  - ][ +  - ]:        867 :                     rEntity.maContextStack.top()->maNamespace = OUString( awAttributes[i+1], strlen( awAttributes[i+1] ), RTL_TEXTENCODING_UTF8 );
     769                 :            :                 }
     770                 :            :                 else
     771                 :            :                 {
     772         [ +  - ]:      41971 :                     aAttribs.resize( aAttribs.size() + 1 );
     773         [ +  - ]:      41971 :                     aAttribs.back().maName = OString( pName, nNameLen );
     774         [ +  - ]:      41971 :                     aAttribs.back().maValue = OString( awAttributes[i+1] );
     775                 :            :                 }
     776                 :            :             }
     777                 :            :         }
     778                 :            : 
     779                 :            :         // #158414# second: fill attribute list with other attributes
     780 [ +  - ][ +  - ]:     158941 :         for( ::std::vector< AttributeData >::const_iterator aIt = aAttribs.begin(), aEnd = aAttribs.end(); aIt != aEnd; ++aIt )
         [ +  - ][ +  + ]
     781                 :            :         {
     782         [ +  + ]:      86581 :             if( !aIt->maPrefix.isEmpty() )
     783                 :            :             {
     784         [ +  - ]:      44610 :                 sal_Int32 nAttributeToken = GetTokenWithPrefix( aIt->maPrefix, aIt->maName );
     785         [ +  + ]:      44610 :                 if( nAttributeToken != FastToken::DONTKNOW )
     786         [ +  - ]:      43991 :                     rEntity.mxAttributes->add( nAttributeToken, aIt->maValue );
     787                 :            :                 else
     788 [ +  - ][ +  - ]:        619 :                     rEntity.mxAttributes->addUnknown( GetNamespaceURL( aIt->maPrefix ), aIt->maName, aIt->maValue );
     789                 :            :             }
     790                 :            :             else
     791                 :            :             {
     792         [ +  - ]:      41971 :                 sal_Int32 nAttributeToken = GetToken( aIt->maName );
     793         [ +  - ]:      41971 :                 if( nAttributeToken != FastToken::DONTKNOW )
     794         [ +  - ]:      41971 :                     rEntity.mxAttributes->add( nAttributeToken, aIt->maValue );
     795                 :            :                 else
     796         [ #  # ]:          0 :                     rEntity.mxAttributes->addUnknown( aIt->maName, aIt->maValue );
     797                 :            :             }
     798                 :            :         }
     799                 :            : 
     800                 :            :         sal_Int32 nElementToken;
     801                 :      72360 :         splitName( pwName, pPrefix, nPrefixLen, pName, nNameLen );
     802         [ +  + ]:      72360 :         if( nPrefixLen > 0 )
     803         [ +  - ]:      62590 :             nElementToken = GetTokenWithPrefix( pPrefix, nPrefixLen, pName, nNameLen );
     804 [ +  - ][ +  + ]:       9770 :         else if( !rEntity.maContextStack.top()->maNamespace.isEmpty() )
     805 [ +  - ][ +  - ]:       9758 :             nElementToken = GetTokenWithNamespaceURL( rEntity.maContextStack.top()->maNamespace, pName, nNameLen );
     806                 :            :         else
     807         [ +  - ]:         12 :             nElementToken = GetToken( pName );
     808         [ +  - ]:      72360 :         rEntity.maContextStack.top()->mnElementToken = nElementToken;
     809                 :            : 
     810 [ +  - ][ +  - ]:      72360 :         Reference< XFastAttributeList > xAttr( rEntity.mxAttributes.get() );
     811                 :      72360 :         Reference< XFastContextHandler > xContext;
     812         [ +  + ]:      72360 :         if( nElementToken == FastToken::DONTKNOW )
     813                 :            :         {
     814         [ +  - ]:         21 :             if( nPrefixLen > 0 )
     815 [ +  - ][ +  - ]:         21 :                 rEntity.maContextStack.top()->maNamespace = GetNamespaceURL( pPrefix, nPrefixLen );
     816                 :            : 
     817         [ +  - ]:         21 :             const OUString aNamespace( rEntity.maContextStack.top()->maNamespace );
     818         [ +  - ]:         21 :             const OUString aElementName( pPrefix, nPrefixLen, RTL_TEXTENCODING_UTF8 );
     819         [ +  - ]:         21 :             rEntity.maContextStack.top()->maElementName = aElementName;
     820                 :            : 
     821         [ +  - ]:         21 :             if( xParentContext.is() )
     822 [ +  - ][ +  - ]:         21 :                 xContext = xParentContext->createUnknownChildContext( aNamespace, aElementName, xAttr );
                 [ +  - ]
     823                 :            :             else
     824 [ #  # ][ #  # ]:          0 :                 xContext = rEntity.mxDocumentHandler->createUnknownChildContext( aNamespace, aElementName, xAttr );
                 [ #  # ]
     825                 :            : 
     826         [ +  + ]:         21 :             if( xContext.is() )
     827                 :            :             {
     828 [ +  - ][ +  - ]:          9 :                 rEntity.maContextStack.top()->mxContext = xContext;
     829 [ +  - ][ +  - ]:          9 :                 xContext->startUnknownElement( aNamespace, aElementName, xAttr );
     830                 :         21 :             }
     831                 :            :         }
     832                 :            :         else
     833                 :            :         {
     834         [ +  + ]:      72339 :             if( xParentContext.is() )
     835 [ +  - ][ +  - ]:      70335 :                 xContext = xParentContext->createFastChildContext( nElementToken, xAttr );
                 [ +  - ]
     836                 :            :             else
     837 [ +  - ][ +  - ]:       2004 :                 xContext = rEntity.mxDocumentHandler->createFastChildContext( nElementToken, xAttr );
                 [ +  - ]
     838                 :            : 
     839                 :            : 
     840         [ +  + ]:      72339 :             if( xContext.is() )
     841                 :            :             {
     842 [ +  - ][ +  - ]:      67751 :                 rEntity.maContextStack.top()->mxContext = xContext;
     843 [ +  - ][ +  - ]:      67751 :                 xContext->startFastElement( nElementToken, xAttr );
     844                 :            :             }
     845                 :      72360 :         }
     846                 :            :     }
     847   [ #  #  #  # ]:          0 :     catch (const Exception& e)
     848                 :            :     {
     849         [ #  # ]:          0 :         rEntity.maSavedException <<= e;
     850         [ +  + ]:      90706 :     }
     851                 :            : }
     852                 :            : 
     853                 :      90688 : void FastSaxParser::callbackEndElement( SAL_UNUSED_PARAMETER const XML_Char* )
     854                 :            : {
     855                 :      90688 :     Entity& rEntity = getEntity();
     856                 :            :     OSL_ENSURE( !rEntity.maContextStack.empty(), "FastSaxParser::callbackEndElement - no context" );
     857         [ +  - ]:      90688 :     if( !rEntity.maContextStack.empty() )
     858                 :            :     {
     859 [ +  - ][ +  - ]:      90688 :         SaxContextImplPtr pContext = rEntity.maContextStack.top();
     860                 :      90688 :         const Reference< XFastContextHandler >& xContext( pContext->mxContext );
     861         [ +  + ]:      90688 :         if( xContext.is() ) try
     862                 :            :         {
     863                 :      67742 :             sal_Int32 nElementToken = pContext->mnElementToken;
     864         [ +  + ]:      67742 :             if( nElementToken != FastToken::DONTKNOW )
     865 [ +  - ][ +  - ]:      67733 :                 xContext->endFastElement( nElementToken );
     866                 :            :             else
     867 [ +  - ][ +  - ]:          9 :                 xContext->endUnknownElement( pContext->maNamespace, pContext->maElementName );
     868                 :            :         }
     869   [ #  #  #  # ]:          0 :         catch (const Exception& e)
     870                 :            :         {
     871         [ #  # ]:          0 :             rEntity.maSavedException <<= e;
     872                 :            :         }
     873                 :            : 
     874 [ +  - ][ +  - ]:      90688 :         popContext();
     875                 :            :     }
     876                 :      90688 : }
     877                 :            : 
     878                 :            : 
     879                 :      11174 : void FastSaxParser::callbackCharacters( const XML_Char* s, int nLen )
     880                 :            : {
     881                 :      11174 :     Entity& rEntity = getEntity();
     882                 :      11174 :     const Reference< XFastContextHandler >& xContext( rEntity.maContextStack.top()->mxContext );
     883         [ +  + ]:      11174 :     if( xContext.is() ) try
     884                 :            :     {
     885 [ +  - ][ +  - ]:      11123 :         xContext->characters( OUString( s, nLen, RTL_TEXTENCODING_UTF8 ) );
                 [ +  - ]
     886                 :            :     }
     887         [ #  # ]:          0 :     catch (const Exception& e)
     888                 :            :     {
     889         [ #  # ]:          0 :         rEntity.maSavedException <<= e;
     890                 :            :     }
     891                 :      11174 : }
     892                 :            : 
     893                 :          0 : void FastSaxParser::callbackEntityDecl(
     894                 :            :     SAL_UNUSED_PARAMETER const XML_Char * /*entityName*/,
     895                 :            :     SAL_UNUSED_PARAMETER int /*is_parameter_entity*/,
     896                 :            :     const XML_Char *value, SAL_UNUSED_PARAMETER int /*value_length*/,
     897                 :            :     SAL_UNUSED_PARAMETER const XML_Char * /*base*/,
     898                 :            :     SAL_UNUSED_PARAMETER const XML_Char * /*systemId*/,
     899                 :            :     SAL_UNUSED_PARAMETER const XML_Char * /*publicId*/,
     900                 :            :     SAL_UNUSED_PARAMETER const XML_Char * /*notationName*/)
     901                 :            : {
     902         [ #  # ]:          0 :     if (value) { // value != 0 means internal entity
     903                 :            :         OSL_TRACE("FastSaxParser: internal entity declaration, stopping");
     904                 :          0 :         XML_StopParser(getEntity().mpParser, XML_FALSE);
     905         [ #  # ]:          0 :         getEntity().maSavedException <<= SAXParseException(
     906                 :            :             ::rtl::OUString(
     907                 :            :                     "FastSaxParser: internal entity declaration, stopping"),
     908                 :            :             static_cast<OWeakObject*>(this), Any(),
     909                 :          0 :             mxDocumentLocator->getPublicId(),
     910                 :          0 :             mxDocumentLocator->getSystemId(),
     911         [ #  # ]:          0 :             mxDocumentLocator->getLineNumber(),
     912 [ #  # ][ #  # ]:          0 :             mxDocumentLocator->getColumnNumber() );
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     913                 :            :     } else {
     914                 :            :         OSL_TRACE("FastSaxParser: ignoring external entity declaration");
     915                 :            :     }
     916                 :          0 : }
     917                 :            : 
     918                 :          0 : int FastSaxParser::callbackExternalEntityRef(
     919                 :            :     XML_Parser parser, const XML_Char *context,
     920                 :            :     SAL_UNUSED_PARAMETER const XML_Char * /*base*/, const XML_Char *systemId,
     921                 :            :     const XML_Char *publicId )
     922                 :            : {
     923                 :          0 :     bool bOK = true;
     924         [ #  # ]:          0 :     InputSource source;
     925                 :            : 
     926         [ #  # ]:          0 :     Entity& rCurrEntity = getEntity();
     927         [ #  # ]:          0 :     Entity aNewEntity( rCurrEntity );
     928                 :            : 
     929         [ #  # ]:          0 :     if( rCurrEntity.mxEntityResolver.is() ) try
     930                 :            :     {
     931         [ #  # ]:          0 :         aNewEntity.maStructSource = rCurrEntity.mxEntityResolver->resolveEntity(
     932                 :          0 :             OUString( publicId, strlen( publicId ), RTL_TEXTENCODING_UTF8 ) ,
     933 [ #  # ][ #  # ]:          0 :             OUString( systemId, strlen( systemId ), RTL_TEXTENCODING_UTF8 ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     934                 :            :     }
     935         [ #  # ]:          0 :     catch (const SAXParseException & e)
     936                 :            :     {
     937         [ #  # ]:          0 :         rCurrEntity.maSavedException <<= e;
     938                 :          0 :         bOK = false;
     939                 :            :     }
     940   [ #  #  #  #  :          0 :     catch (const SAXException& e)
                      # ]
     941                 :            :     {
     942                 :            :         rCurrEntity.maSavedException <<= SAXParseException(
     943                 :            :             e.Message, e.Context, e.WrappedException,
     944                 :          0 :             mxDocumentLocator->getPublicId(),
     945                 :          0 :             mxDocumentLocator->getSystemId(),
     946         [ #  # ]:          0 :             mxDocumentLocator->getLineNumber(),
     947   [ #  #  #  #  :          0 :             mxDocumentLocator->getColumnNumber() );
          #  #  #  #  #  
                #  #  # ]
     948                 :          0 :         bOK = false;
     949                 :            :     }
     950                 :            : 
     951         [ #  # ]:          0 :     if( aNewEntity.maStructSource.aInputStream.is() )
     952                 :            :     {
     953         [ #  # ]:          0 :         aNewEntity.mpParser = XML_ExternalEntityParserCreate( parser, context, 0 );
     954         [ #  # ]:          0 :         if( !aNewEntity.mpParser )
     955                 :            :         {
     956                 :          0 :             return false;
     957                 :            :         }
     958                 :            : 
     959         [ #  # ]:          0 :         aNewEntity.maConverter.setInputStream( aNewEntity.maStructSource.aInputStream );
     960         [ #  # ]:          0 :         pushEntity( aNewEntity );
     961                 :            :         try
     962                 :            :         {
     963         [ #  # ]:          0 :             parse();
     964                 :            :         }
     965         [ #  # ]:          0 :         catch (const SAXParseException& e)
     966                 :            :         {
     967         [ #  # ]:          0 :             rCurrEntity.maSavedException <<= e;
     968                 :          0 :             bOK = false;
     969                 :            :         }
     970         [ #  # ]:          0 :         catch (const IOException& e)
     971                 :            :         {
     972         [ #  # ]:          0 :             SAXException aEx;
     973         [ #  # ]:          0 :             aEx.WrappedException <<= e;
     974         [ #  # ]:          0 :             rCurrEntity.maSavedException <<= aEx;
     975         [ #  # ]:          0 :             bOK = false;
     976                 :            :         }
     977   [ #  #  #  #  :          0 :         catch (const RuntimeException& e)
                   #  # ]
     978                 :            :         {
     979         [ #  # ]:          0 :             SAXException aEx;
     980         [ #  # ]:          0 :             aEx.WrappedException <<= e;
     981         [ #  # ]:          0 :             rCurrEntity.maSavedException <<= aEx;
     982         [ #  # ]:          0 :             bOK = false;
     983                 :            :         }
     984                 :            : 
     985         [ #  # ]:          0 :         popEntity();
     986         [ #  # ]:          0 :         XML_ParserFree( aNewEntity.mpParser );
     987                 :            :     }
     988                 :            : 
     989 [ #  # ][ #  # ]:          0 :     return bOK;
     990                 :            : }
     991                 :            : 
     992                 :            : } // namespace sax_fastparser
     993                 :            : 
     994                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10