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

Generated by: LCOV version 1.10