LCOV - code coverage report
Current view: top level - xmloff/source/transform - MergeElemTContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 129 0.0 %
Date: 2014-11-03 Functions: 0 34 0.0 %
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 "MergeElemTContext.hxx"
      21             : #include "MutableAttrList.hxx"
      22             : #include "TransformerBase.hxx"
      23             : #include "TransformerActions.hxx"
      24             : #include "AttrTransformerAction.hxx"
      25             : #include "ElemTransformerAction.hxx"
      26             : #include "IgnoreTContext.hxx"
      27             : #include <xmloff/xmlnmspe.hxx>
      28             : 
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star::xml::sax;
      31             : using namespace ::xmloff::token;
      32             : 
      33             : class XMLParagraphTransformerContext : public XMLTransformerContext
      34             : {
      35             : public:
      36             :     TYPEINFO_OVERRIDE();
      37             : 
      38             :     XMLParagraphTransformerContext( XMLTransformerBase& rTransformer,
      39             :                            const OUString& rQName );
      40             : 
      41             :     virtual ~XMLParagraphTransformerContext();
      42             : 
      43             :     // Create a children element context. By default, the import's
      44             :     // CreateContext method is called to create a new default context.
      45             :     virtual XMLTransformerContext *CreateChildContext( sal_uInt16 nPrefix,
      46             :                                    const OUString& rLocalName,
      47             :                                    const OUString& rQName,
      48             :                                    const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
      49             : 
      50             :     // StartElement is called after a context has been constructed and
      51             :     // before a elements context is parsed. It may be used for actions that
      52             :     // require virtual methods. The default is to do nothing.
      53             :     virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
      54             : 
      55             :     // EndElement is called before a context will be destructed, but
      56             :     // after a elements context has been parsed. It may be used for actions
      57             :     // that require virtual methods. The default is to do nothing.
      58             :     virtual void EndElement() SAL_OVERRIDE;
      59             : 
      60             :     // This method is called for all characters that are contained in the
      61             :     // current element. The default is to ignore them.
      62             :     virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
      63             : };
      64             : 
      65           0 : TYPEINIT1( XMLParagraphTransformerContext, XMLTransformerContext );
      66             : 
      67           0 : XMLParagraphTransformerContext::XMLParagraphTransformerContext(
      68             :         XMLTransformerBase& rImp,
      69             :         const OUString& rQName ) :
      70           0 :     XMLTransformerContext( rImp, rQName )
      71             : {
      72           0 : }
      73             : 
      74           0 : XMLParagraphTransformerContext::~XMLParagraphTransformerContext()
      75             : {
      76           0 : }
      77             : 
      78           0 : XMLTransformerContext *XMLParagraphTransformerContext::CreateChildContext(
      79             :         sal_uInt16 /*nPrefix*/,
      80             :         const OUString& /*rLocalName*/,
      81             :         const OUString& rQName,
      82             :         const Reference< XAttributeList >& )
      83             : {
      84           0 :     XMLTransformerContext *pContext = 0;
      85             : 
      86           0 :     pContext = new XMLIgnoreTransformerContext( GetTransformer(),
      87           0 :                                                 rQName, true );
      88             : 
      89           0 :     return pContext;
      90             : }
      91             : 
      92           0 : void XMLParagraphTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
      93             : {
      94           0 :     XMLTransformerContext::StartElement( rAttrList );
      95           0 : }
      96             : 
      97           0 : void XMLParagraphTransformerContext::EndElement()
      98             : {
      99           0 :     XMLTransformerContext::EndElement();
     100           0 : }
     101             : 
     102           0 : void XMLParagraphTransformerContext::Characters( const OUString& rChars )
     103             : {
     104           0 :     XMLTransformerContext::Characters( rChars );
     105           0 : }
     106             : 
     107             : class XMLPersTextContentRNGTransformTContext : public XMLPersTextContentTContext
     108             : {
     109             : public:
     110             :     TYPEINFO_OVERRIDE();
     111             : 
     112             :     XMLPersTextContentRNGTransformTContext(
     113             :         XMLTransformerBase& rTransformer,
     114             :         const OUString& rQName,
     115             :         sal_uInt16 nPrefix,
     116             :         ::xmloff::token::XMLTokenEnum eToken );
     117             :     virtual ~XMLPersTextContentRNGTransformTContext();
     118             : 
     119             :     virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
     120             : };
     121             : 
     122           0 : TYPEINIT1( XMLPersTextContentRNGTransformTContext, XMLPersAttrListTContext );
     123             : 
     124           0 : XMLPersTextContentRNGTransformTContext::XMLPersTextContentRNGTransformTContext(
     125             :     XMLTransformerBase& rTransformer,
     126             :     const OUString& rQName,
     127             :     sal_uInt16 nPrefix,
     128             :     ::xmloff::token::XMLTokenEnum eToken ) :
     129             :         XMLPersTextContentTContext(
     130           0 :             rTransformer, rQName, nPrefix, eToken )
     131           0 : {}
     132             : 
     133           0 : XMLPersTextContentRNGTransformTContext::~XMLPersTextContentRNGTransformTContext()
     134           0 : {}
     135             : 
     136           0 : void XMLPersTextContentRNGTransformTContext::Characters( const OUString& rChars )
     137             : {
     138           0 :     OUString aConvChars( rChars );
     139           0 :     XMLTransformerBase::ConvertRNGDateTimeToISO( aConvChars );
     140           0 :     XMLPersTextContentTContext::Characters( aConvChars );
     141           0 : }
     142             : 
     143             : 
     144           0 : TYPEINIT1( XMLMergeElemTransformerContext, XMLTransformerContext );
     145             : 
     146           0 : void XMLMergeElemTransformerContext::ExportStartElement()
     147             : {
     148           0 :     XMLPersTextContentTContextVector::iterator aIter = m_aChildContexts.begin();
     149             : 
     150           0 :     for( ; aIter != m_aChildContexts.end(); ++aIter )
     151             :     {
     152           0 :         XMLPersTextContentTContext *pContext = (*aIter).get();
     153           0 :         static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
     154           0 :             ->AddAttribute( pContext->GetExportQName(),
     155           0 :                             pContext->GetTextContent() );
     156             :     }
     157           0 :     XMLTransformerContext::StartElement( m_xAttrList );
     158             : 
     159           0 :     m_bStartElementExported = true;
     160           0 : }
     161             : 
     162           0 : XMLMergeElemTransformerContext::XMLMergeElemTransformerContext(
     163             :         XMLTransformerBase& rImp,
     164             :         const OUString& rQName,
     165             :        sal_uInt16 nActionMap ) :
     166             :     XMLTransformerContext( rImp, rQName ),
     167             :     m_nActionMap( nActionMap ),
     168           0 :     m_bStartElementExported( false )
     169             : {
     170           0 : }
     171             : 
     172           0 : XMLMergeElemTransformerContext::~XMLMergeElemTransformerContext()
     173             : {
     174           0 : }
     175             : 
     176           0 : void XMLMergeElemTransformerContext::StartElement(
     177             :     const Reference< XAttributeList >& rAttrList )
     178             : {
     179             :     XMLMutableAttributeList *pMutableAttrList =
     180           0 :         new XMLMutableAttributeList( rAttrList, true );
     181           0 :     m_xAttrList = pMutableAttrList;
     182             : 
     183           0 :     sal_Int16 nAttrCount = m_xAttrList.is() ? m_xAttrList->getLength() : 0;
     184           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     185             :     {
     186           0 :         const OUString& rAttrName = m_xAttrList->getNameByIndex( i );
     187           0 :         OUString aLocalName;
     188             :         sal_uInt16 nPrefix =
     189           0 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     190           0 :                                                                 &aLocalName );
     191           0 :         bool bRemove = true;
     192           0 :         if( XML_NAMESPACE_OFFICE == nPrefix)
     193             :         {
     194           0 :             if (IsXMLToken( aLocalName, XML_DISPLAY ) )
     195           0 :                 bRemove = false;
     196           0 :             else if (IsXMLToken( aLocalName, XML_AUTHOR ) )
     197           0 :                 bRemove = false;
     198           0 :             else if (IsXMLToken( aLocalName, XML_CREATE_DATE ) )
     199           0 :                 bRemove = false;
     200           0 :             else if (IsXMLToken( aLocalName, XML_CREATE_DATE_STRING ) )
     201           0 :                 bRemove = false;
     202             :         }
     203           0 :         if (bRemove)
     204             :         {
     205           0 :             pMutableAttrList->RemoveAttributeByIndex( i );
     206           0 :             --i;
     207           0 :             --nAttrCount;
     208             :         }
     209           0 :     }
     210           0 : }
     211             : 
     212           0 : XMLTransformerContext *XMLMergeElemTransformerContext::CreateChildContext(
     213             :         sal_uInt16 nPrefix,
     214             :         const OUString& rLocalName,
     215             :         const OUString& rQName,
     216             :         const Reference< XAttributeList >& rAttrList )
     217             : {
     218           0 :     XMLTransformerContext *pContext = 0;
     219             : 
     220           0 :     if( !m_bStartElementExported )
     221             :     {
     222             :         XMLTransformerActions *pActions =
     223           0 :             GetTransformer().GetUserDefinedActions( m_nActionMap );
     224             :         OSL_ENSURE( pActions, "go no actions" );
     225           0 :         if( pActions )
     226             :         {
     227           0 :             XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
     228             :             XMLTransformerActions::const_iterator aIter =
     229           0 :                 pActions->find( aKey );
     230             : 
     231           0 :             if( !(aIter == pActions->end()) )
     232             :             {
     233           0 :                 switch( (*aIter).second.m_nActionType )
     234             :                 {
     235             :                 case XML_ATACTION_MOVE_FROM_ELEM_RNG2ISO_DATETIME:
     236             :                     {
     237             :                         XMLPersTextContentTContext *pTC =
     238             :                             new XMLPersTextContentRNGTransformTContext(
     239           0 :                                     GetTransformer(), rQName,
     240           0 :                                     (*aIter).second.GetQNamePrefixFromParam1(),
     241           0 :                                     (*aIter).second.GetQNameTokenFromParam1() );
     242           0 :                         XMLPersTextContentTContextVector::value_type aVal(pTC);
     243           0 :                         m_aChildContexts.push_back( aVal );
     244           0 :                         pContext = pTC;
     245             :                     }
     246           0 :                     break;
     247             :                 case XML_ATACTION_MOVE_FROM_ELEM:
     248             :                     {
     249             :                         XMLPersTextContentTContext *pTC =
     250             :                             new XMLPersTextContentTContext(
     251           0 :                                     GetTransformer(), rQName,
     252           0 :                                     (*aIter).second.GetQNamePrefixFromParam1(),
     253           0 :                                     (*aIter).second.GetQNameTokenFromParam1() );
     254           0 :                         XMLPersTextContentTContextVector::value_type aVal(pTC);
     255           0 :                         m_aChildContexts.push_back( aVal );
     256           0 :                         pContext = pTC;
     257             :                     }
     258           0 :                     break;
     259             :                 case XML_ETACTION_EXTRACT_CHARACTERS:
     260             :                     {
     261           0 :                         if( !m_bStartElementExported )
     262           0 :                             ExportStartElement();
     263             :                         XMLParagraphTransformerContext* pPTC =
     264           0 :                             new XMLParagraphTransformerContext( GetTransformer(),
     265           0 :                             rQName);
     266           0 :                         pContext = pPTC;
     267             :                     }
     268           0 :                     break;
     269             :                 default:
     270             :                     OSL_ENSURE( false, "unknown action" );
     271           0 :                     break;
     272             :                 }
     273           0 :             }
     274             :         }
     275             :     }
     276             :     else
     277             :     {
     278             :         XMLTransformerActions *pActions =
     279           0 :             GetTransformer().GetUserDefinedActions( m_nActionMap );
     280             :         OSL_ENSURE( pActions, "go no actions" );
     281           0 :         if( pActions )
     282             :         {
     283           0 :             XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
     284             :             XMLTransformerActions::const_iterator aIter =
     285           0 :                 pActions->find( aKey );
     286             : 
     287           0 :             if( !(aIter == pActions->end()) )
     288             :             {
     289           0 :                 switch( (*aIter).second.m_nActionType )
     290             :                 {
     291             :                 case XML_ETACTION_EXTRACT_CHARACTERS:
     292             :                     {
     293           0 :                         if( !m_bStartElementExported )
     294           0 :                             ExportStartElement();
     295             :                         XMLParagraphTransformerContext* pPTC =
     296           0 :                             new XMLParagraphTransformerContext( GetTransformer(),
     297           0 :                             rQName);
     298           0 :                         pContext = pPTC;
     299             :                     }
     300           0 :                     break;
     301             :                 default:
     302             :                     OSL_ENSURE( false, "unknown action" );
     303           0 :                     break;
     304             :                 }
     305           0 :             }
     306             :         }
     307             :     }
     308             : 
     309             :     // default is copying
     310           0 :     if( !pContext )
     311             :     {
     312           0 :         if( !m_bStartElementExported )
     313           0 :             ExportStartElement();
     314             :         pContext = XMLTransformerContext::CreateChildContext( nPrefix,
     315             :                                                               rLocalName,
     316             :                                                               rQName,
     317           0 :                                                               rAttrList );
     318             :     }
     319             : 
     320           0 :     return pContext;
     321             : }
     322             : 
     323           0 : void XMLMergeElemTransformerContext::EndElement()
     324             : {
     325           0 :     if( !m_bStartElementExported )
     326           0 :         ExportStartElement();
     327           0 :     XMLTransformerContext::EndElement();
     328           0 : }
     329             : 
     330           0 : void XMLMergeElemTransformerContext::Characters( const OUString& )
     331             : {
     332             :     // ignore
     333           0 : }
     334             : 
     335             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10