LCOV - code coverage report
Current view: top level - libreoffice/oox/source/core - fragmenthandler2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 75 72.0 %
Date: 2012-12-17 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             : using ::rtl::OUString;
      32             : 
      33             : 
      34             : using ::com::sun::star::uno::Sequence;
      35             : 
      36             : // ============================================================================
      37             : 
      38         216 : FragmentHandler2::FragmentHandler2( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEnableTrimSpace ) :
      39             :     FragmentHandler( rFilter, rFragmentPath ),
      40         216 :     ContextHandler2Helper( bEnableTrimSpace )
      41             : {
      42         216 : }
      43             : 
      44         260 : FragmentHandler2::~FragmentHandler2()
      45             : {
      46         260 : }
      47             : 
      48             : // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
      49             : 
      50         176 : void SAL_CALL FragmentHandler2::startDocument() throw( SAXException, RuntimeException )
      51             : {
      52         176 :     initializeImport();
      53         176 : }
      54             : 
      55         176 : void SAL_CALL FragmentHandler2::endDocument() throw( SAXException, RuntimeException )
      56             : {
      57         176 :     finalizeImport();
      58         176 : }
      59             : 
      60          28 : bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs )
      61             : {
      62          28 :     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("none") );
      71          12 :                 aRequires = getFilter().getNamespaceURL( aRequires );
      72          12 :                 if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
      73           6 :                     aMceState.back() = MCE_FOUND_CHOICE;
      74             :                 else
      75           6 :                     return false;
      76             :             }
      77           6 :             break;
      78             : 
      79             :         case MCE_TOKEN( Fallback ):
      80           4 :             if( !aMceState.empty() && aMceState.back() == MCE_STARTED )
      81           2 :                 break;
      82           2 :             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          20 :     return true;
      97             : }
      98             : 
      99             : 
     100             : 
     101             : // com.sun.star.xml.sax.XFastContextHandler interface -------------------------
     102             : 
     103        3404 : Reference< XFastContextHandler > SAL_CALL FragmentHandler2::createFastChildContext(
     104             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
     105             : {
     106        3404 :     if( getNamespace( nElement ) == NMSP_mce ) // TODO for checking 'Ignorable'
     107             :     {
     108          28 :         if( prepareMceContext( nElement, AttributeList( rxAttribs ) ) )
     109          20 :             return getFastContextHandler();
     110           8 :         return NULL;
     111             :     }
     112        3376 :     return implCreateChildContext( nElement, rxAttribs );
     113             : }
     114             : 
     115        1202 : void SAL_CALL FragmentHandler2::startFastElement(
     116             :         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw( SAXException, RuntimeException )
     117             : {
     118        1202 :     implStartElement( nElement, rxAttribs );
     119        1202 : }
     120             : 
     121         630 : void SAL_CALL FragmentHandler2::characters( const OUString& rChars ) throw( SAXException, RuntimeException )
     122             : {
     123         630 :     implCharacters( rChars );
     124         630 : }
     125             : 
     126        1202 : void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement ) throw( SAXException, RuntimeException )
     127             : {
     128             :     /* If MCE */
     129        1202 :     switch( nElement )
     130             :     {
     131             :         case MCE_TOKEN( AlternateContent ):
     132          12 :             aMceState.pop_back();
     133          12 :             break;
     134             :     }
     135             : 
     136        1202 :     implEndElement( nElement );
     137        1202 : }
     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        1202 : void FragmentHandler2::onStartElement( const AttributeList& )
     164             : {
     165        1202 : }
     166             : 
     167          72 : void FragmentHandler2::onCharacters( const OUString& )
     168             : {
     169          72 : }
     170             : 
     171        1148 : void FragmentHandler2::onEndElement()
     172             : {
     173        1148 : }
     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         126 : void FragmentHandler2::initializeImport()
     191             : {
     192         126 : }
     193             : 
     194          24 : void FragmentHandler2::finalizeImport()
     195             : {
     196          24 : }
     197             : 
     198             : // ============================================================================
     199             : 
     200             : } // namespace core
     201         174 : } // namespace oox
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10