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

Generated by: LCOV version 1.10