LCOV - code coverage report
Current view: top level - xmloff/source/meta - MetaExportComponent.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 47 85 55.3 %
Date: 2015-06-13 12:38:46 Functions: 9 15 60.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 "MetaExportComponent.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/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/uno/Reference.hxx>
      27             : #include <com/sun/star/uno/Exception.hpp>
      28             : #include <com/sun/star/util/MeasureUnit.hpp>
      29             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      30             : #include <comphelper/genericpropertyset.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <rtl/ustrbuf.hxx>
      33             : #include <xmloff/xmlnmspe.hxx>
      34             : #include <xmloff/nmspmap.hxx>
      35             : #include <xmloff/xmltoken.hxx>
      36             : #include <xmloff/xmlmetae.hxx>
      37             : #include "PropertySetMerger.hxx"
      38             : 
      39             : #include <unotools/docinfohelper.hxx>
      40             : 
      41             : 
      42             : using namespace ::com::sun::star;
      43             : using namespace ::xmloff::token;
      44             : 
      45           3 : XMLMetaExportComponent::XMLMetaExportComponent(
      46             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
      47             :     OUString const & implementationName, SvXMLExportFlags nFlags )
      48           3 : :   SvXMLExport( util::MeasureUnit::CM, xContext, implementationName, XML_TEXT, nFlags )
      49             : {
      50           3 : }
      51             : 
      52           6 : XMLMetaExportComponent::~XMLMetaExportComponent()
      53             : {
      54           6 : }
      55             : 
      56           3 : void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
      57             : {
      58             :     try
      59             :     {
      60           3 :         SvXMLExport::setSourceDocument( xDoc );
      61             :     }
      62           3 :     catch( lang::IllegalArgumentException& )
      63             :     {
      64             :         // allow to use document properties service without model access
      65             :         // this is required for document properties exporter
      66           6 :         mxDocProps =
      67           3 :             uno::Reference< document::XDocumentProperties >::query( xDoc );
      68           3 :         if( !mxDocProps.is() )
      69           0 :             throw lang::IllegalArgumentException();
      70             :     }
      71           3 : }
      72             : 
      73           3 : sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
      74             : {
      75           3 :     uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
      76             : 
      77           3 :     if( !(getExportFlags() & SvXMLExportFlags::OASIS) )
      78             :     {
      79           0 :         uno::Reference< uno::XComponentContext > xContext = getComponentContext();
      80             :         try
      81             :         {
      82             :             ::comphelper::PropertyMapEntry const aInfoMap[] =
      83             :             {
      84             :                 { OUString("Class"), 0,
      85           0 :                     ::cppu::UnoType<OUString>::get(),
      86             :                     beans::PropertyAttribute::MAYBEVOID, 0},
      87             :                 { OUString(), 0, css::uno::Type(), 0, 0 }
      88           0 :             };
      89             :             uno::Reference< beans::XPropertySet > xConvPropSet(
      90             :                 ::comphelper::GenericPropertySet_CreateInstance(
      91           0 :                         new ::comphelper::PropertySetInfo( aInfoMap ) ) );
      92             : 
      93           0 :             uno::Any aAny;
      94           0 :             aAny <<= GetXMLToken( XML_TEXT );
      95           0 :             xConvPropSet->setPropertyValue(
      96           0 :                     OUString("Class"), aAny );
      97             : 
      98             :             uno::Reference< beans::XPropertySet > xPropSet =
      99           0 :                 getExportInfo().is()
     100             :                     ?  PropertySetMerger_CreateInstance( getExportInfo(),
     101             :                                                       xConvPropSet )
     102           0 :                     : getExportInfo();
     103             : 
     104           0 :             uno::Sequence< uno::Any > aArgs( 3 );
     105           0 :             aArgs[0] <<= xDocHandler;
     106           0 :             aArgs[1] <<= xPropSet;
     107           0 :             aArgs[2] <<= GetModel();
     108             : 
     109             :             // get filter component
     110           0 :             xDocHandler = uno::Reference< xml::sax::XDocumentHandler >(
     111           0 :                 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
     112           0 :                     "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
     113           0 :                 uno::UNO_QUERY_THROW );
     114             : 
     115           0 :             SetDocHandler( xDocHandler );
     116             :         }
     117           0 :         catch( com::sun::star::uno::Exception& )
     118             :         {
     119             :             OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
     120           0 :         }
     121             :     }
     122             : 
     123             : 
     124           3 :     xDocHandler->startDocument();
     125             : 
     126           3 :     addChaffWhenEncryptedStorage();
     127             : 
     128             :     {
     129             : 
     130           3 :         const SvXMLNamespaceMap& rMap = GetNamespaceMap();
     131           3 :         sal_uInt16 nPos = rMap.GetFirstKey();
     132          24 :         while( USHRT_MAX != nPos )
     133             :         {
     134          18 :             GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
     135          18 :             nPos = GetNamespaceMap().GetNextKey( nPos );
     136             :         }
     137             : 
     138           3 :         const sal_Char* pVersion = 0;
     139           3 :         switch( getDefaultVersion() )
     140             :         {
     141           3 :         case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
     142           0 :         case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = "1.2"; break;
     143           0 :         case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
     144           0 :         case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
     145           0 :         case SvtSaveOptions::ODFVER_010: break;
     146             : 
     147             :         default:
     148             :             OSL_FAIL("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
     149             :         }
     150             : 
     151           3 :         if( pVersion )
     152             :             AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
     153           3 :                             OUString::createFromAscii(pVersion) );
     154             : 
     155             :         SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
     156           3 :                     true, true );
     157             : 
     158             :         // NB: office:meta is now written by _ExportMeta
     159           3 :         _ExportMeta();
     160             :     }
     161           3 :     xDocHandler->endDocument();
     162           3 :     return 0;
     163             : }
     164             : 
     165           3 : void XMLMetaExportComponent::_ExportMeta()
     166             : {
     167           3 :     if (mxDocProps.is()) {
     168           3 :         OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
     169             :         // update generator here
     170           3 :         mxDocProps->setGenerator(generator);
     171           3 :         SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
     172           6 :         uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
     173           6 :         pMeta->Export();
     174             :     } else {
     175           0 :         SvXMLExport::_ExportMeta();
     176             :     }
     177           3 : }
     178             : 
     179             : // methods without content:
     180           0 : void XMLMetaExportComponent::_ExportAutoStyles() {}
     181           0 : void XMLMetaExportComponent::_ExportMasterStyles() {}
     182           0 : void XMLMetaExportComponent::_ExportContent() {}
     183             : 
     184             : 
     185           1 : uno::Sequence< OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
     186             :     throw()
     187             : {
     188             :     const OUString aServiceName(
     189           1 :          "com.sun.star.document.XMLOasisMetaExporter"  );
     190           1 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     191           1 :     return aSeq;
     192             : }
     193             : 
     194           6 : OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
     195             : {
     196           6 :     return OUString(  "XMLMetaExportComponent"  );
     197             : }
     198             : 
     199           3 : uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
     200             :         const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
     201             :     throw( uno::Exception )
     202             : {
     203           3 :     return static_cast<cppu::OWeakObject*>(new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), XMLMetaExportComponent_getImplementationName(), SvXMLExportFlags::META|SvXMLExportFlags::OASIS));
     204             : }
     205             : 
     206           0 : uno::Sequence< OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
     207             :     throw()
     208             : {
     209             :     const OUString aServiceName(
     210           0 :          "com.sun.star.document.XMLMetaExporter"  );
     211           0 :     const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
     212           0 :     return aSeq;
     213             : }
     214             : 
     215           0 : OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
     216             : {
     217           0 :     return OUString(  "XMLMetaExportOOo"  );
     218             : }
     219             : 
     220           0 : uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
     221             :         const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
     222             :     throw( uno::Exception )
     223             : {
     224           0 :     return static_cast<cppu::OWeakObject*>(new XMLMetaExportComponent( comphelper::getComponentContext(rSMgr), XMLMetaExportOOO_getImplementationName(), SvXMLExportFlags::META));
     225             : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11