LCOV - code coverage report
Current view: top level - xmloff/source/transform - NotesTContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 80 57.5 %
Date: 2015-06-13 12:38:46 Functions: 5 12 41.7 %
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 <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 <osl/diagnose.h>
      25             : #include <xmloff/nmspmap.hxx>
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <xmloff/xmlnmspe.hxx>
      28             : 
      29             : #include "TransformerBase.hxx"
      30             : #include "TransformerActions.hxx"
      31             : #include "AttrTransformerAction.hxx"
      32             : #include "ActionMapTypesOASIS.hxx"
      33             : #include "MutableAttrList.hxx"
      34             : #include "RenameElemTContext.hxx"
      35             : #include "FlatTContext.hxx"
      36             : 
      37             : #include "NotesTContext.hxx"
      38             : 
      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           4 : XMLNotesTransformerContext::XMLNotesTransformerContext(
      46             :         XMLTransformerBase& rImp,
      47             :         const OUString& rQName,
      48             :         XMLTokenEnum eToken, bool bPersistent ) :
      49             :     XMLPersElemContentTContext( rImp, rQName ),
      50             :     m_bEndNote( false ),
      51             :     m_bPersistent( bPersistent ),
      52           4 :     m_eTypeToken( eToken )
      53             : {
      54           4 : }
      55             : 
      56           8 : XMLNotesTransformerContext::~XMLNotesTransformerContext()
      57             : {
      58           8 : }
      59             : 
      60           4 : void XMLNotesTransformerContext::StartElement(
      61             :         const Reference< XAttributeList >& rAttrList )
      62             : {
      63             :     XMLTransformerActions *pActions =
      64           4 :         GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
      65             :     OSL_ENSURE( pActions, "go no actions" );
      66             : 
      67           4 :     Reference< XAttributeList > xAttrList( rAttrList );
      68           4 :     XMLMutableAttributeList *pMutableAttrList = 0;
      69           4 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      70          20 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      71             :     {
      72          16 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      73          32 :         OUString aLocalName;
      74             :         sal_uInt16 nPrefix =
      75          16 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      76          16 :                                                                  &aLocalName );
      77          32 :         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
      78             :         XMLTransformerActions::const_iterator aIter =
      79          16 :             pActions->find( aKey );
      80          16 :         if( !(aIter == pActions->end() ) )
      81             :         {
      82           4 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
      83             : 
      84           4 :             if( !pMutableAttrList )
      85             :             {
      86             :                 pMutableAttrList =
      87           4 :                     new XMLMutableAttributeList( xAttrList );
      88           4 :                 xAttrList = pMutableAttrList;
      89             :             }
      90           4 :             switch( (*aIter).second.m_nActionType )
      91             :             {
      92             :             case XML_ATACTION_STYLE_FAMILY:
      93             :                 {
      94           4 :                     if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) )
      95             :                     {
      96             :                     }
      97           2 :                     else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) )
      98             :                     {
      99           2 :                         m_bEndNote = true;
     100             :                     }
     101           4 :                     pMutableAttrList->RemoveAttributeByIndex( i );
     102           4 :                     --i;
     103           4 :                     --nAttrCount;
     104             :                 }
     105           4 :                 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( XMLTransformerBase::DecodeStyleName(aAttrValue) )
     111           0 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     112             :                 }
     113           0 :                 break;
     114           4 :             }
     115             :         }
     116          16 :     }
     117             : 
     118           4 :     XMLTokenEnum eToken = XML_FOOTNOTE;
     119           4 :     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           4 :                              : XML_FOOTNOTES_CONFIGURATION);
     127           4 :         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           4 :     SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
     137             :                             XML_NAMESPACE_TEXT,
     138           8 :                             ::xmloff::token::GetXMLToken( eToken ) ) );
     139           4 :     if( m_bPersistent )
     140           0 :         XMLPersElemContentTContext::StartElement( xAttrList );
     141             :     else
     142           8 :         GetTransformer().GetDocHandler()->startElement( GetExportQName(),
     143           8 :                                                         xAttrList );
     144           4 : }
     145             : 
     146           4 : void XMLNotesTransformerContext::EndElement()
     147             : {
     148           4 :     if( m_bPersistent )
     149             :     {
     150           0 :         XMLPersElemContentTContext::EndElement();
     151             :     }
     152             :     else
     153             :     {
     154           4 :         GetTransformer().GetDocHandler()->endElement( GetExportQName() );
     155             :     }
     156           4 : }
     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 : 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.11