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

Generated by: LCOV version 1.11