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

Generated by: LCOV version 1.10