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

Generated by: LCOV version 1.11