LCOV - code coverage report
Current view: top level - xmloff/source/transform - NotesTContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 80 57.5 %
Date: 2012-08-25 Functions: 5 12 41.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 109 33.9 %

           Branch data     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 <com/sun/star/xml/sax/SAXParseException.hpp>
      21                 :            : #include <com/sun/star/xml/sax/SAXException.hpp>
      22                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      23                 :            : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      24                 :            : #include <xmloff/nmspmap.hxx>
      25                 :            : #include <xmloff/xmltoken.hxx>
      26                 :            : #include "xmloff/xmlnmspe.hxx"
      27                 :            : 
      28                 :            : #include "TransformerBase.hxx"
      29                 :            : #include "TransformerActions.hxx"
      30                 :            : #include "AttrTransformerAction.hxx"
      31                 :            : #include "ActionMapTypesOASIS.hxx"
      32                 :            : #include "MutableAttrList.hxx"
      33                 :            : #include "RenameElemTContext.hxx"
      34                 :            : #include "FlatTContext.hxx"
      35                 :            : 
      36                 :            : #include "NotesTContext.hxx"
      37                 :            : 
      38                 :            : using ::rtl::OUString;
      39                 :            : using namespace ::xmloff::token;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::xml::sax;
      42                 :            : 
      43 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLNotesTransformerContext, XMLPersElemContentTContext );
      44                 :            : 
      45                 :          8 : XMLNotesTransformerContext::XMLNotesTransformerContext(
      46                 :            :         XMLTransformerBase& rImp,
      47                 :            :         const OUString& rQName,
      48                 :            :         XMLTokenEnum eToken, sal_Bool bPersistent ) :
      49                 :            :     XMLPersElemContentTContext( rImp, rQName ),
      50                 :            :     m_bEndNote( sal_False ),
      51                 :            :     m_bPersistent( bPersistent ),
      52                 :          8 :     m_eTypeToken( eToken )
      53                 :            : {
      54                 :          8 : }
      55                 :            : 
      56                 :          8 : XMLNotesTransformerContext::~XMLNotesTransformerContext()
      57                 :            : {
      58         [ -  + ]:         16 : }
      59                 :            : 
      60                 :          8 : void XMLNotesTransformerContext::StartElement(
      61                 :            :         const Reference< XAttributeList >& rAttrList )
      62                 :            : {
      63                 :            :     XMLTransformerActions *pActions =
      64         [ +  - ]:          8 :         GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
      65                 :            :     OSL_ENSURE( pActions, "go no actions" );
      66                 :            : 
      67                 :          8 :     Reference< XAttributeList > xAttrList( rAttrList );
      68                 :          8 :     XMLMutableAttributeList *pMutableAttrList = 0;
      69 [ +  - ][ +  - ]:          8 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
      70         [ +  + ]:         40 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      71                 :            :     {
      72 [ +  - ][ +  - ]:         32 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      73                 :         32 :         OUString aLocalName;
      74                 :            :         sal_uInt16 nPrefix =
      75                 :         32 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      76         [ +  - ]:         32 :                                                                  &aLocalName );
      77                 :         32 :         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
      78                 :            :         XMLTransformerActions::const_iterator aIter =
      79         [ +  - ]:         32 :             pActions->find( aKey );
      80 [ +  + ][ +  - ]:         32 :         if( !(aIter == pActions->end() ) )
      81                 :            :         {
      82 [ +  - ][ +  - ]:          8 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
      83                 :            : 
      84         [ +  - ]:          8 :             if( !pMutableAttrList )
      85                 :            :             {
      86                 :            :                 pMutableAttrList =
      87         [ +  - ]:          8 :                     new XMLMutableAttributeList( xAttrList );
      88 [ +  - ][ +  - ]:          8 :                 xAttrList = pMutableAttrList;
      89                 :            :             }
      90         [ +  - ]:          8 :             switch( (*aIter).second.m_nActionType )
              [ +  -  - ]
      91                 :            :             {
      92                 :            :             case XML_ATACTION_STYLE_FAMILY:
      93                 :            :                 {
      94 [ +  - ][ +  + ]:          8 :                     if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) )
      95                 :            :                     {
      96                 :            :                     }
      97 [ +  - ][ +  - ]:          4 :                     else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) )
      98                 :            :                     {
      99                 :          4 :                         m_bEndNote = sal_True;
     100                 :            :                     }
     101         [ +  - ]:          8 :                     pMutableAttrList->RemoveAttributeByIndex( i );
     102                 :          8 :                     --i;
     103                 :          8 :                     --nAttrCount;
     104                 :            :                 }
     105                 :          8 :                 break;
     106                 :            :             case XML_ATACTION_DECODE_STYLE_NAME:
     107                 :            :             case XML_ATACTION_DECODE_STYLE_NAME_REF:
     108                 :            :                 {
     109                 :          0 :                     OUString aAttrValue( rAttrValue );
     110 [ #  # ][ #  # ]:          0 :                     if( GetTransformer().DecodeStyleName(aAttrValue) )
     111         [ #  # ]:          0 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     112                 :            :                 }
     113                 :          0 :                 break;
     114                 :          8 :             }
     115                 :            :         }
     116                 :         32 :     }
     117                 :            : 
     118                 :          8 :     XMLTokenEnum eToken = XML_FOOTNOTE;
     119   [ -  +  -  - ]:          8 :     switch( m_eTypeToken )
     120                 :            :     {
     121                 :            :     case XML_NOTE:
     122         [ #  # ]:          0 :         eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
     123                 :          0 :         break;
     124                 :            :     case XML_NOTES_CONFIGURATION:
     125                 :            :         eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
     126         [ +  + ]:          8 :                              : XML_FOOTNOTES_CONFIGURATION);
     127                 :          8 :         break;
     128                 :            :     case XML_NOTE_REF:
     129         [ #  # ]:          0 :         eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
     130                 :          0 :         break;
     131                 :            :     default:
     132                 :            :         OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
     133                 :          0 :         break;
     134                 :            :     }
     135                 :            : 
     136                 :          8 :     SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
     137                 :            :                             XML_NAMESPACE_TEXT,
     138   [ +  -  +  - ]:         16 :                             ::xmloff::token::GetXMLToken( eToken ) ) );
     139         [ -  + ]:          8 :     if( m_bPersistent )
     140         [ #  # ]:          0 :         XMLPersElemContentTContext::StartElement( xAttrList );
     141                 :            :     else
     142         [ +  - ]:          8 :         GetTransformer().GetDocHandler()->startElement( GetExportQName(),
     143         [ +  - ]:          8 :                                                         xAttrList );
     144                 :          8 : }
     145                 :            : 
     146                 :          8 : void XMLNotesTransformerContext::EndElement()
     147                 :            : {
     148         [ -  + ]:          8 :     if( m_bPersistent )
     149                 :            :     {
     150                 :          0 :         XMLPersElemContentTContext::EndElement();
     151                 :            :     }
     152                 :            :     else
     153                 :            :     {
     154                 :          8 :         GetTransformer().GetDocHandler()->endElement( GetExportQName() );
     155                 :            :     }
     156                 :          8 : }
     157                 :            : 
     158                 :          0 : XMLTransformerContext *XMLNotesTransformerContext::CreateChildContext(
     159                 :            :         sal_uInt16 nPrefix,
     160                 :            :         const OUString& rLocalName,
     161                 :            :         const OUString& rQName,
     162                 :            :         const Reference< XAttributeList >& rAttrList )
     163                 :            : {
     164                 :          0 :     XMLTransformerContext *pContext = 0;
     165         [ #  # ]:          0 :     if( XML_NOTE == m_eTypeToken )
     166                 :            :     {
     167         [ #  # ]:          0 :         if( XML_NAMESPACE_TEXT == nPrefix )
     168                 :            :         {
     169                 :          0 :             XMLTokenEnum eToken ( XML_TOKEN_INVALID );
     170         [ #  # ]:          0 :             if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
     171                 :            :             {
     172                 :            :                 eToken = m_bEndNote ? XML_ENDNOTE_CITATION
     173         [ #  # ]:          0 :                                   : XML_FOOTNOTE_CITATION;
     174                 :            :             }
     175         [ #  # ]:          0 :             else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
     176                 :            :             {
     177                 :            :                 eToken = m_bEndNote ? XML_ENDNOTE_BODY
     178         [ #  # ]:          0 :                                   : XML_FOOTNOTE_BODY;
     179                 :            :             }
     180                 :            : 
     181         [ #  # ]:          0 :             if( XML_TOKEN_INVALID != eToken )
     182                 :            :             {
     183         [ #  # ]:          0 :                 if( m_bPersistent  )
     184                 :            :                 {
     185                 :            :                     pContext = new XMLPersTextContentTContext(
     186                 :          0 :                                     GetTransformer(), rQName,
     187                 :            :                                     XML_NAMESPACE_TEXT,
     188         [ #  # ]:          0 :                                     eToken );
     189                 :          0 :                     AddContent( pContext );
     190                 :            : 
     191                 :            :                 }
     192                 :            :                 else
     193                 :            :                 {
     194                 :            :                     pContext = new XMLRenameElemTransformerContext(
     195                 :          0 :                                     GetTransformer(), rQName,
     196                 :            :                                     XML_NAMESPACE_TEXT,
     197         [ #  # ]:          0 :                                     eToken );
     198                 :            :                 }
     199                 :            :             }
     200                 :            :         }
     201                 :            :     }
     202                 :            : 
     203         [ #  # ]:          0 :     if( !pContext )
     204                 :            :     {
     205                 :            :         pContext = m_bPersistent
     206                 :            :                         ? XMLPersElemContentTContext::CreateChildContext(
     207                 :          0 :                                 nPrefix, rLocalName, rQName, rAttrList )
     208                 :            :                         : XMLTransformerContext::CreateChildContext(
     209         [ #  # ]:          0 :                                 nPrefix, rLocalName, rQName, rAttrList );
     210                 :            :     }
     211                 :            : 
     212                 :          0 :     return pContext;
     213                 :            : }
     214                 :            : 
     215                 :          0 : sal_Bool XMLNotesTransformerContext::IsPersistent() const
     216                 :            : {
     217                 :          0 :     return m_bPersistent;
     218                 :            : }
     219                 :            : 
     220                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10