LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/oox/source/core - fragmenthandler2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 75 72.0 %
Date: 2013-07-09 Functions: 16 24 66.7 %
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             : // ============================================================================
      27             : 
      28             : using namespace ::com::sun::star::uno;
      29             : using namespace ::com::sun::star::xml::sax;
      30             : 
      31             : 
      32             : 
      33             : using ::com::sun::star::uno::Sequence;
      34             : 
      35             : // ============================================================================
      36             : 
      37         223 : FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
      38             :     FragmentHandler( rFilter, rFragmentPath ),
      39         223 :     ContextHandler2Helper( bEnableTrimSpace )
      40             : {
      41         223 : }
      42             : 
      43         391 : FragmentHandler2::~FragmentHandler2()
      44             : {
      45         391 : }
      46             : 
      47             : // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
      48             : 
      49         160 : void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException )
      50             : {
      51         160 :     initializeImport();
      52         160 : }
      53             : 
      54         158 : void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException )
      55             : {
      56         158 :     finalizeImport();
      57         158 : }
      58             : 
      59          14 : bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
      60             : {
      61          14 :     switch( nElement )
      62             :     {
      63             :         case MCE_TOKEN( AlternateContent ):
      64           6 :             aMceState.push_back( MCE_STARTED );
      65           6 :             break;
      66             : 
      67             :         case MCE_TOKEN( Choice ):
      68             :             {
      69           6 :                 OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString("none") );
      70           6 :                 aRequires = getFilter().getNamespaceURL( aRequires );
      71           6 :                 if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
      72           3 :                     aMceState.back() = MCE_FOUND_CHOICE;
      73             :                 else
      74           3 :                     return false;
      75             :             }
      76           3 :             break;
      77             : 
      78             :         case MCE_TOKEN( Fallback ):
      79           2 :             if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
      80           1 :                 break;
      81           1 :             return false;
      82             :         default:
      83             :             {
      84           0 :                 OUString str = rAttribs.getString( MCE_TOKEN( Ignorable ), OUString() );
      85           0 :                 if( !str.isEmpty() )
      86             :                 {
      87           0 :                     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          10 :     return true;
      96             : }
      97             : 
      98             : 
      99             : 
     100             : // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
     101             : 
     102        3523 : Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
     103             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
     104             : {
     105        3523 :     if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
     106             :     {
     107          14 :         if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
     108          10 :             return getFastContextHandler();
     109           4 :         return NULL;
     110             :     }
     111        3509 :     return implCreateChildContext( nElement, rxAttribs );
     112             : }
     113             : 
     114        1384 : void SAL_CALL FragmentHandler2::startFastElement(
     115             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
     116             : {
     117        1384 :     implStartElement( nElement, rxAttribs );
     118        1384 : }
     119             : 
     120         507 : void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException )
     121             : {
     122         507 :     implCharacters( rChars );
     123         507 : }
     124             : 
     125        1384 : void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
     126             : {
     127             :     /* If MCE */
     128        1384 :     switch( nElement )
     129             :     {
     130             :         case MCE_TOKEN( AlternateContent ):
     131           6 :             aMceState.pop_back();
     132           6 :             break;
     133             :     }
     134             : 
     135        1384 :     implEndElement( nElement );
     136        1384 : }
     137             : 
     138             : // oox.core.ContextHandler interface ------------------------------------------
     139             : 
     140           0 : ContextHandlerRef FragmentHandler2::createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     141             : {
     142           0 :     return implCreateRecordContext( nRecId, rStrm );
     143             : }
     144             : 
     145           0 : void FragmentHandler2::startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm )
     146             : {
     147           0 :     implStartRecord( nRecId, rStrm );
     148           0 : }
     149             : 
     150           0 : void FragmentHandler2::endRecord( sal_Int32 nRecId )
     151             : {
     152           0 :     implEndRecord( nRecId );
     153           0 : }
     154             : 
     155             : // oox.core.ContextHandler2Helper interface -----------------------------------
     156             : 
     157           0 : ContextHandlerRef FragmentHandler2::onCreateContext( sal_Int32, const AttributeList& )
     158             : {
     159           0 :     return 0;
     160             : }
     161             : 
     162        1384 : void FragmentHandler2::onStartElement( const AttributeList& )
     163             : {
     164        1384 : }
     165             : 
     166          64 : void FragmentHandler2::onCharacters( const OUString& )
     167             : {
     168          64 : }
     169             : 
     170        1274 : void FragmentHandler2::onEndElement()
     171             : {
     172        1274 : }
     173             : 
     174           0 : ContextHandlerRef FragmentHandler2::onCreateRecordContext( sal_Int32, SequenceInputStream& )
     175             : {
     176           0 :     return 0;
     177             : }
     178             : 
     179           0 : void FragmentHandler2::onStartRecord( SequenceInputStream& )
     180             : {
     181           0 : }
     182             : 
     183           0 : void FragmentHandler2::onEndRecord()
     184             : {
     185           0 : }
     186             : 
     187             : // oox.core.FragmentHandler2 interface ----------------------------------------
     188             : 
     189         117 : void FragmentHandler2::initializeImport()
     190             : {
     191         117 : }
     192             : 
     193          23 : void FragmentHandler2::finalizeImport()
     194             : {
     195          23 : }
     196             : 
     197             : // ============================================================================
     198             : 
     199             : } // namespace core
     200         141 : } // namespace oox
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10