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

Generated by: LCOV version 1.10