LCOV - code coverage report
Current view: top level - sw/source/core/swg - SwXMLBlockImport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 108 121 89.3 %
Date: 2015-06-13 12:38:46 Functions: 40 44 90.9 %
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 <SwXMLBlockImport.hxx>
      21             : #include <SwXMLTextBlocks.hxx>
      22             : #include <xmloff/xmlictxt.hxx>
      23             : #include <unotools/charclass.hxx>
      24             : #include <swtypes.hxx>
      25             : 
      26             : #if defined __clang__
      27             : #if __has_warning("-Wdeprecated-register")
      28             : #pragma GCC diagnostic push
      29             : #pragma GCC diagnostic ignored "-Wdeprecated-register"
      30             : #endif
      31             : #endif
      32             : #include <tokens.cxx>
      33             : #if defined __clang__
      34             : #if __has_warning("-Wdeprecated-register")
      35             : #pragma GCC diagnostic pop
      36             : #endif
      37             : #endif
      38             : 
      39             : using namespace ::com::sun::star::uno;
      40             : using namespace ::com::sun::star;
      41             : using namespace css::xml::sax;
      42             : 
      43             : class SwXMLBlockListImport;
      44             : class SwXMLTextBlockImport;
      45             : 
      46             : class SwXMLBlockListContext : public SvXMLImportContext
      47             : {
      48             : private:
      49             :     SwXMLBlockListImport & rLocalRef;
      50             : 
      51             : public:
      52             :     SwXMLBlockListContext( SwXMLBlockListImport& rImport, sal_Int32 Element,
      53             :         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
      54             :     virtual ~SwXMLBlockListContext();
      55             : 
      56             :     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
      57             :         sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
      58             :         throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
      59             : };
      60             : 
      61             : class SwXMLBlockContext : public SvXMLImportContext
      62             : {
      63             : public:
      64             :     SwXMLBlockContext( SwXMLBlockListImport& rImport, sal_Int32 Element,
      65             :         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
      66             :     virtual ~SwXMLBlockContext();
      67             : };
      68             : 
      69             : class SwXMLTextBlockDocumentContext : public SvXMLImportContext
      70             : {
      71             : private:
      72             :     SwXMLTextBlockImport & rLocalRef;
      73             : 
      74             : public:
      75             :     SwXMLTextBlockDocumentContext( SwXMLTextBlockImport& rImport, sal_Int32 Element,
      76             :         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
      77             : 
      78             :     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
      79             :         sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
      80             :         throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
      81             : 
      82             :     virtual ~SwXMLTextBlockDocumentContext();
      83             : };
      84             : 
      85             : class SwXMLTextBlockBodyContext : public SvXMLImportContext
      86             : {
      87             : private:
      88             :     SwXMLTextBlockImport & rLocalRef;
      89             : 
      90             : public:
      91             :     SwXMLTextBlockBodyContext( SwXMLTextBlockImport& rImport, sal_Int32 Element,
      92             :         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
      93             : 
      94             :     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
      95             :         sal_Int32, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
      96             :         throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
      97             : 
      98             :     virtual ~SwXMLTextBlockBodyContext();
      99             : };
     100             : 
     101             : class SwXMLTextBlockTextContext : public SvXMLImportContext
     102             : {
     103             : private:
     104             :     SwXMLTextBlockImport & rLocalRef;
     105             : 
     106             : public:
     107             :     SwXMLTextBlockTextContext( SwXMLTextBlockImport& rImport, sal_Int32 Element,
     108             :                 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
     109             : 
     110             :     virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
     111             :         sal_Int32 Element,
     112             :         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
     113             :         throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
     114             : 
     115             :     virtual ~SwXMLTextBlockTextContext();
     116             : };
     117             : 
     118             : class SwXMLTextBlockParContext : public SvXMLImportContext
     119             : {
     120             : private:
     121             :     SwXMLTextBlockImport & rLocalRef;
     122             : 
     123             : public:
     124             :     SwXMLTextBlockParContext( SwXMLTextBlockImport & rImport, sal_Int32 Element,
     125             :             const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
     126             : 
     127             :     virtual void SAL_CALL characters( const OUString & aChars )
     128             :         throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
     129             : 
     130             :     virtual ~SwXMLTextBlockParContext();
     131             : };
     132             : 
     133           6 : SwXMLTextBlockTokenHandler::SwXMLTextBlockTokenHandler()
     134             : {
     135           6 : }
     136             : 
     137          12 : SwXMLTextBlockTokenHandler::~SwXMLTextBlockTokenHandler()
     138             : {
     139          12 : }
     140             : 
     141           0 : sal_Int32 SAL_CALL SwXMLTextBlockTokenHandler::getTokenFromUTF8( const Sequence< sal_Int8 >& Identifier )
     142             :     throw (css::uno::RuntimeException, std::exception)
     143             : {
     144           0 :     return getTokenDirect( reinterpret_cast< const char* >( Identifier.getConstArray() ), Identifier.getLength() );
     145             : }
     146             : 
     147           0 : Sequence< sal_Int8 > SAL_CALL SwXMLTextBlockTokenHandler::getUTF8Identifier( sal_Int32 )
     148             :     throw (css::uno::RuntimeException, std::exception)
     149             : {
     150           0 :     return Sequence< sal_Int8 >();
     151             : }
     152             : 
     153          76 : sal_Int32 SwXMLTextBlockTokenHandler::getTokenDirect( const char *pTag, sal_Int32 nLength ) const
     154             : {
     155          76 :     if( !nLength )
     156           0 :         nLength = strlen( pTag );
     157          76 :     const struct xmltoken* pToken = TextBlockTokens::in_word_set( pTag, nLength );
     158          76 :     return pToken ? pToken->nToken : XML_TOKEN_INVALID;
     159             : }
     160             : 
     161          60 : SwXMLBlockListTokenHandler::SwXMLBlockListTokenHandler()
     162             : {
     163          60 : }
     164             : 
     165         120 : SwXMLBlockListTokenHandler::~SwXMLBlockListTokenHandler()
     166             : {
     167         120 : }
     168             : 
     169           0 : sal_Int32 SAL_CALL SwXMLBlockListTokenHandler::getTokenFromUTF8( const Sequence< sal_Int8 >& Identifier )
     170             :     throw (css::uno::RuntimeException, std::exception)
     171             : {
     172           0 :     return getTokenDirect( reinterpret_cast< const char* >( Identifier.getConstArray() ), Identifier.getLength() );
     173             : }
     174             : 
     175           0 : Sequence< sal_Int8 > SAL_CALL SwXMLBlockListTokenHandler::getUTF8Identifier( sal_Int32 )
     176             :     throw (css::uno::RuntimeException, std::exception)
     177             : {
     178           0 :     return Sequence< sal_Int8 >();
     179             : }
     180             : 
     181         320 : sal_Int32 SwXMLBlockListTokenHandler::getTokenDirect( const char *pTag, sal_Int32 nLength ) const
     182             : {
     183         320 :     if( !nLength )
     184           0 :         nLength = strlen( pTag );
     185         320 :     const struct xmltoken* pToken = BlockListTokens::in_word_set( pTag, nLength );
     186         320 :     return pToken ? pToken->nToken : XML_TOKEN_INVALID;
     187             : }
     188             : 
     189          60 : SwXMLBlockListContext::SwXMLBlockListContext(
     190             :     SwXMLBlockListImport& rImport,
     191             :     sal_Int32 /*Element*/,
     192             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) :
     193             :     SvXMLImportContext( rImport ),
     194          60 :     rLocalRef( rImport )
     195             : {
     196          60 :     if( xAttrList.is() && xAttrList->hasAttribute( SwXMLBlockListToken::LIST_NAME ) )
     197          60 :         rImport.getBlockList().SetName( xAttrList->getValue( SwXMLBlockListToken::LIST_NAME ) );
     198          60 : }
     199             : 
     200         120 : SwXMLBlockListContext::~SwXMLBlockListContext()
     201             : {
     202         120 : }
     203             : 
     204             : uno::Reference< ::xml::sax::XFastContextHandler > SAL_CALL
     205          40 : SwXMLBlockListContext::createFastChildContext( sal_Int32 Element,
     206             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
     207             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     208             : {
     209          40 :     if ( Element == SwXMLBlockListToken::BLOCK )
     210          40 :         return new SwXMLBlockContext( rLocalRef, Element, xAttrList );
     211             :     else
     212           0 :         return new SvXMLImportContext( rLocalRef );
     213             : }
     214             : 
     215          40 : SwXMLBlockContext::SwXMLBlockContext(
     216             :     SwXMLBlockListImport& rImport,
     217             :     sal_Int32 /*Element*/,
     218             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) :
     219          40 :     SvXMLImportContext( rImport )
     220             : {
     221          40 :     static const CharClass & rCC = GetAppCharClass();
     222          80 :     OUString aShort, aLong, aPackageName;
     223          40 :     bool bTextOnly = false;
     224          40 :     if( xAttrList.is() )
     225             :     {
     226          40 :         if( xAttrList->hasAttribute( SwXMLBlockListToken::ABBREVIATED_NAME ) )
     227          40 :             aShort = rCC.uppercase( xAttrList->getValue( SwXMLBlockListToken::ABBREVIATED_NAME ) );
     228          40 :         if( xAttrList->hasAttribute( SwXMLBlockListToken::NAME ) )
     229          40 :             aLong = xAttrList->getValue( SwXMLBlockListToken::NAME );
     230          40 :         if( xAttrList->hasAttribute( SwXMLBlockListToken::PACKAGE_NAME ) )
     231          40 :             aPackageName = xAttrList->getValue( SwXMLBlockListToken::PACKAGE_NAME );
     232          40 :         if( xAttrList->hasAttribute( SwXMLBlockListToken::UNFORMATTED_TEXT ) )
     233             :         {
     234          40 :             OUString rAttrValue( xAttrList->getValue( SwXMLBlockListToken::UNFORMATTED_TEXT ) );
     235          40 :             if( IsXMLToken( rAttrValue, XML_TRUE ) )
     236          34 :                 bTextOnly = true;
     237             :         }
     238             :     }
     239          40 :     if (aShort.isEmpty() || aLong.isEmpty() || aPackageName.isEmpty())
     240          40 :         return;
     241          80 :     rImport.getBlockList().AddName( aShort, aLong, aPackageName, bTextOnly);
     242             : }
     243             : 
     244          80 : SwXMLBlockContext::~SwXMLBlockContext()
     245             : {
     246          80 : }
     247             : 
     248           6 : SwXMLTextBlockDocumentContext::SwXMLTextBlockDocumentContext(
     249             :     SwXMLTextBlockImport& rImport,
     250             :     sal_Int32 /*Element*/,
     251             :     const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) :
     252             :     SvXMLImportContext( rImport ),
     253           6 :     rLocalRef(rImport)
     254             : {
     255           6 : }
     256             : 
     257             : uno::Reference< ::xml::sax::XFastContextHandler > SAL_CALL
     258          12 : SwXMLTextBlockDocumentContext::createFastChildContext( sal_Int32 Element,
     259             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
     260             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     261             : {
     262          12 :     if ( Element == SwXMLTextBlockToken::OFFICE_BODY )
     263           6 :         return new SwXMLTextBlockBodyContext( rLocalRef, Element, xAttrList );
     264             :     else
     265           6 :         return new SvXMLImportContext( rLocalRef );
     266             : }
     267             : 
     268          12 : SwXMLTextBlockDocumentContext::~SwXMLTextBlockDocumentContext()
     269             : {
     270          12 : }
     271             : 
     272           2 : SwXMLTextBlockTextContext::SwXMLTextBlockTextContext(
     273             :     SwXMLTextBlockImport& rImport,
     274             :     sal_Int32 /*Element*/,
     275             :     const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList */) :
     276             :     SvXMLImportContext ( rImport ),
     277           2 :     rLocalRef( rImport )
     278             : {
     279           2 : }
     280             : 
     281             : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
     282          10 : SwXMLTextBlockTextContext::createFastChildContext( sal_Int32 Element,
     283             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
     284             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     285             : {
     286          10 :     if ( Element == SwXMLTextBlockToken::TEXT_P )
     287           8 :         return new SwXMLTextBlockParContext( rLocalRef, Element, xAttrList );
     288             :     else
     289           2 :         return new SvXMLImportContext( rLocalRef );
     290             : }
     291             : 
     292           4 : SwXMLTextBlockTextContext::~SwXMLTextBlockTextContext()
     293             : {
     294           4 : }
     295             : 
     296           6 : SwXMLTextBlockBodyContext::SwXMLTextBlockBodyContext(
     297             :     SwXMLTextBlockImport& rImport,
     298             :     sal_Int32 /*Element*/,
     299             :     const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) :
     300             :     SvXMLImportContext( rImport ),
     301           6 :     rLocalRef(rImport)
     302             : {
     303           6 : }
     304             : 
     305             : uno::Reference < xml::sax::XFastContextHandler > SAL_CALL
     306           8 : SwXMLTextBlockBodyContext::createFastChildContext( sal_Int32 Element,
     307             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
     308             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     309             : {
     310           8 :     if( Element == SwXMLTextBlockToken::OFFICE_TEXT )
     311           2 :         return new SwXMLTextBlockTextContext( rLocalRef, Element, xAttrList );
     312           6 :     else if( Element == SwXMLTextBlockToken::TEXT_P )
     313           6 :         return new SwXMLTextBlockParContext( rLocalRef, Element, xAttrList );
     314             :     else
     315           0 :         return new SvXMLImportContext( rLocalRef );
     316             : }
     317             : 
     318          12 : SwXMLTextBlockBodyContext::~SwXMLTextBlockBodyContext()
     319             : {
     320          12 : }
     321             : 
     322          14 : SwXMLTextBlockParContext::SwXMLTextBlockParContext(
     323             :     SwXMLTextBlockImport& rImport,
     324             :     sal_Int32 /*Element*/,
     325             :     const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) :
     326             :     SvXMLImportContext( rImport ),
     327          14 :     rLocalRef( rImport )
     328             : {
     329          14 : }
     330             : 
     331           7 : void SAL_CALL SwXMLTextBlockParContext::characters( const OUString & aChars )
     332             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     333             : {
     334           7 :     rLocalRef.m_rText += aChars;
     335           7 : }
     336             : 
     337          42 : SwXMLTextBlockParContext::~SwXMLTextBlockParContext()
     338             : {
     339          14 :     if (rLocalRef.bTextOnly)
     340           6 :         rLocalRef.m_rText += "\015";
     341             :     else
     342             :     {
     343           8 :         if (!rLocalRef.m_rText.endsWith( " " ))
     344           2 :             rLocalRef.m_rText += " ";
     345             :     }
     346          28 : }
     347             : 
     348             : // SwXMLBlockListImport //////////////////////////////
     349          60 : SwXMLBlockListImport::SwXMLBlockListImport(
     350             :     const uno::Reference< uno::XComponentContext >& rContext,
     351             :     SwXMLTextBlocks &rBlocks )
     352             : :   SvXMLImport( rContext, "", SvXMLImportFlags::NONE ),
     353          60 :     rBlockList (rBlocks)
     354             : {
     355          60 : }
     356             : 
     357         120 : SwXMLBlockListImport::~SwXMLBlockListImport()
     358          60 :     throw ()
     359             : {
     360         120 : }
     361             : 
     362          60 : SvXMLImportContext* SwXMLBlockListImport::CreateFastContext( sal_Int32 Element,
     363             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
     364             : {
     365          60 :     if( Element == SwXMLBlockListToken::BLOCK_LIST )
     366          60 :         return new SwXMLBlockListContext( *this, Element, xAttrList );
     367             :     else
     368           0 :         return SvXMLImport::CreateFastContext( Element, xAttrList );
     369             : }
     370             : 
     371           6 : SwXMLTextBlockImport::SwXMLTextBlockImport(
     372             :     const uno::Reference< uno::XComponentContext >& rContext,
     373             :     SwXMLTextBlocks &rBlocks,
     374             :     OUString & rNewText,
     375             :     bool bNewTextOnly )
     376             : :   SvXMLImport(rContext, "", SvXMLImportFlags::ALL ),
     377             :     rBlockList ( rBlocks ),
     378             :     bTextOnly ( bNewTextOnly ),
     379           6 :     m_rText ( rNewText )
     380             : {
     381           6 : }
     382             : 
     383          12 : SwXMLTextBlockImport::~SwXMLTextBlockImport()
     384           6 :     throw()
     385             : {
     386          12 : }
     387             : 
     388          14 : SvXMLImportContext* SwXMLTextBlockImport::CreateFastContext( sal_Int32 Element,
     389             :     const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
     390             : {
     391          14 :     if( Element == SwXMLTextBlockToken::OFFICE_DOCUMENT ||
     392             :         Element == SwXMLTextBlockToken::OFFICE_DOCUMENT_CONTENT )
     393           6 :         return new SwXMLTextBlockDocumentContext( *this, Element, xAttrList );
     394             :     else
     395           8 :         return SvXMLImport::CreateFastContext( Element, xAttrList );
     396             : }
     397             : 
     398           6 : void SAL_CALL SwXMLTextBlockImport::endDocument()
     399             :         throw( xml::sax::SAXException, uno::RuntimeException, std::exception )
     400             : {
     401           6 : }
     402             : 
     403             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11