LCOV - code coverage report
Current view: top level - oox/source/core - fragmenthandler2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 75 72.0 %
Date: 2012-08-25 Functions: 16 24 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 38 70 54.3 %

           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 "oox/core/fragmenthandler2.hxx"
      21                 :            : #include "oox/core/xmlfilterbase.hxx"
      22                 :            : 
      23                 :            : namespace oox {
      24                 :            : namespace core {
      25                 :            : 
      26                 :            : // ============================================================================
      27                 :            : 
      28                 :            : using namespace ::com::sun::star::uno;
      29                 :            : using namespace ::com::sun::star::xml::sax;
      30                 :            : 
      31                 :            : using ::rtl::OUString;
      32                 :            : 
      33                 :            : 
      34                 :            : using ::com::sun::star::uno::Sequence;
      35                 :            : 
      36                 :            : // ============================================================================
      37                 :            : 
      38                 :        234 : FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
      39                 :            :     FragmentHandler( rFilter, rFragmentPath ),
      40 [ +  - ][ +  - ]:        234 :     ContextHandler2Helper( bEnableTrimSpace )
      41                 :            : {
      42                 :        234 : }
      43                 :            : 
      44         [ +  - ]:        252 : FragmentHandler2::~FragmentHandler2()
      45                 :            : {
      46         [ -  + ]:        252 : }
      47                 :            : 
      48                 :            : // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
      49                 :            : 
      50                 :        201 : void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException )
      51                 :            : {
      52                 :        201 :     initializeImport();
      53                 :        201 : }
      54                 :            : 
      55                 :        201 : void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException )
      56                 :            : {
      57                 :        201 :     finalizeImport();
      58                 :        201 : }
      59                 :            : 
      60                 :         30 : bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
      61                 :            : {
      62   [ +  +  +  - ]:         30 :     switch( nElement )
      63                 :            :     {
      64                 :            :         case MCE_TOKEN( AlternateContent ):
      65         [ +  - ]:         12 :             aMceState.push_back( MCE_STARTED );
      66                 :         12 :             break;
      67                 :            : 
      68                 :            :         case MCE_TOKEN( Choice ):
      69                 :            :             {
      70 [ +  - ][ +  - ]:         12 :                 OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString(RTL_CONSTASCII_USTRINGPARAM("none")) );
      71 [ +  - ][ +  - ]:         12 :                 aRequires = getFilter().getNamespaceURL( aRequires );
      72 [ +  - ][ +  + ]:         12 :                 if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
                 [ +  - ]
      73         [ +  - ]:          9 :                     aMceState.back() = MCE_FOUND_CHOICE;
      74                 :            :                 else
      75         [ +  + ]:         12 :                     return false;
      76                 :            :             }
      77                 :         12 :             break;
      78                 :            : 
      79                 :            :         case MCE_TOKEN( Fallback ):
      80 [ +  - ][ +  + ]:          6 :             if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
                 [ +  + ]
      81                 :          3 :                 break;
      82                 :          3 :             return false;
      83                 :            :         default:
      84                 :            :             {
      85         [ #  # ]:          0 :                 OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
      86         [ #  # ]:          0 :                 if( !str.isEmpty() )
      87                 :            :                 {
      88 [ #  # ][ #  # ]:          0 :                     Sequence< ::com::sun::star::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
         [ #  # ][ #  # ]
      89                 :            :                     // printf("MCE: %s\n", ::rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
      90                 :            :                     // TODO: Check & Get the namespaces in "Ignorable"
      91                 :            :                     // printf("NS: %d : %s\n", attrs.getLength(), ::rtl::OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
      92                 :          0 :                 }
      93                 :            :             }
      94                 :          0 :             return false;
      95                 :            :     }
      96                 :         30 :     return true;
      97                 :            : }
      98                 :            : 
      99                 :            : 
     100                 :            : 
     101                 :            : // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
     102                 :            : 
     103                 :       3432 : Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
     104                 :            :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
     105                 :            : {
     106         [ +  + ]:       3432 :     if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
     107                 :            :     {
     108 [ +  - ][ +  + ]:         30 :         if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
     109                 :         24 :             return getFastContextHandler();
     110                 :          6 :         return NULL;
     111                 :            :     }
     112                 :       3432 :     return implCreateChildContext( nElement, rxAttribs );
     113                 :            : }
     114                 :            : 
     115                 :       1434 : void SAL_CALL FragmentHandler2::startFastElement(
     116                 :            :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
     117                 :            : {
     118                 :       1434 :     implStartElement( nElement, rxAttribs );
     119                 :       1434 : }
     120                 :            : 
     121                 :        831 : void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException )
     122                 :            : {
     123                 :        831 :     implCharacters( rChars );
     124                 :        831 : }
     125                 :            : 
     126                 :       1434 : void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
     127                 :            : {
     128                 :            :     /* If MCE */
     129         [ +  + ]:       1434 :     switch( nElement )
     130                 :            :     {
     131                 :            :         case MCE_TOKEN( AlternateContent ):
     132                 :         12 :             aMceState.pop_back();
     133                 :         12 :             break;
     134                 :            :     }
     135                 :            : 
     136                 :       1434 :     implEndElement( nElement );
     137                 :       1434 : }
     138                 :            : 
     139                 :            : // oox.core.ContextHandler interface ------------------------------------------
     140                 :            : 
     141                 :          0 : ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     142                 :            : {
     143                 :          0 :     return implCreateRecordContext( nRecId, rStrm );
     144                 :            : }
     145                 :            : 
     146                 :          0 : void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
     147                 :            : {
     148                 :          0 :     implStartRecord( nRecId, rStrm );
     149                 :          0 : }
     150                 :            : 
     151                 :          0 : void FragmentHandler2::endRecord( sal_Int32 nRecId )
     152                 :            : {
     153                 :          0 :     implEndRecord( nRecId );
     154                 :          0 : }
     155                 :            : 
     156                 :            : // oox.core.ContextHandler2Helper interface -----------------------------------
     157                 :            : 
     158                 :          0 : ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
     159                 :            : {
     160                 :          0 :     return 0;
     161                 :            : }
     162                 :            : 
     163                 :       1434 : void FragmentHandler2::onStartElement( const AttributeList& )
     164                 :            : {
     165                 :       1434 : }
     166                 :            : 
     167                 :         93 : void FragmentHandler2::onCharacters( const OUString& )
     168                 :            : {
     169                 :         93 : }
     170                 :            : 
     171                 :       1362 : void FragmentHandler2::onEndElement()
     172                 :            : {
     173                 :       1362 : }
     174                 :            : 
     175                 :          0 : ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
     176                 :            : {
     177                 :          0 :     return 0;
     178                 :            : }
     179                 :            : 
     180                 :          0 : void FragmentHandler2::onStartRecord( SequenceInputStream& )
     181                 :            : {
     182                 :          0 : }
     183                 :            : 
     184                 :          0 : void FragmentHandler2::onEndRecord()
     185                 :            : {
     186                 :          0 : }
     187                 :            : 
     188                 :            : // oox.core.FragmentHandler2 interface ----------------------------------------
     189                 :            : 
     190                 :        141 : void FragmentHandler2::initializeImport()
     191                 :            : {
     192                 :        141 : }
     193                 :            : 
     194                 :         27 : void FragmentHandler2::finalizeImport()
     195                 :            : {
     196                 :         27 : }
     197                 :            : 
     198                 :            : // ============================================================================
     199                 :            : 
     200                 :            : } // namespace core
     201 [ +  - ][ +  - ]:        285 : } // namespace oox
     202                 :            : 
     203                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10