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

Generated by: LCOV version 1.10