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

Generated by: LCOV version 1.11