LCOV - code coverage report
Current view: top level - oox/source/core - fragmenthandler2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 62 76 81.6 %
Date: 2015-06-13 12:38:46 Functions: 21 24 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "oox/core/fragmenthandler2.hxx"
      21             : #include "oox/core/xmlfilterbase.hxx"
      22             : 
      23             : namespace oox {
      24             : namespace core {
      25             : 
      26             : using namespace ::com::sun::star::uno;
      27             : using namespace ::com::sun::star::xml::sax;
      28             : 
      29             : using ::com::sun::star::uno::Sequence;
      30             : 
      31        8136 : FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
      32             :     FragmentHandler( rFilter, rFragmentPath ),
      33        8136 :     ContextHandler2Helper( bEnableTrimSpace )
      34             : {
      35        8136 : }
      36             : 
      37        8720 : FragmentHandler2::~FragmentHandler2()
      38             : {
      39        8720 : }
      40             : 
      41             : // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
      42             : 
      43        2892 : void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException, std::exception )
      44             : {
      45        2892 :     initializeImport();
      46        2892 : }
      47             : 
      48        2807 : void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException, std::exception )
      49             : {
      50        2807 :     finalizeImport();
      51        2807 : }
      52             : 
      53         349 : bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
      54             : {
      55         349 :     switch( nElement )
      56             :     {
      57             :         case MCE_TOKEN( AlternateContent ):
      58         129 :             aMceState.push_back( MCE_STARTED );
      59         129 :             break;
      60             : 
      61             :         case MCE_TOKEN( Choice ):
      62             :             {
      63         129 :                 OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString("none") );
      64         129 :                 if (!getFilter().hasNamespaceURL(aRequires))
      65             :                     // Check to see if we have this namespace defined first,
      66             :                     // because calling getNamespaceURL() would throw if the
      67             :                     // namespace doesn't exist.
      68         129 :                     return false;
      69             : 
      70           0 :                 aRequires = getFilter().getNamespaceURL( aRequires );
      71           0 :                 if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
      72           0 :                     aMceState.back() = MCE_FOUND_CHOICE;
      73             :                 else
      74           0 :                     return false;
      75             :             }
      76           0 :             break;
      77             : 
      78             :         case MCE_TOKEN( Fallback ):
      79          91 :             if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
      80          91 :                 break;
      81           0 :             return false;
      82             :         default:
      83             :             {
      84           0 :                 OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
      85           0 :                 if( !str.isEmpty() )
      86             :                 {
      87             :                     // Sequence< ::com::sun::star::xml::FastAttribute > attrs = rAttribs.getFastAttributeList()->getFastAttributes();
      88             :                     // printf("MCE: %s\n", OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
      89             :                     // TODO: Check & Get the namespaces in "Ignorable"
      90             :                     // printf("NS: %d : %s\n", attrs.getLength(), OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
      91           0 :                 }
      92             :             }
      93           0 :             return false;
      94             :     }
      95         220 :     return true;
      96             : }
      97             : 
      98             : // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
      99             : 
     100       57854 : Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
     101             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException, std::exception )
     102             : {
     103       57854 :     if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
     104             :     {
     105         349 :         if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
     106         220 :             return getFastContextHandler();
     107         129 :         return NULL;
     108             :     }
     109       57505 :     return implCreateChildContext( nElement, rxAttribs );
     110             : }
     111             : 
     112       14495 : void SAL_CALL FragmentHandler2::startFastElement(
     113             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException, std::exception )
     114             : {
     115       14495 :     implStartElement( nElement, rxAttribs );
     116       14495 : }
     117             : 
     118        1355 : void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException, std::exception )
     119             : {
     120        1355 :     implCharacters( rChars );
     121        1355 : }
     122             : 
     123       14493 : void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException, std::exception )
     124             : {
     125             :     /* If MCE */
     126       14493 :     switch( nElement )
     127             :     {
     128             :         case MCE_TOKEN( AlternateContent ):
     129         129 :             aMceState.pop_back();
     130         129 :             break;
     131             :     }
     132             : 
     133       14493 :     implEndElement( nElement );
     134       14493 : }
     135             : 
     136             : // oox.core.ContextHandler interface ------------------------------------------
     137             : 
     138         132 : ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     139             : {
     140         132 :     return implCreateRecordContext( nRecId, rStrm );
     141             : }
     142             : 
     143          78 : void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
     144             : {
     145          78 :     implStartRecord( nRecId, rStrm );
     146          78 : }
     147             : 
     148          78 : void FragmentHandler2::endRecord( sal_Int32 nRecId )
     149             : {
     150          78 :     implEndRecord( nRecId );
     151          78 : }
     152             : 
     153             : // oox.core.ContextHandler2Helper interface -----------------------------------
     154             : 
     155           0 : ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
     156             : {
     157           0 :     return 0;
     158             : }
     159             : 
     160       11077 : void FragmentHandler2::onStartElement( const AttributeList& )
     161             : {
     162       11077 : }
     163             : 
     164         297 : void FragmentHandler2::onCharacters( const OUString& )
     165             : {
     166         297 : }
     167             : 
     168        9694 : void FragmentHandler2::onEndElement()
     169             : {
     170        9694 : }
     171             : 
     172           0 : ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
     173             : {
     174           0 :     return 0;
     175             : }
     176             : 
     177          78 : void FragmentHandler2::onStartRecord( SequenceInputStream& )
     178             : {
     179          78 : }
     180             : 
     181          70 : void FragmentHandler2::onEndRecord()
     182             : {
     183          70 : }
     184             : 
     185             : // oox.core.FragmentHandler2 interface ----------------------------------------
     186             : 
     187        2623 : void FragmentHandler2::initializeImport()
     188             : {
     189        2623 : }
     190             : 
     191        1752 : void FragmentHandler2::finalizeImport()
     192             : {
     193        1752 : }
     194             : 
     195             : } // namespace core
     196         246 : } // namespace oox
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11