LCOV - code coverage report
Current view: top level - xmloff/source/transform - EventOOoTContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 107 0.0 %
Date: 2014-04-14 Functions: 0 18 0.0 %
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           0 : void XMLTransformerOOoEventMap_Impl::AddMap( XMLTransformerEventMapEntry *pInit )
      49             : {
      50           0 :     XMLTransformerOOoEventMap_Impl::key_type aKey;
      51           0 :     XMLTransformerOOoEventMap_Impl::mapped_type aData;
      52           0 :     while( pInit->m_pOOoName )
      53             :     {
      54           0 :         aKey = OUString::createFromAscii(pInit->m_pOOoName);
      55             : 
      56             :         OSL_ENSURE( find( aKey ) == end(), "duplicate event map entry" );
      57             : 
      58           0 :         aData.m_nPrefix = pInit->m_nOASISPrefix;
      59           0 :         aData.m_aLocalName = OUString::createFromAscii(pInit->m_pOASISName);
      60             : 
      61           0 :         XMLTransformerOOoEventMap_Impl::value_type aVal( aKey, aData );
      62             : 
      63           0 :         if( !insert( aVal ).second )
      64             :         {
      65             :             OSL_FAIL( "duplicate OOo event name extry" );
      66             :         }
      67             : 
      68           0 :         ++pInit;
      69           0 :     }
      70           0 : }
      71             : 
      72           0 : XMLTransformerOOoEventMap_Impl::XMLTransformerOOoEventMap_Impl(
      73             :         XMLTransformerEventMapEntry *pInit,
      74           0 :         XMLTransformerEventMapEntry *pInit2 )
      75             : {
      76           0 :     if( pInit )
      77           0 :         AddMap( pInit );
      78           0 :     if( pInit )
      79           0 :         AddMap( pInit2 );
      80           0 : }
      81             : 
      82           0 : XMLTransformerOOoEventMap_Impl::~XMLTransformerOOoEventMap_Impl()
      83             : {
      84           0 : }
      85             : 
      86           0 : TYPEINIT1( XMLEventOOoTransformerContext, XMLPersElemContentTContext );
      87             : 
      88           0 : XMLEventOOoTransformerContext::XMLEventOOoTransformerContext(
      89             :         XMLTransformerBase& rImp,
      90             :         const OUString& rQName,
      91             :         sal_Bool bPersistent ) :
      92             :     XMLPersElemContentTContext( rImp, rQName,
      93           0 :         rImp.GetNamespaceMap().GetKeyByAttrName( rQName ), XML_EVENT_LISTENER ),
      94           0 :     m_bPersistent( bPersistent )
      95             : {
      96           0 : }
      97             : 
      98           0 : XMLEventOOoTransformerContext::~XMLEventOOoTransformerContext()
      99             : {
     100           0 : }
     101             : 
     102             : XMLTransformerOOoEventMap_Impl
     103           0 :     *XMLEventOOoTransformerContext::CreateEventMap()
     104             : {
     105             :     return new XMLTransformerOOoEventMap_Impl( aTransformerEventMap,
     106           0 :                                                   aFormTransformerEventMap );
     107             : }
     108             : 
     109           0 : void XMLEventOOoTransformerContext::FlushEventMap(
     110             :         XMLTransformerOOoEventMap_Impl *p )
     111             : {
     112           0 :     delete p;
     113           0 : }
     114             : 
     115           0 : sal_uInt16 XMLEventOOoTransformerContext::GetEventName(
     116             :         const OUString& rName,
     117             :         OUString& rNewName,
     118             :            XMLTransformerOOoEventMap_Impl& rMap )
     119             : {
     120           0 :     XMLTransformerOOoEventMap_Impl::key_type aKey( rName );
     121           0 :     XMLTransformerOOoEventMap_Impl::const_iterator aIter = rMap.find( aKey );
     122           0 :     if( aIter == rMap.end() )
     123             :     {
     124           0 :         rNewName = rName;
     125           0 :         return XML_NAMESPACE_UNKNOWN;
     126             :     }
     127             :     else
     128             :     {
     129           0 :         rNewName = (*aIter).second.m_aLocalName;
     130           0 :         return (*aIter).second.m_nPrefix;
     131           0 :     }
     132             : }
     133             : 
     134           0 : void XMLEventOOoTransformerContext::StartElement(
     135             :     const Reference< XAttributeList >& rAttrList )
     136             : {
     137             :     XMLTransformerActions *pActions =
     138           0 :         GetTransformer().GetUserDefinedActions( OOO_EVENT_ACTIONS );
     139             :     OSL_ENSURE( pActions, "go no actions" );
     140             : 
     141           0 :     OUString aLocation, aMacroName;
     142           0 :     sal_Int16 nMacroName = -1;
     143           0 :     Reference< XAttributeList > xAttrList( rAttrList );
     144           0 :     XMLMutableAttributeList *pMutableAttrList = 0;
     145           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     146           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     147             :     {
     148           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     149           0 :         OUString aLocalName;
     150             :         sal_uInt16 nPrefix =
     151           0 :             GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     152           0 :                                                                  &aLocalName );
     153           0 :         XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
     154             :         XMLTransformerActions::const_iterator aIter =
     155           0 :             pActions->find( aKey );
     156           0 :         if( !(aIter == pActions->end() ) )
     157             :         {
     158           0 :             if( !pMutableAttrList )
     159             :             {
     160             :                 pMutableAttrList =
     161           0 :                         new XMLMutableAttributeList( xAttrList );
     162           0 :                 xAttrList = pMutableAttrList;
     163             :             }
     164           0 :             const OUString& rAttrValue = xAttrList->getValueByIndex( i );
     165           0 :             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           0 :                                GetTransformer().GetEventName( rAttrValue ) );
     173           0 :                 break;
     174             :             case XML_ATACTION_ADD_NAMESPACE_PREFIX:
     175             :                 {
     176           0 :                     OUString aAttrValue( rAttrValue );
     177             :                     sal_uInt16 nValPrefix =
     178           0 :                         static_cast<sal_uInt16>((*aIter).second.m_nParam1);
     179           0 :                     if( GetTransformer().AddNamespacePrefix( aAttrValue,
     180           0 :                                                              nValPrefix ) )
     181           0 :                         pMutableAttrList->SetValueByIndex( i, aAttrValue );
     182             :                 }
     183           0 :                 break;
     184             :             case XML_ATACTION_MACRO_LOCATION:
     185           0 :                 aLocation = rAttrValue;
     186           0 :                 pMutableAttrList->RemoveAttributeByIndex( i );
     187           0 :                 --i;
     188           0 :                 --nAttrCount;
     189           0 :                 break;
     190             :             case XML_ATACTION_MACRO_NAME:
     191           0 :                 aMacroName = rAttrValue;
     192           0 :                 nMacroName = i;
     193           0 :                 break;
     194             :             case XML_ATACTION_COPY:
     195           0 :                 break;
     196             :             default:
     197             :                 OSL_ENSURE( !this, "unknown action" );
     198           0 :                 break;
     199           0 :             }
     200             :         }
     201           0 :     }
     202             : 
     203           0 :     if( nMacroName != -1 && !aLocation.isEmpty() )
     204             :     {
     205           0 :         if( !IsXMLToken( aLocation, XML_APPLICATION ) )
     206           0 :             aLocation = GetXMLToken( XML_DOCUMENT );
     207           0 :         OUStringBuffer sTmp( aLocation.getLength() + aMacroName.getLength() + 1 );
     208           0 :         sTmp = aLocation;
     209           0 :         sTmp.append( ':' );
     210           0 :         sTmp.append( aMacroName );
     211             :         pMutableAttrList->SetValueByIndex( nMacroName,
     212           0 :                                            sTmp.makeStringAndClear() );
     213             :     }
     214             : 
     215           0 :     if( m_bPersistent )
     216           0 :         XMLPersElemContentTContext::StartElement( xAttrList );
     217             :     else
     218           0 :         GetTransformer().GetDocHandler()->startElement( GetExportQName(),
     219           0 :                                                         xAttrList );
     220           0 : }
     221             : 
     222           0 : void XMLEventOOoTransformerContext::EndElement()
     223             : {
     224           0 :     if( m_bPersistent )
     225           0 :         XMLPersElemContentTContext::EndElement();
     226             :     else
     227           0 :         GetTransformer().GetDocHandler()->endElement( GetExportQName() );
     228           0 : }
     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 : sal_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