LCOV - code coverage report
Current view: top level - xmloff/source/meta - MetaExportComponent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 84 54.8 %
Date: 2012-08-25 Functions: 9 15 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 142 25.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "MetaExportComponent.hxx"
      30                 :            : #include <com/sun/star/frame/XModel.hpp>
      31                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      32                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      33                 :            : #include <com/sun/star/uno/Sequence.hxx>
      34                 :            : #include <com/sun/star/uno/Reference.hxx>
      35                 :            : #include <com/sun/star/uno/Exception.hpp>
      36                 :            : #include <com/sun/star/util/MeasureUnit.hpp>
      37                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      38                 :            : #include <comphelper/genericpropertyset.hxx>
      39                 :            : #include <rtl/ustrbuf.hxx>
      40                 :            : #include "xmloff/xmlnmspe.hxx"
      41                 :            : #include <xmloff/nmspmap.hxx>
      42                 :            : #include <xmloff/xmltoken.hxx>
      43                 :            : #include <xmloff/xmlmetae.hxx>
      44                 :            : #include "PropertySetMerger.hxx"
      45                 :            : 
      46                 :            : #include <unotools/docinfohelper.hxx>
      47                 :            : 
      48                 :            : 
      49                 :            : using namespace ::com::sun::star;
      50                 :            : using namespace ::xmloff::token;
      51                 :            : 
      52                 :          6 : XMLMetaExportComponent::XMLMetaExportComponent(
      53                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
      54                 :            :         sal_uInt16 nFlags )
      55                 :          6 : :   SvXMLExport( util::MeasureUnit::CM, xServiceFactory, XML_TEXT, nFlags )
      56                 :            : {
      57                 :          6 : }
      58                 :            : 
      59                 :          6 : XMLMetaExportComponent::~XMLMetaExportComponent()
      60                 :            : {
      61         [ -  + ]:         12 : }
      62                 :            : 
      63                 :          6 : 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)
      64                 :            : {
      65                 :            :     try
      66                 :            :     {
      67         [ -  + ]:          6 :         SvXMLExport::setSourceDocument( xDoc );
      68                 :            :     }
      69         [ -  + ]:         12 :     catch( lang::IllegalArgumentException& )
      70                 :            :     {
      71                 :            :         // allow to use document properties service without model access
      72                 :            :         // this is required for document properties exporter
      73                 :            :         mxDocProps =
      74 [ -  + ][ -  + ]:          6 :             uno::Reference< document::XDocumentProperties >::query( xDoc );
      75         [ -  + ]:          6 :         if( !mxDocProps.is() )
      76         [ #  # ]:          0 :             throw lang::IllegalArgumentException();
      77                 :            :     }
      78                 :          6 : }
      79                 :            : 
      80                 :          6 : sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
      81                 :            : {
      82                 :          6 :     uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
      83                 :            : 
      84         [ -  + ]:          6 :     if( (getExportFlags() & EXPORT_OASIS) == 0 )
      85                 :            :     {
      86         [ #  # ]:          0 :         uno::Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory();
      87         [ #  # ]:          0 :         if( xFactory.is() )
      88                 :            :         {
      89                 :            :             try
      90                 :            :             {
      91                 :            :                 ::comphelper::PropertyMapEntry aInfoMap[] =
      92                 :            :                 {
      93                 :            :                     { "Class", sizeof("Class")-1, 0,
      94         [ #  # ]:          0 :                         &::getCppuType((::rtl::OUString*)0),
      95                 :            :                         beans::PropertyAttribute::MAYBEVOID, 0},
      96                 :            :                     { NULL, 0, 0, NULL, 0, 0 }
      97                 :          0 :                 };
      98                 :            :                 uno::Reference< beans::XPropertySet > xConvPropSet(
      99                 :            :                     ::comphelper::GenericPropertySet_CreateInstance(
     100         [ #  # ]:          0 :                             new ::comphelper::PropertySetInfo( aInfoMap ) ) );
     101                 :            : 
     102                 :          0 :                 uno::Any aAny;
     103 [ #  # ][ #  # ]:          0 :                 aAny <<= GetXMLToken( XML_TEXT );
     104         [ #  # ]:          0 :                 xConvPropSet->setPropertyValue(
     105         [ #  # ]:          0 :                         ::rtl::OUString("Class"), aAny );
     106                 :            : 
     107                 :            :                 uno::Reference< beans::XPropertySet > xPropSet =
     108         [ #  # ]:          0 :                     getExportInfo().is()
     109                 :            :                         ?  PropertySetMerger_CreateInstance( getExportInfo(),
     110                 :            :                                                           xConvPropSet )
     111 [ #  # ][ #  # ]:          0 :                         : getExportInfo();
         [ #  # ][ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     112                 :            : 
     113         [ #  # ]:          0 :                 uno::Sequence< uno::Any > aArgs( 3 );
     114 [ #  # ][ #  # ]:          0 :                 aArgs[0] <<= xDocHandler;
     115 [ #  # ][ #  # ]:          0 :                 aArgs[1] <<= xPropSet;
     116 [ #  # ][ #  # ]:          0 :                 aArgs[2] <<= GetModel();
     117                 :            : 
     118                 :            :                 // get filter component
     119                 :            :                 xDocHandler = uno::Reference< xml::sax::XDocumentHandler >(
     120         [ #  # ]:          0 :                     xFactory->createInstanceWithArguments(
     121                 :            :                         ::rtl::OUString("com.sun.star.comp.Oasis2OOoTransformer"),
     122                 :          0 :                         aArgs),
     123 [ #  # ][ #  # ]:          0 :                     uno::UNO_QUERY_THROW );
                 [ #  # ]
     124                 :            : 
     125 [ #  # ][ #  # ]:          0 :                 SetDocHandler( xDocHandler );
                 [ #  # ]
     126                 :            :             }
     127         [ #  # ]:          0 :             catch( com::sun::star::uno::Exception& )
     128                 :            :             {
     129                 :            :                 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
     130                 :            :             }
     131                 :          0 :         }
     132                 :            :     }
     133                 :            : 
     134                 :            : 
     135 [ +  - ][ +  - ]:          6 :     xDocHandler->startDocument();
     136                 :            : 
     137         [ +  - ]:          6 :     addChaffWhenEncryptedStorage();
     138                 :            : 
     139                 :            :     {
     140                 :            : 
     141                 :          6 :         const SvXMLNamespaceMap& rMap = GetNamespaceMap();
     142         [ +  - ]:          6 :         sal_uInt16 nPos = rMap.GetFirstKey();
     143         [ +  + ]:         42 :         while( USHRT_MAX != nPos )
     144                 :            :         {
     145 [ +  - ][ +  - ]:         36 :             GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
                 [ +  - ]
     146         [ +  - ]:         36 :             nPos = GetNamespaceMap().GetNextKey( nPos );
     147                 :            :         }
     148                 :            : 
     149                 :          6 :         const sal_Char* pVersion = 0;
     150 [ +  - ][ +  -  :          6 :         switch( getDefaultVersion() )
             -  -  -  - ]
     151                 :            :         {
     152                 :          6 :         case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
     153                 :          0 :         case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = "1.2"; break;
     154                 :          0 :         case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
     155                 :          0 :         case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
     156                 :          0 :         case SvtSaveOptions::ODFVER_010: break;
     157                 :            : 
     158                 :            :         default:
     159                 :            :             OSL_FAIL("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
     160                 :            :         }
     161                 :            : 
     162         [ +  - ]:          6 :         if( pVersion )
     163                 :            :             AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
     164         [ +  - ]:          6 :                             ::rtl::OUString::createFromAscii(pVersion) );
     165                 :            : 
     166                 :            :             SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
     167         [ +  - ]:          6 :                         sal_True, sal_True );
     168                 :            : 
     169                 :            :         // NB: office:meta is now written by _ExportMeta
     170 [ +  - ][ +  - ]:          6 :         _ExportMeta();
     171                 :            :     }
     172 [ +  - ][ +  - ]:          6 :     xDocHandler->endDocument();
     173                 :          6 :     return 0;
     174                 :            : }
     175                 :            : 
     176                 :          6 : void XMLMetaExportComponent::_ExportMeta()
     177                 :            : {
     178         [ +  - ]:          6 :     if (mxDocProps.is()) {
     179         [ +  - ]:          6 :         ::rtl::OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
     180                 :            :         // update generator here
     181 [ +  - ][ +  - ]:          6 :         mxDocProps->setGenerator(generator);
     182         [ +  - ]:          6 :         SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
     183 [ +  - ][ +  - ]:          6 :         uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
     184         [ +  - ]:          6 :         pMeta->Export();
     185                 :            :     } else {
     186                 :          0 :         SvXMLExport::_ExportMeta();
     187                 :            :     }
     188                 :          6 : }
     189                 :            : 
     190                 :            : // methods without content:
     191                 :          0 : void XMLMetaExportComponent::_ExportAutoStyles() {}
     192                 :          0 : void XMLMetaExportComponent::_ExportMasterStyles() {}
     193                 :          0 : void XMLMetaExportComponent::_ExportContent() {}
     194                 :            : 
     195                 :            : 
     196                 :          2 : uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
     197                 :            :     throw()
     198                 :            : {
     199                 :            :     const rtl::OUString aServiceName(
     200                 :          2 :          "com.sun.star.document.XMLOasisMetaExporter"  );
     201         [ +  - ]:          2 :     const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
     202                 :          2 :     return aSeq;
     203                 :            : }
     204                 :            : 
     205                 :         38 : rtl::OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
     206                 :            : {
     207                 :         38 :     return rtl::OUString(  "XMLMetaExportComponent"  );
     208                 :            : }
     209                 :            : 
     210                 :          6 : uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
     211                 :            :         const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
     212                 :            :     throw( uno::Exception )
     213                 :            : {
     214         [ +  - ]:          6 :     return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META|EXPORT_OASIS);
     215                 :            : }
     216                 :            : 
     217                 :          0 : uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
     218                 :            :     throw()
     219                 :            : {
     220                 :            :     const rtl::OUString aServiceName(
     221                 :          0 :          "com.sun.star.document.XMLMetaExporter"  );
     222         [ #  # ]:          0 :     const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
     223                 :          0 :     return aSeq;
     224                 :            : }
     225                 :            : 
     226                 :          0 : rtl::OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
     227                 :            : {
     228                 :          0 :     return rtl::OUString(  "XMLMetaExportOOo"  );
     229                 :            : }
     230                 :            : 
     231                 :          0 : uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
     232                 :            :         const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
     233                 :            :     throw( uno::Exception )
     234                 :            : {
     235         [ #  # ]:          0 :     return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META);
     236                 :            : }
     237                 :            : 
     238                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10