LCOV - code coverage report
Current view: top level - xmloff/source/transform - EventOOoTContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 93 107 86.9 %
Date: 2012-08-25 Functions: 11 18 61.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 64 127 50.4 %

           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 "EventOOoTContext.hxx"
      30                 :            : #include "EventMap.hxx"
      31                 :            : #include "MutableAttrList.hxx"
      32                 :            : #include "xmloff/xmlnmspe.hxx"
      33                 :            : #include "ActionMapTypesOOo.hxx"
      34                 :            : #include "AttrTransformerAction.hxx"
      35                 :            : #include "TransformerActions.hxx"
      36                 :            : #include "TransformerBase.hxx"
      37                 :            : #include <comphelper/stl_types.hxx>
      38                 :            : #include <rtl/ustrbuf.hxx>
      39                 :            : 
      40                 :            : #include <boost/unordered_map.hpp>
      41                 :            : 
      42                 :            : using ::rtl::OUString;
      43                 :            : using ::rtl::OUStringBuffer;
      44                 :            : using namespace ::com::sun::star::uno;
      45                 :            : using namespace ::com::sun::star::xml::sax;
      46                 :            : using namespace ::xmloff::token;
      47                 :            : 
      48                 :            : class XMLTransformerOOoEventMap_Impl:
      49                 :            :     public ::boost::unordered_map< ::rtl::OUString, NameKey_Impl,
      50                 :            :                             ::rtl::OUStringHash, ::comphelper::UStringEqual >
      51                 :            : {
      52                 :            : public:
      53                 :            : 
      54                 :            :     void AddMap( XMLTransformerEventMapEntry *pInit );
      55                 :            : 
      56                 :            :     XMLTransformerOOoEventMap_Impl( XMLTransformerEventMapEntry *pInit,
      57                 :            :                                        XMLTransformerEventMapEntry *pInit2  );
      58                 :            :     ~XMLTransformerOOoEventMap_Impl();
      59                 :            : };
      60                 :            : 
      61                 :          4 : void XMLTransformerOOoEventMap_Impl::AddMap( XMLTransformerEventMapEntry *pInit )
      62                 :            : {
      63                 :          4 :     XMLTransformerOOoEventMap_Impl::key_type aKey;
      64                 :          4 :     XMLTransformerOOoEventMap_Impl::mapped_type aData;
      65         [ +  + ]:        140 :     while( pInit->m_pOOoName )
      66                 :            :     {
      67                 :        136 :         aKey = OUString::createFromAscii(pInit->m_pOOoName);
      68                 :            : 
      69                 :            :         OSL_ENSURE( find( aKey ) == end(), "duplicate event map entry" );
      70                 :            : 
      71                 :        136 :         aData.m_nPrefix = pInit->m_nOASISPrefix;
      72                 :        136 :         aData.m_aLocalName = OUString::createFromAscii(pInit->m_pOASISName);
      73                 :            : 
      74                 :        136 :         XMLTransformerOOoEventMap_Impl::value_type aVal( aKey, aData );
      75                 :            : 
      76         [ +  - ]:        136 :         if( !insert( aVal ).second )
      77                 :            :         {
      78                 :            :             OSL_FAIL( "duplicate OOo event name extry" );
      79                 :            :         }
      80                 :            : 
      81                 :        136 :         ++pInit;
      82                 :        140 :     }
      83                 :          4 : }
      84                 :            : 
      85                 :          2 : XMLTransformerOOoEventMap_Impl::XMLTransformerOOoEventMap_Impl(
      86                 :            :         XMLTransformerEventMapEntry *pInit,
      87         [ +  - ]:          2 :         XMLTransformerEventMapEntry *pInit2 )
      88                 :            : {
      89         [ +  - ]:          2 :     if( pInit )
      90         [ +  - ]:          2 :         AddMap( pInit );
      91         [ +  - ]:          2 :     if( pInit )
      92         [ +  - ]:          2 :         AddMap( pInit2 );
      93                 :          2 : }
      94                 :            : 
      95                 :          2 : XMLTransformerOOoEventMap_Impl::~XMLTransformerOOoEventMap_Impl()
      96                 :            : {
      97                 :          2 : }
      98                 :            : 
      99                 :            : // -----------------------------------------------------------------------------
     100                 :            : 
     101 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLEventOOoTransformerContext, XMLPersElemContentTContext );
     102                 :            : 
     103                 :          6 : XMLEventOOoTransformerContext::XMLEventOOoTransformerContext(
     104                 :            :         XMLTransformerBase& rImp,
     105                 :            :         const OUString& rQName,
     106                 :            :         sal_Bool bPersistent ) :
     107                 :            :     XMLPersElemContentTContext( rImp, rQName,
     108                 :          6 :         rImp.GetNamespaceMap().GetKeyByAttrName( rQName ), XML_EVENT_LISTENER ),
     109                 :          6 :     m_bPersistent( bPersistent )
     110                 :            : {
     111                 :          6 : }
     112                 :            : 
     113                 :          6 : XMLEventOOoTransformerContext::~XMLEventOOoTransformerContext()
     114                 :            : {
     115         [ -  + ]:         12 : }
     116                 :            : 
     117                 :            : XMLTransformerOOoEventMap_Impl
     118                 :          2 :     *XMLEventOOoTransformerContext::CreateEventMap()
     119                 :            : {
     120                 :            :     return new XMLTransformerOOoEventMap_Impl( aTransformerEventMap,
     121         [ +  - ]:          2 :                                                   aFormTransformerEventMap );
     122                 :            : }
     123                 :            : 
     124                 :        138 : void XMLEventOOoTransformerContext::FlushEventMap(
     125                 :            :         XMLTransformerOOoEventMap_Impl *p )
     126                 :            : {
     127         [ +  + ]:        138 :     delete p;
     128                 :        138 : }
     129                 :            : 
     130                 :          6 : sal_uInt16 XMLEventOOoTransformerContext::GetEventName(
     131                 :            :         const OUString& rName,
     132                 :            :         OUString& rNewName,
     133                 :            :            XMLTransformerOOoEventMap_Impl& rMap )
     134                 :            : {
     135                 :          6 :     XMLTransformerOOoEventMap_Impl::key_type aKey( rName );
     136         [ +  - ]:          6 :     XMLTransformerOOoEventMap_Impl::const_iterator aIter = rMap.find( aKey );
     137 [ -  + ][ +  - ]:          6 :     if( aIter == rMap.end() )
     138                 :            :     {
     139                 :          0 :         rNewName = rName;
     140                 :          0 :         return XML_NAMESPACE_UNKNOWN;
     141                 :            :     }
     142                 :            :     else
     143                 :            :     {
     144         [ +  - ]:          6 :         rNewName = (*aIter).second.m_aLocalName;
     145         [ +  - ]:          6 :         return (*aIter).second.m_nPrefix;
     146                 :          6 :     }
     147                 :            : }
     148                 :            : 
     149                 :            : 
     150                 :          6 : void XMLEventOOoTransformerContext::StartElement(
     151                 :            :     const Reference< XAttributeList >& rAttrList )
     152                 :            : {
     153                 :            :     XMLTransformerActions *pActions =
     154         [ +  - ]:          6 :         GetTransformer().GetUserDefinedActions( OOO_EVENT_ACTIONS );
     155                 :            :     OSL_ENSURE( pActions, "go no actions" );
     156                 :            : 
     157                 :          6 :     OUString aLocation, aMacroName;
     158                 :          6 :     sal_Int16 nMacroName = -1;
     159                 :          6 :     Reference< XAttributeList > xAttrList( rAttrList );
     160                 :          6 :     XMLMutableAttributeList *pMutableAttrList = 0;
     161 [ +  - ][ +  - ]:          6 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ +  - ]
     162         [ +  + ]:         36 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     163                 :            :     {
     164 [ +  - ][ +  - ]:         30 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     165                 :         30 :         OUString aLocalName;
     166                 :            :         sal_uInt16 nPrefix =
     167                 :         30 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     168         [ +  - ]:         30 :                                                                  &aLocalName );
     169                 :         30 :         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
     170                 :            :         XMLTransformerActions::const_iterator aIter =
     171         [ +  - ]:         30 :             pActions->find( aKey );
     172 [ +  - ][ +  - ]:         30 :         if( !(aIter == pActions->end() ) )
     173                 :            :         {
     174         [ +  + ]:         30 :             if( !pMutableAttrList )
     175                 :            :             {
     176                 :            :                 pMutableAttrList =
     177         [ +  - ]:          6 :                         new XMLMutableAttributeList( xAttrList );
     178 [ +  - ][ +  - ]:          6 :                 xAttrList = pMutableAttrList;
     179                 :            :             }
     180 [ +  - ][ +  - ]:         30 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     181 [ +  - ][ -  +  :         30 :             switch( (*aIter).second.m_nActionType )
             +  +  +  -  
                      - ]
     182                 :            :             {
     183                 :            :             case XML_ATACTION_HREF:
     184                 :            :                 // TODO
     185                 :          0 :                 break;
     186                 :            :             case XML_ATACTION_EVENT_NAME:
     187                 :            :                 pMutableAttrList->SetValueByIndex( i,
     188 [ +  - ][ +  - ]:          6 :                                GetTransformer().GetEventName( rAttrValue ) );
     189                 :          6 :                 break;
     190                 :            :             case XML_ATACTION_ADD_NAMESPACE_PREFIX:
     191                 :            :                 {
     192                 :          6 :                     OUString aAttrValue( rAttrValue );
     193                 :            :                     sal_uInt16 nValPrefix =
     194         [ +  - ]:          6 :                         static_cast<sal_uInt16>((*aIter).second.m_nParam1);
     195         [ +  - ]:         12 :                     if( GetTransformer().AddNamespacePrefix( aAttrValue,
     196         [ +  - ]:          6 :                                                              nValPrefix ) )
     197         [ +  - ]:          6 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     198                 :            :                 }
     199                 :          6 :                 break;
     200                 :            :             case XML_ATACTION_MACRO_LOCATION:
     201                 :         12 :                 aLocation = rAttrValue;
     202         [ +  - ]:         12 :                 pMutableAttrList->RemoveAttributeByIndex( i );
     203                 :         12 :                 --i;
     204                 :         12 :                 --nAttrCount;
     205                 :         12 :                 break;
     206                 :            :             case XML_ATACTION_MACRO_NAME:
     207                 :          6 :                 aMacroName = rAttrValue;
     208                 :          6 :                 nMacroName = i;
     209                 :          6 :                 break;
     210                 :            :             case XML_ATACTION_COPY:
     211                 :          0 :                 break;
     212                 :            :             default:
     213                 :            :                 OSL_ENSURE( !this, "unknown action" );
     214                 :          0 :                 break;
     215                 :         30 :             }
     216                 :            :         }
     217                 :         30 :     }
     218                 :            : 
     219 [ +  - ][ +  - ]:          6 :     if( nMacroName != -1 && !aLocation.isEmpty() )
                 [ +  - ]
     220                 :            :     {
     221 [ +  - ][ +  - ]:          6 :         if( !IsXMLToken( aLocation, XML_APPLICATION ) )
     222         [ +  - ]:          6 :             aLocation = GetXMLToken( XML_DOCUMENT );
     223                 :          6 :         OUStringBuffer sTmp( aLocation.getLength() + aMacroName.getLength() + 1 );
     224 [ +  - ][ +  - ]:          6 :         sTmp = aLocation;
     225         [ +  - ]:          6 :         sTmp.append( sal_Unicode( ':' ) );
     226         [ +  - ]:          6 :         sTmp.append( aMacroName );
     227                 :            :         pMutableAttrList->SetValueByIndex( nMacroName,
     228 [ +  - ][ +  - ]:          6 :                                            sTmp.makeStringAndClear() );
     229                 :            :     }
     230                 :            : 
     231         [ -  + ]:          6 :     if( m_bPersistent )
     232         [ #  # ]:          0 :         XMLPersElemContentTContext::StartElement( xAttrList );
     233                 :            :     else
     234         [ +  - ]:          6 :         GetTransformer().GetDocHandler()->startElement( GetExportQName(),
     235         [ +  - ]:          6 :                                                         xAttrList );
     236                 :          6 : }
     237                 :            : 
     238                 :          6 : void XMLEventOOoTransformerContext::EndElement()
     239                 :            : {
     240         [ -  + ]:          6 :     if( m_bPersistent )
     241                 :          0 :         XMLPersElemContentTContext::EndElement();
     242                 :            :     else
     243                 :          6 :         GetTransformer().GetDocHandler()->endElement( GetExportQName() );
     244                 :          6 : }
     245                 :            : 
     246                 :          0 : XMLTransformerContext * XMLEventOOoTransformerContext::CreateChildContext(
     247                 :            :                             sal_uInt16 nPrefix,
     248                 :            :                             const OUString& rLocalName,
     249                 :            :                             const OUString& rQName,
     250                 :            :                             const Reference< XAttributeList >& xAttrList )
     251                 :            : {
     252         [ #  # ]:          0 :     if( m_bPersistent )
     253                 :          0 :         return XMLPersElemContentTContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
     254                 :            :     else
     255                 :          0 :         return XMLTransformerContext::CreateChildContext(nPrefix, rLocalName, rQName, xAttrList);
     256                 :            : }
     257                 :            : 
     258                 :          0 : sal_Bool XMLEventOOoTransformerContext::IsPersistent() const
     259                 :            : {
     260                 :          0 :     return m_bPersistent;
     261                 :            : }
     262                 :            : 
     263                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10