LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/text - XMLAutoTextEventExport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 90 0.0 %
Date: 2013-07-09 Functions: 0 21 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 "XMLAutoTextEventExport.hxx"
      21             : #include <com/sun/star/frame/XModel.hpp>
      22             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      23             : #include <com/sun/star/util/MeasureUnit.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/document/XEventsSupplier.hpp>
      26             : #include <com/sun/star/container/XNameReplace.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/uno/Reference.hxx>
      29             : #include <com/sun/star/uno/Sequence.hxx>
      30             : #include <com/sun/star/uno/Exception.hpp>
      31             : #include <rtl/ustrbuf.hxx>
      32             : #include "xmloff/xmlnmspe.hxx"
      33             : #include <xmloff/nmspmap.hxx>
      34             : #include <xmloff/xmltoken.hxx>
      35             : #include <xmloff/XMLEventExport.hxx>
      36             : #include <tools/debug.hxx>
      37             : #include <tools/fldunit.hxx>
      38             : #include <comphelper/processfactory.hxx>
      39             : 
      40             : 
      41             : using namespace ::com::sun::star;
      42             : using namespace ::xmloff::token;
      43             : 
      44             : using ::std::set;
      45             : using ::com::sun::star::beans::XPropertySet;
      46             : using ::com::sun::star::beans::PropertyValue;
      47             : using ::com::sun::star::container::XNameAccess;
      48             : using ::com::sun::star::container::XNameReplace;
      49             : using ::com::sun::star::document::XEventsSupplier;
      50             : using ::com::sun::star::frame::XModel;
      51             : using ::com::sun::star::lang::XMultiServiceFactory;
      52             : using ::com::sun::star::uno::Any;
      53             : using ::com::sun::star::uno::Exception;
      54             : using ::com::sun::star::uno::Reference;
      55             : using ::com::sun::star::uno::Sequence;
      56             : using ::com::sun::star::uno::XInterface;
      57             : using ::com::sun::star::uno::UNO_QUERY;
      58             : using ::com::sun::star::xml::sax::XDocumentHandler;
      59             : 
      60             : 
      61           0 : XMLAutoTextEventExport::XMLAutoTextEventExport(
      62             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
      63             :         sal_uInt16 nFlags
      64             :     )
      65             : :   SvXMLExport(util::MeasureUnit::INCH, xContext, XML_AUTO_TEXT, nFlags)
      66             : ,
      67             :         sEventType("EventType"),
      68           0 :         sNone("None")
      69             : {
      70           0 : }
      71             : 
      72           0 : XMLAutoTextEventExport::~XMLAutoTextEventExport()
      73             : {
      74           0 : }
      75             : 
      76           0 : void XMLAutoTextEventExport::initialize(
      77             :     const Sequence<Any> & rArguments )
      78             :         throw(uno::Exception, uno::RuntimeException)
      79             : {
      80           0 :     if (rArguments.getLength() > 1)
      81             :     {
      82           0 :         Reference<XEventsSupplier> xSupplier;
      83           0 :         rArguments[1] >>= xSupplier;
      84           0 :         if (xSupplier.is())
      85             :         {
      86           0 :             Reference<XNameAccess> xAccess(xSupplier->getEvents(), UNO_QUERY);
      87           0 :             xEvents = xAccess;
      88             :         }
      89             :         else
      90             :         {
      91           0 :             Reference<XNameReplace> xReplace;
      92           0 :             rArguments[1] >>= xReplace;
      93           0 :             if (xReplace.is())
      94             :             {
      95           0 :                 xEvents = xReplace;
      96             :             }
      97             :             else
      98             :             {
      99           0 :                 rArguments[1] >>= xEvents;
     100           0 :             }
     101           0 :         }
     102             :     }
     103             : 
     104             :     // call super class (for XHandler)
     105           0 :     SvXMLExport::initialize(rArguments);
     106           0 : }
     107             : 
     108             : 
     109           0 : sal_uInt32 XMLAutoTextEventExport::exportDoc( enum XMLTokenEnum )
     110             : {
     111           0 :     if( (getExportFlags() & EXPORT_OASIS) == 0 )
     112             :     {
     113           0 :         Reference< uno::XComponentContext> xContext = getComponentContext();
     114             :         try
     115             :         {
     116             : 
     117           0 :             Sequence<Any> aArgs( 1 );
     118           0 :             aArgs[0] <<= GetDocHandler();
     119             : 
     120             :             // get filter component
     121             :             Reference< xml::sax::XDocumentHandler > xTmpDocHandler(
     122           0 :                 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
     123             :                     "com.sun.star.comp.Oasis2OOoTransformer",
     124             :                     aArgs,
     125           0 :                     xContext),
     126           0 :                 UNO_QUERY);
     127             :             OSL_ENSURE( xTmpDocHandler.is(),
     128             :                 "can't instantiate OASIS transformer component" );
     129           0 :             if( xTmpDocHandler.is() )
     130             :             {
     131           0 :                 SetDocHandler( xTmpDocHandler );
     132           0 :             }
     133             :         }
     134           0 :         catch( com::sun::star::uno::Exception& )
     135             :         {
     136           0 :         }
     137             :     }
     138           0 :     if (hasEvents())
     139             :     {
     140           0 :         GetDocHandler()->startDocument();
     141             : 
     142           0 :         addChaffWhenEncryptedStorage();
     143             : 
     144           0 :         addNamespaces();
     145             : 
     146             :         {
     147             :             // container element
     148             :             SvXMLElementExport aContainerElement(
     149             :                 *this, XML_NAMESPACE_OOO, XML_AUTO_TEXT_EVENTS,
     150           0 :                 sal_True, sal_True);
     151             : 
     152           0 :             exportEvents();
     153             :         }
     154             : 
     155             :         // and close document again
     156           0 :         GetDocHandler()->endDocument();
     157             :     }
     158             : 
     159           0 :     return 0;
     160             : }
     161             : 
     162           0 : sal_Bool XMLAutoTextEventExport::hasEvents()
     163             : {
     164             :     // TODO: provide full implementation that check for presence of events
     165           0 :     return xEvents.is();
     166             : }
     167             : 
     168           0 : void XMLAutoTextEventExport::addNamespaces()
     169             : {
     170             :     // namespaces for office:, text: and script:
     171           0 :     GetAttrList().AddAttribute(
     172           0 :         GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OFFICE ),
     173           0 :         GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OFFICE ) );
     174           0 :     GetAttrList().AddAttribute(
     175           0 :         GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_TEXT ),
     176           0 :         GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_TEXT ) );
     177           0 :     GetAttrList().AddAttribute(
     178           0 :         GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_SCRIPT ),
     179           0 :         GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_SCRIPT ) );
     180           0 :     GetAttrList().AddAttribute(
     181           0 :         GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_DOM ),
     182           0 :         GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_DOM ) );
     183           0 :     GetAttrList().AddAttribute(
     184           0 :         GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_OOO ),
     185           0 :         GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_OOO ) );
     186           0 :     GetAttrList().AddAttribute(
     187           0 :         GetNamespaceMap().GetAttrNameByIndex( XML_NAMESPACE_XLINK ),
     188           0 :         GetNamespaceMap().GetNameByIndex( XML_NAMESPACE_XLINK ) );
     189           0 : }
     190             : 
     191           0 : void XMLAutoTextEventExport::exportEvents()
     192             : {
     193             :     DBG_ASSERT(hasEvents(), "no events to export!");
     194             : 
     195           0 :     GetEventExport().Export(xEvents, sal_True);
     196           0 : }
     197             : 
     198             : 
     199             : 
     200             : // methods without content:
     201             : 
     202           0 : void XMLAutoTextEventExport::_ExportMeta() {}
     203           0 : void XMLAutoTextEventExport::_ExportScripts() {}
     204           0 : void XMLAutoTextEventExport::_ExportFontDecls() {}
     205           0 : void XMLAutoTextEventExport::_ExportStyles( sal_Bool ) {}
     206           0 : void XMLAutoTextEventExport::_ExportAutoStyles() {}
     207           0 : void XMLAutoTextEventExport::_ExportMasterStyles() {}
     208           0 : void XMLAutoTextEventExport::_ExportContent() {}
     209             : 
     210             : 
     211             : 
     212             : // methods to support the component registration
     213             : 
     214           0 : Sequence< OUString > SAL_CALL XMLAutoTextEventExport_getSupportedServiceNames()
     215             :     throw()
     216             : {
     217           0 :     Sequence< OUString > aSeq( 1 );
     218           0 :     aSeq[0] = XMLAutoTextEventExport_getImplementationName();
     219           0 :     return aSeq;
     220             : }
     221             : 
     222           0 : OUString SAL_CALL XMLAutoTextEventExport_getImplementationName() throw()
     223             : {
     224           0 :     return OUString( "com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter"  );
     225             : }
     226             : 
     227           0 : Reference< XInterface > SAL_CALL XMLAutoTextEventExport_createInstance(
     228             :         const Reference< XMultiServiceFactory > & rSMgr)
     229             :     throw( Exception )
     230             : {
     231           0 :     return (cppu::OWeakObject*)new XMLAutoTextEventExport( comphelper::getComponentContext(rSMgr), EXPORT_ALL|EXPORT_OASIS);
     232             : }
     233             : 
     234             : // methods to support the component registration
     235             : 
     236           0 : Sequence< OUString > SAL_CALL XMLAutoTextEventExportOOO_getSupportedServiceNames()
     237             :     throw()
     238             : {
     239           0 :     Sequence< OUString > aSeq( 1 );
     240           0 :     aSeq[0] = XMLAutoTextEventExportOOO_getImplementationName();
     241           0 :     return aSeq;
     242             : }
     243             : 
     244           0 : OUString SAL_CALL XMLAutoTextEventExportOOO_getImplementationName() throw()
     245             : {
     246           0 :     return OUString( "com.sun.star.comp.Writer.XMLAutotextEventsExporter"  );
     247             : }
     248             : 
     249           0 : Reference< XInterface > SAL_CALL XMLAutoTextEventExportOOO_createInstance(
     250             :         const Reference< XMultiServiceFactory > & rSMgr)
     251             :     throw( Exception )
     252             : {
     253           0 :     return (cppu::OWeakObject*)new XMLAutoTextEventExport( comphelper::getComponentContext(rSMgr),EXPORT_ALL);
     254             : }
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10