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

Generated by: LCOV version 1.10