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

Generated by: LCOV version 1.10