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

Generated by: LCOV version 1.10