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

Generated by: LCOV version 1.11