LCOV - code coverage report
Current view: top level - sw/source/filter/xml - wrtxml.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 215 259 83.0 %
Date: 2014-04-11 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10