LCOV - code coverage report
Current view: top level - sw/source/filter/xml - wrtxml.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 220 269 81.8 %
Date: 2012-08-25 Functions: 10 10 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 255 615 41.5 %

           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                 :            : 
      30                 :            : #include <com/sun/star/embed/XStorage.hpp>
      31                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      32                 :            : #include <com/sun/star/container/XIndexContainer.hpp>
      33                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      34                 :            : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
      35                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      36                 :            : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      37                 :            : #include <com/sun/star/document/XExporter.hpp>
      38                 :            : #include <com/sun/star/document/XFilter.hpp>
      39                 :            : #include <com/sun/star/frame/XModule.hpp>
      40                 :            : #include <comphelper/processfactory.hxx>
      41                 :            : #include <comphelper/genericpropertyset.hxx>
      42                 :            : #include <unotools/streamwrap.hxx>
      43                 :            : #include <svx/xmlgrhlp.hxx>
      44                 :            : #include <svx/xmleohlp.hxx>
      45                 :            : #include <unotools/saveopt.hxx>
      46                 :            : #include <svl/stritem.hxx>
      47                 :            : #include <sfx2/frame.hxx>
      48                 :            : #include <sfx2/docfile.hxx>
      49                 :            : #include <pam.hxx>
      50                 :            : #include <doc.hxx>
      51                 :            : #include <docstat.hxx>
      52                 :            : #include <docsh.hxx>
      53                 :            : 
      54                 :            : #include <unotools/ucbstreamhelper.hxx>
      55                 :            : #include <swerror.h>
      56                 :            : #include <wrtxml.hxx>
      57                 :            : #include <statstr.hrc>
      58                 :            : #include <rtl/logfile.hxx>
      59                 :            : 
      60                 :            : #include <comphelper/documentconstants.hxx>
      61                 :            : #include <comphelper/makesequence.hxx>
      62                 :            : #include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
      63                 :            : 
      64                 :            : using ::rtl::OUString;
      65                 :            : using namespace ::com::sun::star;
      66                 :            : using namespace ::com::sun::star::uno;
      67                 :            : using namespace ::com::sun::star::container;
      68                 :            : using namespace ::com::sun::star::document;
      69                 :            : using namespace ::com::sun::star::beans;
      70                 :            : using namespace ::com::sun::star::lang;
      71                 :            : 
      72                 :            : #define LOGFILE_AUTHOR "mb93740"
      73                 :            : 
      74                 :         21 : SwXMLWriter::SwXMLWriter( const String& rBaseURL )
      75                 :            : {
      76         [ +  - ]:         21 :     SetBaseURL( rBaseURL );
      77                 :         21 : }
      78                 :            : 
      79                 :            : 
      80                 :         21 : SwXMLWriter::~SwXMLWriter()
      81                 :            : {
      82         [ -  + ]:         42 : }
      83                 :            : 
      84                 :            : 
      85                 :         21 : sal_uInt32 SwXMLWriter::_Write( SfxMedium* pTargetMedium )
      86                 :            : {
      87                 :            :     OSL_ENSURE( pTargetMedium, "No medium is provided!" );
      88                 :            :     // Get service factory
      89                 :            :     uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
      90         [ +  - ]:         21 :             comphelper::getProcessServiceFactory();
      91                 :            :     OSL_ENSURE( xServiceFactory.is(),
      92                 :            :             "SwXMLWriter::Write: got no service manager" );
      93         [ -  + ]:         21 :     if( !xServiceFactory.is() )
      94                 :          0 :         return ERR_SWG_WRITE_ERROR;
      95                 :            : 
      96                 :            :     // Get data sink ...
      97                 :         21 :     uno::Reference< io::XOutputStream > xOut;
      98                 :         21 :     SvStorageStreamRef xDocStream;
      99                 :         21 :     uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
     100                 :         21 :     SvXMLGraphicHelper *pGraphicHelper = 0;
     101                 :         21 :     uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
     102                 :         21 :     SvXMLEmbeddedObjectHelper *pObjectHelper = 0;
     103                 :            : 
     104                 :            :     OSL_ENSURE( xStg.is(), "Where is my storage?" );
     105                 :            : pGraphicHelper = SvXMLGraphicHelper::Create( xStg,
     106                 :            :                                                  GRAPHICHELPER_MODE_WRITE,
     107         [ +  - ]:         21 :                                                  sal_False );
     108 [ +  - ][ +  - ]:         21 :     xGraphicResolver = pGraphicHelper;
     109                 :            : 
     110         [ +  - ]:         21 :     SfxObjectShell *pPersist = pDoc->GetPersist();
     111         [ +  - ]:         21 :     if( pPersist )
     112                 :            :     {
     113                 :            :         pObjectHelper = SvXMLEmbeddedObjectHelper::Create(
     114                 :            :                                          xStg, *pPersist,
     115                 :            :                                          EMBEDDEDOBJECTHELPER_MODE_WRITE,
     116         [ +  - ]:         21 :                                          sal_False );
     117 [ +  - ][ +  - ]:         21 :         xObjectResolver = pObjectHelper;
     118                 :            :     }
     119                 :            : 
     120                 :            :     // create and prepare the XPropertySet that gets passed through
     121                 :            :     // the components, and the XStatusIndicator that shows progress to
     122                 :            :     // the user.
     123                 :            : 
     124                 :            :     // create XPropertySet with three properties for status indicator
     125                 :            :     comphelper::PropertyMapEntry aInfoMap[] =
     126                 :            :     {
     127                 :            :         { "ProgressRange", sizeof("ProgressRange")-1, 0,
     128         [ +  - ]:         21 :               &::getCppuType((sal_Int32*)0),
     129                 :            :               beans::PropertyAttribute::MAYBEVOID, 0},
     130                 :            :         { "ProgressMax", sizeof("ProgressMax")-1, 0,
     131         [ +  - ]:         21 :               &::getCppuType((sal_Int32*)0),
     132                 :            :               beans::PropertyAttribute::MAYBEVOID, 0},
     133                 :            :         { "ProgressCurrent", sizeof("ProgressCurrent")-1, 0,
     134         [ +  - ]:         21 :               &::getCppuType((sal_Int32*)0),
     135                 :            :               beans::PropertyAttribute::MAYBEVOID, 0},
     136                 :            :         { "WrittenNumberStyles", sizeof("WrittenNumberStyles")-1, 0,
     137         [ +  - ]:         21 :               &::getCppuType((uno::Sequence<sal_Int32> *)0),
     138                 :            :               beans::PropertyAttribute::MAYBEVOID, 0},
     139                 :            :         { "UsePrettyPrinting", sizeof("UsePrettyPrinting")-1, 0,
     140         [ +  - ]:         21 :               &::getBooleanCppuType(),
     141                 :            :               beans::PropertyAttribute::MAYBEVOID, 0},
     142                 :            :         { "ShowChanges", sizeof("ShowChanges")-1, 0,
     143         [ +  - ]:         21 :               &::getBooleanCppuType(),
     144                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     145                 :            :         { "RedlineProtectionKey", sizeof("RedlineProtectionKey")-1, 0,
     146                 :            : #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
     147                 :            :               new uno::Type(::getCppuType((Sequence<sal_Int8>*)0)),
     148                 :            : #else
     149         [ +  - ]:         21 :               &::getCppuType((Sequence<sal_Int8>*)0),
     150                 :            : #endif
     151                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     152                 :            :         { "BaseURI", sizeof("BaseURI")-1, 0,
     153         [ +  - ]:         21 :               &::getCppuType( (OUString *)0 ),
     154                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     155                 :            :         { "StreamRelPath", sizeof("StreamRelPath")-1, 0,
     156         [ +  - ]:         21 :               &::getCppuType( (OUString *)0 ),
     157                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     158                 :            :         { "StreamName", sizeof("StreamName")-1, 0,
     159         [ +  - ]:         21 :               &::getCppuType( (OUString *)0 ),
     160                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     161                 :            :         { "AutoTextMode", sizeof("AutoTextMode")-1, 0,
     162         [ +  - ]:         21 :               &::getBooleanCppuType(),
     163                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     164                 :            :         { "StyleNames", sizeof("StyleNames")-1, 0,
     165         [ +  - ]:         21 :               &::getCppuType( (Sequence<OUString>*)0 ),
     166                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     167                 :            :         { "StyleFamilies", sizeof("StyleFamilies")-1, 0,
     168         [ +  - ]:         21 :               &::getCppuType( (Sequence<sal_Int32>*)0 ),
     169                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     170                 :            :         // #i69627#
     171                 :            :         { "OutlineStyleAsNormalListStyle", sizeof("OutlineStyleAsNormalListStyle")-1, 0,
     172         [ +  - ]:         21 :               &::getBooleanCppuType(),
     173                 :            :               beans::PropertyAttribute::MAYBEVOID, 0 },
     174         [ +  - ]:         21 :         { "TargetStorage", sizeof("TargetStorage")-1,0, &embed::XStorage::static_type(),
     175                 :            :               ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
     176                 :            : 
     177                 :            :         { NULL, 0, 0, NULL, 0, 0 }
     178                 :        336 :     };
     179                 :            :     uno::Reference< beans::XPropertySet > xInfoSet(
     180                 :            :                 comphelper::GenericPropertySet_CreateInstance(
     181         [ +  - ]:         21 :                             new comphelper::PropertySetInfo( aInfoMap ) ) );
     182                 :            : 
     183         [ +  - ]:         21 :     const OUString sTargetStorage( RTL_CONSTASCII_USTRINGPARAM("TargetStorage") );
     184 [ +  - ][ +  - ]:         21 :     xInfoSet->setPropertyValue( sTargetStorage, Any( xStg ) );
                 [ +  - ]
     185                 :            : 
     186                 :            :     // create XStatusIndicator
     187                 :         21 :     uno::Reference<task::XStatusIndicator> xStatusIndicator;
     188                 :            : 
     189                 :         21 :     uno::Any aAny;
     190         [ +  - ]:         21 :     if (bShowProgress)
     191                 :            :     {
     192                 :            :         // retrieve status indicator from the medium MediaDescriptor
     193         [ +  + ]:         21 :         if ( pTargetMedium )
     194                 :            :         {
     195                 :            :             const SfxUnoAnyItem* pStatusBarItem = static_cast<const SfxUnoAnyItem*>(
     196 [ +  - ][ +  - ]:         19 :                pTargetMedium->GetItemSet()->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
     197                 :            : 
     198         [ -  + ]:         19 :             if ( pStatusBarItem )
     199         [ #  # ]:          0 :                 pStatusBarItem->GetValue() >>= xStatusIndicator;
     200                 :            :         }
     201                 :            : 
     202                 :            :         // set progress range and start status indicator
     203                 :         21 :         sal_Int32 nProgressRange(1000000);
     204         [ -  + ]:         21 :         if (xStatusIndicator.is())
     205                 :            :         {
     206         [ #  # ]:          0 :             xStatusIndicator->start(SW_RESSTR( STR_STATSTR_SWGWRITE),
     207 [ #  # ][ #  # ]:          0 :                                     nProgressRange);
     208                 :            :         }
     209         [ +  - ]:         21 :         aAny <<= nProgressRange;
     210         [ +  - ]:         21 :         OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM("ProgressRange"));
     211 [ +  - ][ +  - ]:         21 :         xInfoSet->setPropertyValue(sProgressRange, aAny);
     212                 :            : 
     213         [ +  - ]:         21 :         aAny <<= static_cast < sal_Int32 >( -1 );
     214         [ +  - ]:         21 :         OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM("ProgressMax"));
     215 [ +  - ][ +  - ]:         21 :         xInfoSet->setPropertyValue(sProgressMax, aAny);
     216                 :            :     }
     217         [ +  - ]:         21 :     SvtSaveOptions aSaveOpt;
     218         [ +  - ]:         21 :     OUString sUsePrettyPrinting(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting"));
     219         [ +  - ]:         21 :     sal_Bool bUsePrettyPrinting( aSaveOpt.IsPrettyPrinting() );
     220         [ +  - ]:         21 :     aAny.setValue( &bUsePrettyPrinting, ::getBooleanCppuType() );
     221 [ +  - ][ +  - ]:         21 :     xInfoSet->setPropertyValue( sUsePrettyPrinting, aAny );
     222                 :            : 
     223                 :            :     // save show redline mode ...
     224         [ +  - ]:         21 :     OUString sShowChanges(RTL_CONSTASCII_USTRINGPARAM("ShowChanges"));
     225         [ +  - ]:         21 :     sal_uInt16 nRedlineMode = pDoc->GetRedlineMode();
     226                 :         21 :     sal_Bool bShowChanges( IDocumentRedlineAccess::IsShowChanges( nRedlineMode ) );
     227         [ +  - ]:         21 :     aAny.setValue( &bShowChanges, ::getBooleanCppuType() );
     228 [ +  - ][ +  - ]:         21 :     xInfoSet->setPropertyValue( sShowChanges, aAny );
     229                 :            :     // ... and hide redlines for export
     230                 :         21 :     nRedlineMode &= ~nsRedlineMode_t::REDLINE_SHOW_MASK;
     231                 :         21 :     nRedlineMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
     232         [ +  - ]:         21 :     pDoc->SetRedlineMode((RedlineMode_t)( nRedlineMode ));
     233                 :            : 
     234                 :            :     // Set base URI
     235         [ +  - ]:         21 :     OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
     236 [ +  - ][ +  - ]:         21 :     xInfoSet->setPropertyValue( sPropName, makeAny( ::rtl::OUString( GetBaseURL() ) ) );
         [ +  - ][ +  - ]
     237                 :            : 
     238         [ -  + ]:         21 :     if( SFX_CREATE_MODE_EMBEDDED == pDoc->GetDocShell()->GetCreateMode() )
     239                 :            :     {
     240                 :          0 :         OUString aName;
     241 [ #  # ][ #  # ]:          0 :         if ( pTargetMedium && pTargetMedium->GetItemSet() )
         [ #  # ][ #  # ]
     242                 :            :         {
     243                 :            :             const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
     244 [ #  # ][ #  # ]:          0 :                 pTargetMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
     245         [ #  # ]:          0 :             if ( pDocHierarchItem )
     246         [ #  # ]:          0 :                 aName = pDocHierarchItem->GetValue();
     247                 :            :         }
     248                 :            :         else
     249         [ #  # ]:          0 :             aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummyObjectName" ) );
     250                 :            : 
     251         [ #  # ]:          0 :         if( !aName.isEmpty() )
     252                 :            :         {
     253         [ #  # ]:          0 :             sPropName = OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
     254 [ #  # ][ #  # ]:          0 :             xInfoSet->setPropertyValue( sPropName, makeAny( aName ) );
                 [ #  # ]
     255                 :          0 :         }
     256                 :            :     }
     257                 :            : 
     258         [ +  + ]:         21 :     if( bBlock )
     259                 :            :     {
     260                 :            :         OUString sAutoTextMode(
     261         [ +  - ]:          2 :                 RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
     262                 :          2 :         sal_Bool bTmp = sal_True;
     263                 :          2 :         Any aAny2;
     264         [ +  - ]:          2 :         aAny2.setValue( &bTmp, ::getBooleanCppuType() );
     265 [ +  - ][ +  - ]:          2 :         xInfoSet->setPropertyValue( sAutoTextMode, aAny2 );
     266                 :            :     }
     267                 :            : 
     268                 :            :     // #i69627#
     269         [ +  - ]:         21 :     const sal_Bool bOASIS = ( SotStorage::GetVersion( xStg ) > SOFFICE_FILEFORMAT_60 );
     270 [ +  + ][ -  + ]:         38 :     if ( bOASIS &&
                 [ -  + ]
     271         [ +  - ]:         17 :          docfunc::HasOutlineStyleToBeWrittenAsNormalListStyle( *pDoc ) )
     272                 :            :     {
     273                 :            :         OUString sOutlineStyleAsNormalListStyle(
     274         [ #  # ]:          0 :                 RTL_CONSTASCII_USTRINGPARAM("OutlineStyleAsNormalListStyle") );
     275 [ #  # ][ #  # ]:          0 :         xInfoSet->setPropertyValue( sOutlineStyleAsNormalListStyle, makeAny( sal_True ) );
                 [ #  # ]
     276                 :            :     }
     277                 :            : 
     278                 :            :     // filter arguments
     279                 :            :     // - graphics + object resolver for styles + content
     280                 :            :     // - status indicator
     281                 :            :     // - info property set
     282                 :            :     // - else empty
     283                 :         21 :     sal_Int32 nArgs = 1;
     284         [ -  + ]:         21 :     if( xStatusIndicator.is() )
     285                 :          0 :         nArgs++;
     286                 :            : 
     287         [ +  - ]:         21 :     Sequence < Any > aEmptyArgs( nArgs );
     288         [ +  - ]:         21 :     Any *pArgs = aEmptyArgs.getArray();
     289         [ +  - ]:         21 :     *pArgs++ <<= xInfoSet;
     290         [ -  + ]:         21 :     if( xStatusIndicator.is() )
     291         [ #  # ]:          0 :         *pArgs++ <<= xStatusIndicator;
     292                 :            : 
     293         [ +  - ]:         21 :     if( xGraphicResolver.is() )
     294                 :         21 :         nArgs++;
     295         [ +  - ]:         21 :     if( xObjectResolver.is() )
     296                 :         21 :         nArgs++;
     297                 :            : 
     298         [ +  - ]:         21 :     Sequence < Any > aFilterArgs( nArgs );
     299         [ +  - ]:         21 :     pArgs = aFilterArgs.getArray();
     300         [ +  - ]:         21 :     *pArgs++ <<= xInfoSet;
     301         [ +  - ]:         21 :     if( xGraphicResolver.is() )
     302         [ +  - ]:         21 :         *pArgs++ <<= xGraphicResolver;
     303         [ +  - ]:         21 :     if( xObjectResolver.is() )
     304         [ +  - ]:         21 :         *pArgs++ <<= xObjectResolver;
     305         [ -  + ]:         21 :     if( xStatusIndicator.is() )
     306         [ #  # ]:          0 :         *pArgs++ <<= xStatusIndicator;
     307                 :            : 
     308                 :            :     //Get model
     309                 :            :     uno::Reference< lang::XComponent > xModelComp(
     310 [ +  - ][ +  - ]:         21 :         pDoc->GetDocShell()->GetModel(), UNO_QUERY );
     311                 :            :     OSL_ENSURE( xModelComp.is(), "XMLWriter::Write: got no model" );
     312         [ -  + ]:         21 :     if( !xModelComp.is() )
     313                 :          0 :         return ERR_SWG_WRITE_ERROR;
     314                 :            : 
     315         [ +  - ]:         21 :     PutNumFmtFontsInAttrPool();
     316         [ +  - ]:         21 :     PutEditEngFontsInAttrPool();
     317                 :            : 
     318                 :            :     // properties
     319 [ -  + ][ +  - ]:         21 :     Sequence < PropertyValue > aProps( pOrigFileName ? 1 : 0 );
     320         [ -  + ]:         21 :     if( pOrigFileName )
     321                 :            :     {
     322         [ #  # ]:          0 :         PropertyValue *pProps = aProps.getArray();
     323         [ #  # ]:          0 :         pProps->Name = OUString( RTL_CONSTASCII_USTRINGPARAM("FileName") );
     324 [ #  # ][ #  # ]:          0 :         (pProps++)->Value <<= OUString( *pOrigFileName  );
     325                 :            :     }
     326                 :            : 
     327                 :            :     // export sub streams for package, else full stream into a file
     328                 :         21 :     sal_Bool bWarn = sal_False, bErr = sal_False;
     329 [ +  - ][ +  - ]:         21 :     String sWarnFile, sErrFile;
     330                 :            : 
     331                 :            :     // RDF metadata: export if ODF >= 1.2
     332                 :            :     // N.B.: embedded documents have their own manifest.rdf!
     333         [ +  + ]:         21 :     if ( bOASIS )
     334                 :            :     {
     335                 :            :         const uno::Reference<beans::XPropertySet> xPropSet(xStg,
     336         [ +  - ]:         17 :             uno::UNO_QUERY_THROW);
     337         [ +  - ]:         17 :         const ::rtl::OUString VersionProp(RTL_CONSTASCII_USTRINGPARAM("Version"));
     338                 :            :         try
     339                 :            :         {
     340                 :         17 :             ::rtl::OUString Version;
     341                 :            :             // ODF >= 1.2
     342 [ +  - ][ +  -  :         68 :             if ((xPropSet->getPropertyValue(VersionProp) >>= Version)
             +  -  +  - ]
                 [ +  - ]
           [ +  -  #  # ]
                 [ +  - ]
     343 [ +  - ][ +  - ]:         34 :                 && !Version.equals(ODFVER_010_TEXT)
                 [ #  # ]
     344 [ +  - ][ +  - ]:         34 :                 && !Version.equals(ODFVER_011_TEXT))
                 [ #  # ]
     345                 :            :             {
     346                 :            :                 const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
     347         [ +  - ]:         17 :                     xModelComp, uno::UNO_QUERY_THROW);
     348 [ +  - ][ +  + ]:         17 :                 xDMA->storeMetadataToStorage(xStg);
     349      [ -  -  + ]:         17 :             }
     350                 :            :         }
     351         [ #  # ]:          0 :         catch (beans::UnknownPropertyException &)
     352                 :            :         { /* ignore */ }
     353         [ +  - ]:          3 :         catch (uno::Exception &)
     354                 :            :         {
     355                 :          3 :             bWarn = sal_True;
     356                 :         17 :         }
     357                 :            :     }
     358                 :            : 
     359                 :         21 :     sal_Bool bStoreMeta = ( SFX_CREATE_MODE_EMBEDDED != pDoc->GetDocShell()->GetCreateMode() );
     360         [ -  + ]:         21 :     if ( !bStoreMeta )
     361                 :            :     {
     362                 :            :         try
     363                 :            :         {
     364         [ #  # ]:          0 :             Reference< frame::XModule > xModule( xModelComp, UNO_QUERY );
     365         [ #  # ]:          0 :             if ( xModule.is() )
     366                 :            :             {
     367 [ #  # ][ #  # ]:          0 :                 ::rtl::OUString aModuleID = xModule->getIdentifier();
     368 [ #  # ][ #  # ]:          0 :                 bStoreMeta = ( !aModuleID.isEmpty() && ( aModuleID == "com.sun.star.sdb.FormDesign" || aModuleID == "com.sun.star.sdb.TextReportDesign" ) );
                 [ #  # ]
     369         [ #  # ]:          0 :             }
     370                 :            :         }
     371         [ #  # ]:          0 :         catch( uno::Exception& )
     372                 :            :         {}
     373                 :            :     }
     374                 :            : 
     375 [ +  - ][ +  + ]:         21 :     if( !bOrganizerMode && !bBlock && bStoreMeta )
                 [ +  - ]
     376                 :            :     {
     377         [ -  + ]:         19 :         if( !WriteThroughComponent(
     378                 :            :                 xModelComp, "meta.xml", xServiceFactory,
     379                 :            :                 (bOASIS ? "com.sun.star.comp.Writer.XMLOasisMetaExporter"
     380                 :            :                         : "com.sun.star.comp.Writer.XMLMetaExporter"),
     381 [ +  + ][ +  - ]:         19 :                 aEmptyArgs, aProps, sal_True ) )
     382                 :            :         {
     383                 :          0 :             bWarn = sal_True;
     384                 :            :             sWarnFile = String( RTL_CONSTASCII_STRINGPARAM("meta.xml"),
     385 [ #  # ][ #  # ]:          0 :                                 RTL_TEXTENCODING_ASCII_US );
                 [ #  # ]
     386                 :            :         }
     387                 :            :     }
     388                 :            : 
     389         [ +  - ]:         21 :     if( !bErr )
     390                 :            :     {
     391         [ +  + ]:         21 :         if( !bBlock )
     392                 :            :         {
     393         [ -  + ]:         19 :             if( !WriteThroughComponent(
     394                 :            :                 xModelComp, "settings.xml", xServiceFactory,
     395                 :            :                 (bOASIS ? "com.sun.star.comp.Writer.XMLOasisSettingsExporter"
     396                 :            :                         : "com.sun.star.comp.Writer.XMLSettingsExporter"),
     397 [ +  + ][ +  - ]:         19 :                 aEmptyArgs, aProps, sal_False ) )
     398                 :            :             {
     399         [ #  # ]:          0 :                 if( !bWarn )
     400                 :            :                 {
     401                 :          0 :                     bWarn = sal_True;
     402                 :            :                     sWarnFile = String( RTL_CONSTASCII_STRINGPARAM("settings.xml"),
     403 [ #  # ][ #  # ]:          0 :                                         RTL_TEXTENCODING_ASCII_US );
                 [ #  # ]
     404                 :            :                 }
     405                 :            :             }
     406                 :            :         }
     407                 :            :     }
     408                 :            : 
     409         [ -  + ]:         21 :     if( !WriteThroughComponent(
     410                 :            :             xModelComp, "styles.xml", xServiceFactory,
     411                 :            :             (bOASIS ? "com.sun.star.comp.Writer.XMLOasisStylesExporter"
     412                 :            :                     : "com.sun.star.comp.Writer.XMLStylesExporter"),
     413 [ +  + ][ +  - ]:         21 :             aFilterArgs, aProps, sal_False ) )
     414                 :            :     {
     415                 :          0 :         bErr = sal_True;
     416                 :            :         sErrFile = String( RTL_CONSTASCII_STRINGPARAM("styles.xml"),
     417 [ #  # ][ #  # ]:          0 :                            RTL_TEXTENCODING_ASCII_US );
                 [ #  # ]
     418                 :            :     }
     419                 :            : 
     420                 :            : 
     421 [ +  - ][ +  - ]:         21 :     if( !bOrganizerMode && !bErr )
     422                 :            :     {
     423         [ -  + ]:         21 :         if( !WriteThroughComponent(
     424                 :            :                 xModelComp, "content.xml", xServiceFactory,
     425                 :            :                 (bOASIS ? "com.sun.star.comp.Writer.XMLOasisContentExporter"
     426                 :            :                         : "com.sun.star.comp.Writer.XMLContentExporter"),
     427 [ +  + ][ +  - ]:         21 :                 aFilterArgs, aProps, sal_False ) )
     428                 :            :         {
     429                 :          0 :             bErr = sal_True;
     430                 :            :             sErrFile = String( RTL_CONSTASCII_STRINGPARAM("content.xml"),
     431 [ #  # ][ #  # ]:          0 :                                RTL_TEXTENCODING_ASCII_US );
                 [ #  # ]
     432                 :            :         }
     433                 :            :     }
     434                 :            : 
     435 [ +  - ][ +  + ]:         25 :     if( pDoc->GetCurrentViewShell() && pDoc->GetDocStat().nPage > 1 &&  //swmod 071108//swmod 071225
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
     436 [ +  - ][ +  - ]:          4 :         !(bOrganizerMode || bBlock || bErr) )
     437                 :            :     {
     438         [ +  - ]:          4 :         OUString sStreamName( RTL_CONSTASCII_USTRINGPARAM("layout-cache") );
     439                 :            :         try
     440                 :            :         {
     441 [ +  - ][ +  - ]:          4 :             uno::Reference < io::XStream > xStm = xStg->openStreamElement( sStreamName, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
     442         [ +  - ]:          4 :             SvStream* pStream = utl::UcbStreamHelper::CreateStream( xStm );
     443         [ +  - ]:          4 :             if( !pStream->GetError() )
     444                 :            :             {
     445         [ +  - ]:          4 :                 uno::Reference < beans::XPropertySet > xSet( xStm, UNO_QUERY );
     446         [ +  - ]:          4 :                 OUString aMime( RTL_CONSTASCII_USTRINGPARAM("application/binary") );
     447                 :          4 :                 uno::Any aAny2;
     448         [ +  - ]:          4 :                 aAny2 <<= aMime;
     449 [ +  - ][ +  - ]:          4 :                 xSet->setPropertyValue( rtl::OUString("MediaType"), aAny2 );
     450         [ +  - ]:          4 :                 pDoc->WriteLayoutCache( *pStream );
     451                 :            :             }
     452                 :            : 
     453 [ +  - ][ +  - ]:          4 :             delete pStream;
                 [ #  # ]
     454                 :            :         }
     455         [ #  # ]:          0 :         catch ( uno::Exception& )
     456                 :            :         {
     457                 :          4 :         }
     458                 :            :     }
     459                 :            : 
     460         [ +  - ]:         21 :     if( pGraphicHelper )
     461         [ +  - ]:         21 :         SvXMLGraphicHelper::Destroy( pGraphicHelper );
     462         [ +  - ]:         21 :     xGraphicResolver = 0;
     463                 :            : 
     464         [ +  - ]:         21 :     if( pObjectHelper )
     465         [ +  - ]:         21 :         SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
     466         [ +  - ]:         21 :     xObjectResolver = 0;
     467                 :            : 
     468                 :            :     // restore redline mode
     469 [ +  - ][ +  - ]:         21 :     aAny = xInfoSet->getPropertyValue( sShowChanges );
     470         [ +  - ]:         21 :     nRedlineMode = pDoc->GetRedlineMode();
     471                 :         21 :     nRedlineMode &= ~nsRedlineMode_t::REDLINE_SHOW_MASK;
     472                 :         21 :     nRedlineMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
     473         [ +  - ]:         21 :     if ( *(sal_Bool*)aAny.getValue() )
     474                 :         21 :         nRedlineMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
     475         [ +  - ]:         21 :     pDoc->SetRedlineMode((RedlineMode_t)( nRedlineMode ));
     476                 :            : 
     477         [ -  + ]:         21 :     if (xStatusIndicator.is())
     478                 :            :     {
     479 [ #  # ][ #  # ]:          0 :         xStatusIndicator->end();
     480                 :            :     }
     481                 :            : 
     482         [ -  + ]:         21 :     if( bErr )
     483                 :            :     {
     484         [ #  # ]:          0 :         if( sErrFile.Len() )
     485                 :            :             return *new StringErrorInfo( ERR_WRITE_ERROR_FILE, sErrFile,
     486 [ #  # ][ #  # ]:          0 :                                          ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
                 [ #  # ]
     487                 :            :         else
     488                 :          0 :             return ERR_SWG_WRITE_ERROR;
     489                 :            :     }
     490         [ +  + ]:         21 :     else if( bWarn )
     491                 :            :     {
     492         [ -  + ]:          3 :         if( sWarnFile.Len() )
     493                 :            :             return *new StringErrorInfo( WARN_WRITE_ERROR_FILE, sWarnFile,
     494 [ #  # ][ #  # ]:          0 :                                          ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
                 [ #  # ]
     495                 :            :         else
     496                 :          3 :             return WARN_SWG_FEATURES_LOST;
     497                 :            :     }
     498                 :            : 
     499 [ +  - ][ +  - ]:         21 :     return 0;
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     500                 :            : }
     501                 :            : 
     502                 :          2 : sal_uLong SwXMLWriter::WriteStorage()
     503                 :            : {
     504                 :          2 :     return _Write();
     505                 :            : }
     506                 :            : 
     507                 :         19 : sal_uLong SwXMLWriter::WriteMedium( SfxMedium& aTargetMedium )
     508                 :            : {
     509                 :         19 :     return _Write( &aTargetMedium );
     510                 :            : }
     511                 :            : 
     512                 :         19 : sal_uLong SwXMLWriter::Write( SwPaM& rPaM, SfxMedium& rMed,
     513                 :            :                                const String* pFileName )
     514                 :            : {
     515                 :         19 :     return IsStgWriter()
     516 [ +  - ][ +  - ]:         38 :             ? ((StgWriter *)this)->Write( rPaM, rMed.GetOutputStorage(), pFileName, &rMed )
                 [ #  # ]
     517 [ +  - ][ #  # ]:         57 :             : ((Writer *)this)->Write( rPaM, *rMed.GetOutStream(), pFileName );
         [ #  # ][ +  - ]
     518                 :            : }
     519                 :            : 
     520                 :         80 : sal_Bool SwXMLWriter::WriteThroughComponent(
     521                 :            :     const uno::Reference<XComponent> & xComponent,
     522                 :            :     const sal_Char* pStreamName,
     523                 :            :     const uno::Reference<lang::XMultiServiceFactory> & rFactory,
     524                 :            :     const sal_Char* pServiceName,
     525                 :            :     const Sequence<Any> & rArguments,
     526                 :            :     const Sequence<beans::PropertyValue> & rMediaDesc,
     527                 :            :     sal_Bool bPlainStream )
     528                 :            : {
     529                 :            :     OSL_ENSURE( xStg.is(), "Need storage!" );
     530                 :            :     OSL_ENSURE( NULL != pStreamName, "Need stream name!" );
     531                 :            :     OSL_ENSURE( NULL != pServiceName, "Need service name!" );
     532                 :            : 
     533                 :            :     RTL_LOGFILE_TRACE_AUTHOR1( "sw", LOGFILE_AUTHOR,
     534                 :            :                                "SwXMLWriter::WriteThroughComponent : stream %s",
     535                 :            :                                pStreamName );
     536                 :            : 
     537                 :            :     // open stream
     538                 :         80 :     sal_Bool bRet = sal_False;
     539                 :            :     try
     540                 :            :     {
     541                 :         80 :         OUString sStreamName = OUString::createFromAscii( pStreamName );
     542                 :            :         uno::Reference<io::XStream> xStream =
     543         [ +  - ]:         80 :                 xStg->openStreamElement( sStreamName,
     544         [ +  - ]:         80 :                 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
     545                 :            : 
     546         [ +  - ]:         80 :         uno::Reference <beans::XPropertySet > xSet( xStream, uno::UNO_QUERY );
     547         [ -  + ]:         80 :         if( !xSet.is() )
     548                 :          0 :             return sal_False;
     549                 :            : 
     550         [ +  - ]:         80 :         OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
     551                 :         80 :         uno::Any aAny;
     552         [ +  - ]:         80 :         aAny <<= aMime;
     553 [ +  - ][ +  - ]:         80 :         xSet->setPropertyValue( rtl::OUString("MediaType"), aAny );
     554                 :            : 
     555         [ +  - ]:         80 :         OUString aUseCommonPassPropName( RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") );
     556         [ +  + ]:         80 :         if( bPlainStream )
     557                 :            :         {
     558         [ +  - ]:         19 :             OUString aCompressPropName( RTL_CONSTASCII_USTRINGPARAM("Compressed") );
     559                 :         19 :             sal_Bool bFalse = sal_False;
     560         [ +  - ]:         19 :             aAny.setValue( &bFalse, ::getBooleanCppuType() );
     561 [ +  - ][ +  - ]:         19 :             xSet->setPropertyValue( aCompressPropName, aAny );
     562                 :            :         }
     563                 :            : 
     564                 :            :         // even plain stream should be encrypted in encrypted documents
     565                 :         80 :         sal_Bool bTrue = sal_True;
     566         [ +  - ]:         80 :         aAny.setValue( &bTrue, ::getBooleanCppuType() );
     567 [ +  - ][ +  - ]:         80 :         xSet->setPropertyValue( aUseCommonPassPropName, aAny );
     568                 :            : 
     569                 :            :         // set buffer and create outputstream
     570 [ +  - ][ +  - ]:         80 :         uno::Reference< io::XOutputStream > xOutputStream = xStream->getOutputStream();
     571                 :            : 
     572                 :            :         // set Base URL
     573                 :         80 :         uno::Reference< beans::XPropertySet > xInfoSet;
     574         [ +  - ]:         80 :         if( rArguments.getLength() > 0 )
     575         [ +  - ]:         80 :             rArguments.getConstArray()[0] >>= xInfoSet;
     576                 :            :         OSL_ENSURE( xInfoSet.is(), "missing property set" );
     577         [ +  - ]:         80 :         if( xInfoSet.is() )
     578                 :            :         {
     579         [ +  - ]:         80 :             OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
     580 [ +  - ][ +  - ]:         80 :             xInfoSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
                 [ +  - ]
     581                 :            :         }
     582                 :            : 
     583                 :            :         // write the stuff
     584                 :            :         bRet = WriteThroughComponent(
     585                 :            :             xOutputStream, xComponent, rFactory,
     586 [ +  - ][ -  + ]:         80 :             pServiceName, rArguments, rMediaDesc );
         [ -  + ][ +  - ]
                 [ #  # ]
     587                 :            :     }
     588                 :          0 :     catch ( uno::Exception& )
     589                 :            :     {
     590                 :            :     }
     591                 :            : 
     592                 :         80 :     return bRet;
     593                 :            : 
     594                 :            : }
     595                 :            : 
     596                 :         80 : sal_Bool SwXMLWriter::WriteThroughComponent(
     597                 :            :     const uno::Reference<io::XOutputStream> & xOutputStream,
     598                 :            :     const uno::Reference<XComponent> & xComponent,
     599                 :            :     const uno::Reference<XMultiServiceFactory> & rFactory,
     600                 :            :     const sal_Char* pServiceName,
     601                 :            :     const Sequence<Any> & rArguments,
     602                 :            :     const Sequence<PropertyValue> & rMediaDesc )
     603                 :            : {
     604                 :            :     OSL_ENSURE( xOutputStream.is(), "I really need an output stream!" );
     605                 :            :     OSL_ENSURE( xComponent.is(), "Need component!" );
     606                 :            :     OSL_ENSURE( NULL != pServiceName, "Need component name!" );
     607                 :            : 
     608                 :            :     RTL_LOGFILE_CONTEXT_AUTHOR( aFilterLog, "sw", LOGFILE_AUTHOR,
     609                 :            :                                 "SwXMLWriter::WriteThroughComponent" );
     610                 :            : 
     611                 :            :     // get component
     612                 :            :     uno::Reference< io::XActiveDataSource > xSaxWriter(
     613         [ +  - ]:         80 :         rFactory->createInstance(rtl::OUString("com.sun.star.xml.sax.Writer")),
     614 [ +  - ][ +  - ]:         80 :         UNO_QUERY );
     615                 :            :     OSL_ENSURE( xSaxWriter.is(), "can't instantiate XML writer" );
     616         [ -  + ]:         80 :     if(!xSaxWriter.is())
     617                 :          0 :         return sal_False;
     618                 :            : 
     619                 :            :     RTL_LOGFILE_CONTEXT_TRACE( aFilterLog, "SAX-Writer created" );
     620                 :            : 
     621                 :            :     // connect XML writer to output stream
     622 [ +  - ][ +  - ]:         80 :     xSaxWriter->setOutputStream( xOutputStream );
     623                 :            : 
     624                 :            :     // prepare arguments (prepend doc handler to given arguments)
     625         [ +  - ]:         80 :     uno::Reference<xml::sax::XDocumentHandler> xDocHandler( xSaxWriter,UNO_QUERY);
     626         [ +  - ]:         80 :     Sequence<Any> aArgs( 1 + rArguments.getLength() );
     627 [ +  - ][ +  - ]:         80 :     aArgs[0] <<= xDocHandler;
     628         [ +  + ]:        244 :     for(sal_Int32 i = 0; i < rArguments.getLength(); i++)
     629         [ +  - ]:        164 :         aArgs[i+1] = rArguments[i];
     630                 :            : 
     631                 :            :     // get filter component
     632                 :            :     uno::Reference< document::XExporter > xExporter(
     633         [ +  - ]:         80 :         rFactory->createInstanceWithArguments(
     634 [ +  - ][ +  - ]:         80 :             OUString::createFromAscii(pServiceName), aArgs), UNO_QUERY);
     635                 :            :     OSL_ENSURE( xExporter.is(),
     636                 :            :             "can't instantiate export filter component" );
     637         [ -  + ]:         80 :     if( !xExporter.is() )
     638                 :          0 :         return sal_False;
     639                 :            :     RTL_LOGFILE_CONTEXT_TRACE1( aFilterLog, "%s instantiated.", pServiceName );
     640                 :            : 
     641                 :            :     // connect model and filter
     642 [ +  - ][ +  - ]:         80 :     xExporter->setSourceDocument( xComponent );
     643                 :            : 
     644                 :            :     // filter!
     645                 :            :     RTL_LOGFILE_CONTEXT_TRACE( aFilterLog, "call filter()" );
     646         [ +  - ]:         80 :     uno::Reference<XFilter> xFilter( xExporter, UNO_QUERY );
     647 [ +  - ][ +  - ]:         80 :     return xFilter->filter( rMediaDesc );
                 [ +  - ]
     648                 :            : }
     649                 :            : 
     650                 :            : 
     651                 :            : // -----------------------------------------------------------------------
     652                 :            : 
     653                 :         21 : void GetXMLWriter( const String& /*rName*/, const String& rBaseURL, WriterRef& xRet )
     654                 :            : {
     655         [ +  - ]:         21 :     xRet = new SwXMLWriter( rBaseURL );
     656                 :         21 : }
     657                 :            : 
     658                 :            : // -----------------------------------------------------------------------
     659                 :            : 
     660                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10