LCOV - code coverage report
Current view: top level - xmloff/source/transform - MergeElemTContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 129 0.0 %
Date: 2012-08-25 Functions: 0 34 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 152 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "MergeElemTContext.hxx"
      30                 :            : #include "MutableAttrList.hxx"
      31                 :            : #include "TransformerBase.hxx"
      32                 :            : #include "TransformerActions.hxx"
      33                 :            : #include "AttrTransformerAction.hxx"
      34                 :            : #include "ElemTransformerAction.hxx"
      35                 :            : #include "IgnoreTContext.hxx"
      36                 :            : #include "xmloff/xmlnmspe.hxx"
      37                 :            : 
      38                 :            : using ::rtl::OUString;
      39                 :            : using namespace ::com::sun::star::uno;
      40                 :            : using namespace ::com::sun::star::xml::sax;
      41                 :            : using namespace ::xmloff::token;
      42                 :            : 
      43                 :            : class XMLParagraphTransformerContext : public XMLTransformerContext
      44                 :            : {
      45                 :            : public:
      46                 :            :     TYPEINFO();
      47                 :            : 
      48                 :            :     XMLParagraphTransformerContext( XMLTransformerBase& rTransformer,
      49                 :            :                            const ::rtl::OUString& rQName );
      50                 :            : 
      51                 :            :     virtual ~XMLParagraphTransformerContext();
      52                 :            : 
      53                 :            :     // Create a children element context. By default, the import's
      54                 :            :     // CreateContext method is called to create a new default context.
      55                 :            :     virtual XMLTransformerContext *CreateChildContext( sal_uInt16 nPrefix,
      56                 :            :                                    const ::rtl::OUString& rLocalName,
      57                 :            :                                    const ::rtl::OUString& rQName,
      58                 :            :                                    const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
      59                 :            : 
      60                 :            :     // StartElement is called after a context has been constructed and
      61                 :            :     // before a elements context is parsed. It may be used for actions that
      62                 :            :     // require virtual methods. The default is to do nothing.
      63                 :            :     virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
      64                 :            : 
      65                 :            :     // EndElement is called before a context will be destructed, but
      66                 :            :     // after a elements context has been parsed. It may be used for actions
      67                 :            :     // that require virtual methods. The default is to do nothing.
      68                 :            :     virtual void EndElement();
      69                 :            : 
      70                 :            :     // This method is called for all characters that are contained in the
      71                 :            :     // current element. The default is to ignore them.
      72                 :            :     virtual void Characters( const ::rtl::OUString& rChars );
      73                 :            : };
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLParagraphTransformerContext, XMLTransformerContext );
      76                 :            : 
      77                 :          0 : XMLParagraphTransformerContext::XMLParagraphTransformerContext(
      78                 :            :         XMLTransformerBase& rImp,
      79                 :            :         const OUString& rQName ) :
      80                 :          0 :     XMLTransformerContext( rImp, rQName )
      81                 :            : {
      82                 :          0 : }
      83                 :            : 
      84                 :          0 : XMLParagraphTransformerContext::~XMLParagraphTransformerContext()
      85                 :            : {
      86         [ #  # ]:          0 : }
      87                 :            : 
      88                 :          0 : XMLTransformerContext *XMLParagraphTransformerContext::CreateChildContext(
      89                 :            :         sal_uInt16 /*nPrefix*/,
      90                 :            :         const OUString& /*rLocalName*/,
      91                 :            :         const OUString& rQName,
      92                 :            :         const Reference< XAttributeList >& )
      93                 :            : {
      94                 :          0 :     XMLTransformerContext *pContext = 0;
      95                 :            : 
      96                 :          0 :     pContext = new XMLIgnoreTransformerContext( GetTransformer(),
      97         [ #  # ]:          0 :                                                 rQName, sal_True );
      98                 :            : 
      99                 :          0 :     return pContext;
     100                 :            : }
     101                 :            : 
     102                 :          0 : void XMLParagraphTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
     103                 :            : {
     104                 :          0 :     XMLTransformerContext::StartElement( rAttrList );
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : void XMLParagraphTransformerContext::EndElement()
     108                 :            : {
     109                 :          0 :     XMLTransformerContext::EndElement();
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : void XMLParagraphTransformerContext::Characters( const OUString& rChars )
     113                 :            : {
     114                 :          0 :     XMLTransformerContext::Characters( rChars );
     115                 :          0 : }
     116                 :            : 
     117                 :            : class XMLPersTextContentRNGTransformTContext : public XMLPersTextContentTContext
     118                 :            : {
     119                 :            : public:
     120                 :            :     TYPEINFO();
     121                 :            : 
     122                 :            :     XMLPersTextContentRNGTransformTContext(
     123                 :            :         XMLTransformerBase& rTransformer,
     124                 :            :         const ::rtl::OUString& rQName,
     125                 :            :         sal_uInt16 nPrefix,
     126                 :            :         ::xmloff::token::XMLTokenEnum eToken );
     127                 :            :     virtual ~XMLPersTextContentRNGTransformTContext();
     128                 :            : 
     129                 :            :     virtual void Characters( const ::rtl::OUString& rChars );
     130                 :            : };
     131                 :            : 
     132 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLPersTextContentRNGTransformTContext, XMLPersAttrListTContext );
     133                 :            : 
     134                 :          0 : XMLPersTextContentRNGTransformTContext::XMLPersTextContentRNGTransformTContext(
     135                 :            :     XMLTransformerBase& rTransformer,
     136                 :            :     const ::rtl::OUString& rQName,
     137                 :            :     sal_uInt16 nPrefix,
     138                 :            :     ::xmloff::token::XMLTokenEnum eToken ) :
     139                 :            :         XMLPersTextContentTContext(
     140                 :          0 :             rTransformer, rQName, nPrefix, eToken )
     141                 :          0 : {}
     142                 :            : 
     143                 :          0 : XMLPersTextContentRNGTransformTContext::~XMLPersTextContentRNGTransformTContext()
     144         [ #  # ]:          0 : {}
     145                 :            : 
     146                 :          0 : void XMLPersTextContentRNGTransformTContext::Characters( const ::rtl::OUString& rChars )
     147                 :            : {
     148                 :          0 :     OUString aConvChars( rChars );
     149         [ #  # ]:          0 :     GetTransformer().ConvertRNGDateTimeToISO( aConvChars );
     150         [ #  # ]:          0 :     XMLPersTextContentTContext::Characters( aConvChars );
     151                 :          0 : }
     152                 :            : 
     153                 :            : 
     154 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLMergeElemTransformerContext, XMLTransformerContext );
     155                 :            : 
     156                 :          0 : void XMLMergeElemTransformerContext::ExportStartElement()
     157                 :            : {
     158                 :          0 :     XMLPersTextContentTContextVector::iterator aIter = m_aChildContexts.begin();
     159                 :            : 
     160 [ #  # ][ #  # ]:          0 :     for( ; aIter != m_aChildContexts.end(); ++aIter )
     161                 :            :     {
     162                 :          0 :         XMLPersTextContentTContext *pContext = (*aIter).get();
     163         [ #  # ]:          0 :         static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
     164                 :          0 :             ->AddAttribute( pContext->GetExportQName(),
     165 [ #  # ][ #  # ]:          0 :                             pContext->GetTextContent() );
     166                 :            :     }
     167         [ #  # ]:          0 :     XMLTransformerContext::StartElement( m_xAttrList );
     168                 :            : 
     169                 :          0 :     m_bStartElementExported = sal_True;
     170                 :          0 : }
     171                 :            : 
     172                 :          0 : XMLMergeElemTransformerContext::XMLMergeElemTransformerContext(
     173                 :            :         XMLTransformerBase& rImp,
     174                 :            :         const OUString& rQName,
     175                 :            :        sal_uInt16 nActionMap ) :
     176                 :            :     XMLTransformerContext( rImp, rQName ),
     177                 :            :     m_nActionMap( nActionMap ),
     178         [ #  # ]:          0 :     m_bStartElementExported( sal_False )
     179                 :            : {
     180                 :          0 : }
     181                 :            : 
     182                 :          0 : XMLMergeElemTransformerContext::~XMLMergeElemTransformerContext()
     183                 :            : {
     184         [ #  # ]:          0 : }
     185                 :            : 
     186                 :          0 : void XMLMergeElemTransformerContext::StartElement(
     187                 :            :     const Reference< XAttributeList >& rAttrList )
     188                 :            : {
     189                 :            :     XMLMutableAttributeList *pMutableAttrList =
     190         [ #  # ]:          0 :         new XMLMutableAttributeList( rAttrList, sal_True );
     191         [ #  # ]:          0 :     m_xAttrList = pMutableAttrList;
     192                 :            : 
     193         [ #  # ]:          0 :     sal_Int16 nAttrCount = m_xAttrList.is() ? m_xAttrList->getLength() : 0;
     194         [ #  # ]:          0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     195                 :            :     {
     196 [ #  # ][ #  # ]:          0 :         const OUString& rAttrName = m_xAttrList->getNameByIndex( i );
     197                 :          0 :         OUString aLocalName;
     198                 :            :         sal_uInt16 nPrefix =
     199                 :          0 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     200         [ #  # ]:          0 :                                                                 &aLocalName );
     201                 :          0 :         sal_Bool bRemove = sal_True;
     202         [ #  # ]:          0 :         if( XML_NAMESPACE_OFFICE == nPrefix)
     203                 :            :         {
     204 [ #  # ][ #  # ]:          0 :             if (IsXMLToken( aLocalName, XML_DISPLAY ) )
     205                 :          0 :                 bRemove = sal_False;
     206 [ #  # ][ #  # ]:          0 :             else if (IsXMLToken( aLocalName, XML_AUTHOR ) )
     207                 :          0 :                 bRemove = sal_False;
     208 [ #  # ][ #  # ]:          0 :             else if (IsXMLToken( aLocalName, XML_CREATE_DATE ) )
     209                 :          0 :                 bRemove = sal_False;
     210 [ #  # ][ #  # ]:          0 :             else if (IsXMLToken( aLocalName, XML_CREATE_DATE_STRING ) )
     211                 :          0 :                 bRemove = sal_False;
     212                 :            :         }
     213         [ #  # ]:          0 :         if (bRemove)
     214                 :            :         {
     215         [ #  # ]:          0 :             pMutableAttrList->RemoveAttributeByIndex( i );
     216                 :          0 :             --i;
     217                 :          0 :             --nAttrCount;
     218                 :            :         }
     219                 :          0 :     }
     220                 :          0 : }
     221                 :            : 
     222                 :          0 : XMLTransformerContext *XMLMergeElemTransformerContext::CreateChildContext(
     223                 :            :         sal_uInt16 nPrefix,
     224                 :            :         const OUString& rLocalName,
     225                 :            :         const OUString& rQName,
     226                 :            :         const Reference< XAttributeList >& rAttrList )
     227                 :            : {
     228                 :          0 :     XMLTransformerContext *pContext = 0;
     229                 :            : 
     230         [ #  # ]:          0 :     if( !m_bStartElementExported )
     231                 :            :     {
     232                 :            :         XMLTransformerActions *pActions =
     233                 :          0 :             GetTransformer().GetUserDefinedActions( m_nActionMap );
     234                 :            :         OSL_ENSURE( pActions, "go no actions" );
     235         [ #  # ]:          0 :         if( pActions )
     236                 :            :         {
     237                 :          0 :             XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
     238                 :            :             XMLTransformerActions::const_iterator aIter =
     239         [ #  # ]:          0 :                 pActions->find( aKey );
     240                 :            : 
     241 [ #  # ][ #  # ]:          0 :             if( !(aIter == pActions->end()) )
     242                 :            :             {
     243         [ #  # ]:          0 :                 switch( (*aIter).second.m_nActionType )
           [ #  #  #  # ]
     244                 :            :                 {
     245                 :            :                 case XML_ATACTION_MOVE_FROM_ELEM_RNG2ISO_DATETIME:
     246                 :            :                     {
     247                 :            :                         XMLPersTextContentTContext *pTC =
     248                 :            :                             new XMLPersTextContentRNGTransformTContext(
     249                 :          0 :                                     GetTransformer(), rQName,
     250         [ #  # ]:          0 :                                     (*aIter).second.GetQNamePrefixFromParam1(),
     251 [ #  # ][ #  # ]:          0 :                                     (*aIter).second.GetQNameTokenFromParam1() );
                 [ #  # ]
     252         [ #  # ]:          0 :                         XMLPersTextContentTContextVector::value_type aVal(pTC);
     253         [ #  # ]:          0 :                         m_aChildContexts.push_back( aVal );
     254         [ #  # ]:          0 :                         pContext = pTC;
     255                 :            :                     }
     256                 :          0 :                     break;
     257                 :            :                 case XML_ATACTION_MOVE_FROM_ELEM:
     258                 :            :                     {
     259                 :            :                         XMLPersTextContentTContext *pTC =
     260                 :            :                             new XMLPersTextContentTContext(
     261                 :          0 :                                     GetTransformer(), rQName,
     262         [ #  # ]:          0 :                                     (*aIter).second.GetQNamePrefixFromParam1(),
     263 [ #  # ][ #  # ]:          0 :                                     (*aIter).second.GetQNameTokenFromParam1() );
                 [ #  # ]
     264         [ #  # ]:          0 :                         XMLPersTextContentTContextVector::value_type aVal(pTC);
     265         [ #  # ]:          0 :                         m_aChildContexts.push_back( aVal );
     266         [ #  # ]:          0 :                         pContext = pTC;
     267                 :            :                     }
     268                 :          0 :                     break;
     269                 :            :                 case XML_ETACTION_EXTRACT_CHARACTERS:
     270                 :            :                     {
     271         [ #  # ]:          0 :                         if( !m_bStartElementExported )
     272         [ #  # ]:          0 :                             ExportStartElement();
     273                 :            :                         XMLParagraphTransformerContext* pPTC =
     274                 :          0 :                             new XMLParagraphTransformerContext( GetTransformer(),
     275 [ #  # ][ #  # ]:          0 :                             rQName);
     276                 :          0 :                         pContext = pPTC;
     277                 :            :                     }
     278                 :          0 :                     break;
     279                 :            :                 default:
     280                 :            :                     OSL_ENSURE( !this, "unknown action" );
     281                 :          0 :                     break;
     282                 :            :                 }
     283                 :          0 :             }
     284                 :            :         }
     285                 :            :     }
     286                 :            :     else
     287                 :            :     {
     288                 :            :         XMLTransformerActions *pActions =
     289                 :          0 :             GetTransformer().GetUserDefinedActions( m_nActionMap );
     290                 :            :         OSL_ENSURE( pActions, "go no actions" );
     291         [ #  # ]:          0 :         if( pActions )
     292                 :            :         {
     293                 :          0 :             XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
     294                 :            :             XMLTransformerActions::const_iterator aIter =
     295         [ #  # ]:          0 :                 pActions->find( aKey );
     296                 :            : 
     297 [ #  # ][ #  # ]:          0 :             if( !(aIter == pActions->end()) )
     298                 :            :             {
     299 [ #  # ][ #  # ]:          0 :                 switch( (*aIter).second.m_nActionType )
     300                 :            :                 {
     301                 :            :                 case XML_ETACTION_EXTRACT_CHARACTERS:
     302                 :            :                     {
     303         [ #  # ]:          0 :                         if( !m_bStartElementExported )
     304         [ #  # ]:          0 :                             ExportStartElement();
     305                 :            :                         XMLParagraphTransformerContext* pPTC =
     306                 :          0 :                             new XMLParagraphTransformerContext( GetTransformer(),
     307 [ #  # ][ #  # ]:          0 :                             rQName);
     308                 :          0 :                         pContext = pPTC;
     309                 :            :                     }
     310                 :          0 :                     break;
     311                 :            :                 default:
     312                 :            :                     OSL_ENSURE( !this, "unknown action" );
     313                 :          0 :                     break;
     314                 :            :                 }
     315                 :          0 :             }
     316                 :            :         }
     317                 :            :     }
     318                 :            : 
     319                 :            :     // default is copying
     320         [ #  # ]:          0 :     if( !pContext )
     321                 :            :     {
     322         [ #  # ]:          0 :         if( !m_bStartElementExported )
     323                 :          0 :             ExportStartElement();
     324                 :            :         pContext = XMLTransformerContext::CreateChildContext( nPrefix,
     325                 :            :                                                               rLocalName,
     326                 :            :                                                               rQName,
     327                 :          0 :                                                               rAttrList );
     328                 :            :     }
     329                 :            : 
     330                 :          0 :     return pContext;
     331                 :            : }
     332                 :            : 
     333                 :          0 : void XMLMergeElemTransformerContext::EndElement()
     334                 :            : {
     335         [ #  # ]:          0 :     if( !m_bStartElementExported )
     336                 :          0 :         ExportStartElement();
     337                 :          0 :     XMLTransformerContext::EndElement();
     338                 :          0 : }
     339                 :            : 
     340                 :          0 : void XMLMergeElemTransformerContext::Characters( const OUString& )
     341                 :            : {
     342                 :            :     // ignore
     343                 :          0 : }
     344                 :            : 
     345                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10