1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrtxml.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <com/sun/star/embed/XStorage.hpp>
35 #include <com/sun/star/embed/ElementModes.hpp>
36 #include <com/sun/star/container/XIndexContainer.hpp>
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
39 #include <com/sun/star/io/XActiveDataSource.hpp>
40 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
41 #include <com/sun/star/document/XExporter.hpp>
42 #include <com/sun/star/document/XFilter.hpp>
43 #include <com/sun/star/frame/XModule.hpp>
44 #include <comphelper/processfactory.hxx>
45 #include <comphelper/genericpropertyset.hxx>
46 #include <unotools/streamwrap.hxx>
47 #include <svx/xmlgrhlp.hxx>
48 #include <svx/xmleohlp.hxx>
49 #include <svtools/saveopt.hxx>
50 #include <tools/urlobj.hxx>
51 #include <svtools/stritem.hxx>
52 #include <sfx2/frame.hxx>
53 #include <sfx2/docfile.hxx>
56 #include <docstat.hxx>
59 #include <unotools/ucbstreamhelper.hxx>
63 #include <statstr.hrc>
64 #include <rtl/logfile.hxx>
66 #include <comphelper/documentconstants.hxx>
67 #include <comphelper/makesequence.hxx>
68 #include <com/sun/star/rdf/XDocumentMetadataAccess.hpp>
70 using ::rtl::OUString
;
71 using namespace ::com::sun::star
;
72 using namespace ::com::sun::star::uno
;
73 using namespace ::com::sun::star::container
;
74 using namespace ::com::sun::star::document
;
75 using namespace ::com::sun::star::beans
;
76 using namespace ::com::sun::star::lang
;
78 #define LOGFILE_AUTHOR "mb93740"
80 SwXMLWriter::SwXMLWriter( const String
& rBaseURL
)
82 SetBaseURL( rBaseURL
);
86 __EXPORT
SwXMLWriter::~SwXMLWriter()
91 sal_uInt32
SwXMLWriter::_Write( SfxMedium
* pTargetMedium
)
93 DBG_ASSERT( pTargetMedium
, "No medium is provided!" );
94 // Get service factory
95 uno::Reference
< lang::XMultiServiceFactory
> xServiceFactory
=
96 comphelper::getProcessServiceFactory();
97 ASSERT( xServiceFactory
.is(),
98 "SwXMLWriter::Write: got no service manager" );
99 if( !xServiceFactory
.is() )
100 return ERR_SWG_WRITE_ERROR
;
103 uno::Reference
< io::XOutputStream
> xOut
;
104 SvStorageStreamRef xDocStream
;
105 uno::Reference
< document::XGraphicObjectResolver
> xGraphicResolver
;
106 SvXMLGraphicHelper
*pGraphicHelper
= 0;
107 uno::Reference
< document::XEmbeddedObjectResolver
> xObjectResolver
;
108 SvXMLEmbeddedObjectHelper
*pObjectHelper
= 0;
110 ASSERT( xStg
.is(), "Where is my storage?" );
111 pGraphicHelper
= SvXMLGraphicHelper::Create( xStg
,
112 GRAPHICHELPER_MODE_WRITE
,
114 xGraphicResolver
= pGraphicHelper
;
116 SfxObjectShell
*pPersist
= pDoc
->GetPersist();
119 pObjectHelper
= SvXMLEmbeddedObjectHelper::Create(
121 EMBEDDEDOBJECTHELPER_MODE_WRITE
,
123 xObjectResolver
= pObjectHelper
;
126 // create and prepare the XPropertySet that gets passed through
127 // the components, and the XStatusIndicator that shows progress to
130 // create XPropertySet with three properties for status indicator
131 comphelper::PropertyMapEntry aInfoMap
[] =
133 { "ProgressRange", sizeof("ProgressRange")-1, 0,
134 &::getCppuType((sal_Int32
*)0),
135 beans::PropertyAttribute::MAYBEVOID
, 0},
136 { "ProgressMax", sizeof("ProgressMax")-1, 0,
137 &::getCppuType((sal_Int32
*)0),
138 beans::PropertyAttribute::MAYBEVOID
, 0},
139 { "ProgressCurrent", sizeof("ProgressCurrent")-1, 0,
140 &::getCppuType((sal_Int32
*)0),
141 beans::PropertyAttribute::MAYBEVOID
, 0},
142 { "WrittenNumberStyles", sizeof("WrittenNumberStyles")-1, 0,
143 &::getCppuType((uno::Sequence
<sal_Int32
> *)0),
144 beans::PropertyAttribute::MAYBEVOID
, 0},
145 { "UsePrettyPrinting", sizeof("UsePrettyPrinting")-1, 0,
146 &::getBooleanCppuType(),
147 beans::PropertyAttribute::MAYBEVOID
, 0},
148 { "ShowChanges", sizeof("ShowChanges")-1, 0,
149 &::getBooleanCppuType(),
150 beans::PropertyAttribute::MAYBEVOID
, 0 },
151 { "RedlineProtectionKey", sizeof("RedlineProtectionKey")-1, 0,
152 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
153 new uno::Type(::getCppuType((Sequence
<sal_Int8
>*)0)),
155 &::getCppuType((Sequence
<sal_Int8
>*)0),
157 beans::PropertyAttribute::MAYBEVOID
, 0 },
158 { "BaseURI", sizeof("BaseURI")-1, 0,
159 &::getCppuType( (OUString
*)0 ),
160 beans::PropertyAttribute::MAYBEVOID
, 0 },
161 { "StreamRelPath", sizeof("StreamRelPath")-1, 0,
162 &::getCppuType( (OUString
*)0 ),
163 beans::PropertyAttribute::MAYBEVOID
, 0 },
164 { "StreamName", sizeof("StreamName")-1, 0,
165 &::getCppuType( (OUString
*)0 ),
166 beans::PropertyAttribute::MAYBEVOID
, 0 },
167 { "AutoTextMode", sizeof("AutoTextMode")-1, 0,
168 &::getBooleanCppuType(),
169 beans::PropertyAttribute::MAYBEVOID
, 0 },
170 { "StyleNames", sizeof("StyleNames")-1, 0,
171 &::getCppuType( (Sequence
<OUString
>*)0 ),
172 beans::PropertyAttribute::MAYBEVOID
, 0 },
173 { "StyleFamilies", sizeof("StyleFamilies")-1, 0,
174 &::getCppuType( (Sequence
<sal_Int32
>*)0 ),
175 beans::PropertyAttribute::MAYBEVOID
, 0 },
176 // --> OD 2006-09-26 #i69627#
177 { "OutlineStyleAsNormalListStyle", sizeof("OutlineStyleAsNormalListStyle")-1, 0,
178 &::getBooleanCppuType(),
179 beans::PropertyAttribute::MAYBEVOID
, 0 },
181 { "TargetStorage", sizeof("TargetStorage")-1,0, &embed::XStorage::static_type(),
182 ::com::sun::star::beans::PropertyAttribute::MAYBEVOID
, 0 },
184 { NULL
, 0, 0, NULL
, 0, 0 }
186 uno::Reference
< beans::XPropertySet
> xInfoSet(
187 comphelper::GenericPropertySet_CreateInstance(
188 new comphelper::PropertySetInfo( aInfoMap
) ) );
190 const OUString
sTargetStorage( RTL_CONSTASCII_USTRINGPARAM("TargetStorage") );
191 xInfoSet
->setPropertyValue( sTargetStorage
, Any( xStg
) );
193 // create XStatusIndicator
194 uno::Reference
<task::XStatusIndicator
> xStatusIndicator
;
199 // retrieve status indicator from the medium MediaDescriptor
202 const SfxUnoAnyItem
* pStatusBarItem
= static_cast<const SfxUnoAnyItem
*>(
203 pTargetMedium
->GetItemSet()->GetItem(SID_PROGRESS_STATUSBAR_CONTROL
) );
205 if ( pStatusBarItem
)
206 pStatusBarItem
->GetValue() >>= xStatusIndicator
;
211 // uno::Reference<frame::XModel> xModel( pDoc->GetDocShell()->GetModel());
214 // uno::Sequence< beans::PropertyValue > xMediaDescr
215 // uno::Reference<frame::XController> xController(
216 // xModel->getCurrentController());
217 // if( xController.is())
219 // uno::Reference<frame::XFrame> xFrame( xController->getFrame());
222 // uno::Reference<task::XStatusIndicatorFactory> xFactory(
223 // xFrame, uno::UNO_QUERY );
224 // if( xFactory.is())
226 // xStatusIndicator =
227 // xFactory->createStatusIndicator();
233 // catch( const RuntimeException& )
235 // xStatusIndicator = 0;
238 // set progress range and start status indicator
239 sal_Int32
nProgressRange(1000000);
240 if (xStatusIndicator
.is())
242 xStatusIndicator
->start(SW_RESSTR( STR_STATSTR_SWGWRITE
),
245 aAny
<<= nProgressRange
;
246 OUString
sProgressRange(RTL_CONSTASCII_USTRINGPARAM("ProgressRange"));
247 xInfoSet
->setPropertyValue(sProgressRange
, aAny
);
249 aAny
<<= static_cast < sal_Int32
>( -1 );
250 OUString
sProgressMax(RTL_CONSTASCII_USTRINGPARAM("ProgressMax"));
251 xInfoSet
->setPropertyValue(sProgressMax
, aAny
);
253 SvtSaveOptions aSaveOpt
;
254 OUString
sUsePrettyPrinting(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting"));
255 sal_Bool
bUsePrettyPrinting( aSaveOpt
.IsPrettyPrinting() );
256 aAny
.setValue( &bUsePrettyPrinting
, ::getBooleanCppuType() );
257 xInfoSet
->setPropertyValue( sUsePrettyPrinting
, aAny
);
259 // save show redline mode ...
260 OUString
sShowChanges(RTL_CONSTASCII_USTRINGPARAM("ShowChanges"));
261 sal_uInt16 nRedlineMode
= pDoc
->GetRedlineMode();
262 sal_Bool
bShowChanges( IDocumentRedlineAccess::IsShowChanges( nRedlineMode
) );
263 aAny
.setValue( &bShowChanges
, ::getBooleanCppuType() );
264 xInfoSet
->setPropertyValue( sShowChanges
, aAny
);
265 // ... and hide redlines for export
266 nRedlineMode
&= ~nsRedlineMode_t::REDLINE_SHOW_MASK
;
267 nRedlineMode
|= nsRedlineMode_t::REDLINE_SHOW_INSERT
;
268 pDoc
->SetRedlineMode((RedlineMode_t
)( nRedlineMode
));
271 OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
272 xInfoSet
->setPropertyValue( sPropName
, makeAny( ::rtl::OUString( GetBaseURL() ) ) );
274 if( SFX_CREATE_MODE_EMBEDDED
== pDoc
->GetDocShell()->GetCreateMode() )
277 if ( pTargetMedium
&& pTargetMedium
->GetItemSet() )
279 const SfxStringItem
* pDocHierarchItem
= static_cast<const SfxStringItem
*>(
280 pTargetMedium
->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME
) );
281 if ( pDocHierarchItem
)
282 aName
= pDocHierarchItem
->GetValue();
285 aName
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "dummyObjectName" ) );
287 if( aName
.getLength() )
289 sPropName
= OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
290 xInfoSet
->setPropertyValue( sPropName
, makeAny( aName
) );
296 OUString
sAutoTextMode(
297 RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
298 sal_Bool bTmp
= sal_True
;
300 aAny2
.setValue( &bTmp
, ::getBooleanCppuType() );
301 xInfoSet
->setPropertyValue( sAutoTextMode
, aAny2
);
304 // --> OD 2006-09-26 #i69627#
305 const sal_Bool bOASIS
= ( SotStorage::GetVersion( xStg
) > SOFFICE_FILEFORMAT_60
);
307 docfunc::HasOutlineStyleToBeWrittenAsNormalListStyle( *pDoc
) )
309 OUString
sOutlineStyleAsNormalListStyle(
310 RTL_CONSTASCII_USTRINGPARAM("OutlineStyleAsNormalListStyle") );
311 xInfoSet
->setPropertyValue( sOutlineStyleAsNormalListStyle
, makeAny( sal_True
) );
316 // - graphics + object resolver for styles + content
317 // - status indicator
318 // - info property set
321 if( xStatusIndicator
.is() )
324 Sequence
< Any
> aEmptyArgs( nArgs
);
325 Any
*pArgs
= aEmptyArgs
.getArray();
326 *pArgs
++ <<= xInfoSet
;
327 if( xStatusIndicator
.is() )
328 *pArgs
++ <<= xStatusIndicator
;
330 if( xGraphicResolver
.is() )
332 if( xObjectResolver
.is() )
335 Sequence
< Any
> aFilterArgs( nArgs
);
336 pArgs
= aFilterArgs
.getArray();
337 *pArgs
++ <<= xInfoSet
;
338 if( xGraphicResolver
.is() )
339 *pArgs
++ <<= xGraphicResolver
;
340 if( xObjectResolver
.is() )
341 *pArgs
++ <<= xObjectResolver
;
342 if( xStatusIndicator
.is() )
343 *pArgs
++ <<= xStatusIndicator
;
346 uno::Reference
< lang::XComponent
> xModelComp(
347 pDoc
->GetDocShell()->GetModel(), UNO_QUERY
);
348 ASSERT( xModelComp
.is(), "XMLWriter::Write: got no model" );
349 if( !xModelComp
.is() )
350 return ERR_SWG_WRITE_ERROR
;
352 PutNumFmtFontsInAttrPool();
353 PutEditEngFontsInAttrPool();
356 Sequence
< PropertyValue
> aProps( pOrigFileName
? 1 : 0 );
359 PropertyValue
*pProps
= aProps
.getArray();
360 pProps
->Name
= OUString( RTL_CONSTASCII_USTRINGPARAM("FileName") );
361 (pProps
++)->Value
<<= OUString( *pOrigFileName
);
364 // export sub streams for package, else full stream into a file
365 sal_Bool bWarn
= sal_False
, bErr
= sal_False
;
366 String sWarnFile
, sErrFile
;
368 // RDF metadata: export if ODF >= 1.2
369 // N.B.: embedded documents have their own manifest.rdf!
372 const uno::Reference
<beans::XPropertySet
> xPropSet(xStg
,
373 uno::UNO_QUERY_THROW
);
374 const ::rtl::OUString
VersionProp(
375 ::rtl::OUString::createFromAscii("Version"));
378 ::rtl::OUString Version
;
380 if ((xPropSet
->getPropertyValue(VersionProp
) >>= Version
)
381 && !Version
.equals(ODFVER_010_TEXT
)
382 && !Version
.equals(ODFVER_011_TEXT
))
384 const uno::Reference
<rdf::XDocumentMetadataAccess
> xDMA(
385 xModelComp
, uno::UNO_QUERY_THROW
);
386 xDMA
->storeMetadataToStorage(xStg
);
389 catch (beans::UnknownPropertyException
&)
391 catch (uno::Exception
&)
397 sal_Bool bStoreMeta
= ( SFX_CREATE_MODE_EMBEDDED
!= pDoc
->GetDocShell()->GetCreateMode() );
402 Reference
< frame::XModule
> xModule( xModelComp
, UNO_QUERY
);
405 ::rtl::OUString aModuleID
= xModule
->getIdentifier();
406 bStoreMeta
= ( aModuleID
.getLength()
407 && ( aModuleID
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.FormDesign" ) ) )
408 || aModuleID
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.TextReportDesign" ) ) ) ) );
411 catch( uno::Exception
& )
415 if( !bOrganizerMode
&& !bBlock
&& bStoreMeta
)
417 if( !WriteThroughComponent(
418 xModelComp
, "meta.xml", xServiceFactory
,
419 (bOASIS
? "com.sun.star.comp.Writer.XMLOasisMetaExporter"
420 : "com.sun.star.comp.Writer.XMLMetaExporter"),
421 aEmptyArgs
, aProps
, sal_True
) )
424 sWarnFile
= String( RTL_CONSTASCII_STRINGPARAM("meta.xml"),
425 RTL_TEXTENCODING_ASCII_US
);
433 if( !WriteThroughComponent(
434 xModelComp
, "settings.xml", xServiceFactory
,
435 (bOASIS
? "com.sun.star.comp.Writer.XMLOasisSettingsExporter"
436 : "com.sun.star.comp.Writer.XMLSettingsExporter"),
437 aEmptyArgs
, aProps
, sal_False
) )
442 sWarnFile
= String( RTL_CONSTASCII_STRINGPARAM("settings.xml"),
443 RTL_TEXTENCODING_ASCII_US
);
449 if( !WriteThroughComponent(
450 xModelComp
, "styles.xml", xServiceFactory
,
451 (bOASIS
? "com.sun.star.comp.Writer.XMLOasisStylesExporter"
452 : "com.sun.star.comp.Writer.XMLStylesExporter"),
453 aFilterArgs
, aProps
, sal_False
) )
456 sErrFile
= String( RTL_CONSTASCII_STRINGPARAM("styles.xml"),
457 RTL_TEXTENCODING_ASCII_US
);
461 if( !bOrganizerMode
&& !bErr
)
463 if( !WriteThroughComponent(
464 xModelComp
, "content.xml", xServiceFactory
,
465 (bOASIS
? "com.sun.star.comp.Writer.XMLOasisContentExporter"
466 : "com.sun.star.comp.Writer.XMLContentExporter"),
467 aFilterArgs
, aProps
, sal_False
) )
470 sErrFile
= String( RTL_CONSTASCII_STRINGPARAM("content.xml"),
471 RTL_TEXTENCODING_ASCII_US
);
475 if( pDoc
->GetRootFrm() && pDoc
->GetDocStat().nPage
> 1 &&
476 !(bOrganizerMode
|| bBlock
|| bErr
) )
478 // DBG_ASSERT( !pDoc->GetDocStat().bModified,
479 // "doc stat is modified!" );
480 OUString
sStreamName( RTL_CONSTASCII_USTRINGPARAM("layout-cache") );
483 uno::Reference
< io::XStream
> xStm
= xStg
->openStreamElement( sStreamName
, embed::ElementModes::READWRITE
| embed::ElementModes::TRUNCATE
);
484 SvStream
* pStream
= utl::UcbStreamHelper::CreateStream( xStm
);
485 if( !pStream
->GetError() )
487 uno::Reference
< beans::XPropertySet
> xSet( xStm
, UNO_QUERY
);
488 String
aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
489 OUString
aMime( RTL_CONSTASCII_USTRINGPARAM("application/binary") );
492 xSet
->setPropertyValue( aPropName
, aAny2
);
493 pDoc
->WriteLayoutCache( *pStream
);
498 catch ( uno::Exception
& )
504 SvXMLGraphicHelper::Destroy( pGraphicHelper
);
505 xGraphicResolver
= 0;
508 SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper
);
511 // restore redline mode
512 aAny
= xInfoSet
->getPropertyValue( sShowChanges
);
513 nRedlineMode
= pDoc
->GetRedlineMode();
514 nRedlineMode
&= ~nsRedlineMode_t::REDLINE_SHOW_MASK
;
515 nRedlineMode
|= nsRedlineMode_t::REDLINE_SHOW_INSERT
;
516 if ( *(sal_Bool
*)aAny
.getValue() )
517 nRedlineMode
|= nsRedlineMode_t::REDLINE_SHOW_DELETE
;
518 pDoc
->SetRedlineMode((RedlineMode_t
)( nRedlineMode
));
520 if (xStatusIndicator
.is())
522 xStatusIndicator
->end();
528 return *new StringErrorInfo( ERR_WRITE_ERROR_FILE
, sErrFile
,
529 ERRCODE_BUTTON_OK
| ERRCODE_MSG_ERROR
);
531 return ERR_SWG_WRITE_ERROR
;
535 if( sWarnFile
.Len() )
536 return *new StringErrorInfo( WARN_WRITE_ERROR_FILE
, sWarnFile
,
537 ERRCODE_BUTTON_OK
| ERRCODE_MSG_ERROR
);
539 return WARN_SWG_FEATURES_LOST
;
545 ULONG
SwXMLWriter::WriteStorage()
550 ULONG
SwXMLWriter::WriteMedium( SfxMedium
& aTargetMedium
)
552 return _Write( &aTargetMedium
);
555 ULONG
SwXMLWriter::Write( SwPaM
& rPaM
, SfxMedium
& rMed
,
556 const String
* pFileName
)
559 ? ((StgWriter
*)this)->Write( rPaM
, rMed
.GetOutputStorage(), pFileName
, &rMed
)
560 : ((Writer
*)this)->Write( rPaM
, *rMed
.GetOutStream(), pFileName
);
563 sal_Bool
SwXMLWriter::WriteThroughComponent(
564 const uno::Reference
<XComponent
> & xComponent
,
565 const sal_Char
* pStreamName
,
566 const uno::Reference
<lang::XMultiServiceFactory
> & rFactory
,
567 const sal_Char
* pServiceName
,
568 const Sequence
<Any
> & rArguments
,
569 const Sequence
<beans::PropertyValue
> & rMediaDesc
,
570 sal_Bool bPlainStream
)
572 DBG_ASSERT( xStg
.is(), "Need storage!" );
573 DBG_ASSERT( NULL
!= pStreamName
, "Need stream name!" );
574 DBG_ASSERT( NULL
!= pServiceName
, "Need service name!" );
576 RTL_LOGFILE_TRACE_AUTHOR1( "sw", LOGFILE_AUTHOR
,
577 "SwXMLWriter::WriteThroughComponent : stream %s",
581 sal_Bool bRet
= sal_False
;
584 OUString sStreamName
= OUString::createFromAscii( pStreamName
);
585 uno::Reference
<io::XStream
> xStream
=
586 xStg
->openStreamElement( sStreamName
,
587 embed::ElementModes::READWRITE
| embed::ElementModes::TRUNCATE
);
589 uno::Reference
<beans::XPropertySet
> xSet( xStream
, uno::UNO_QUERY
);
593 String
aPropName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM("MediaType") ) );
594 OUString
aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
597 xSet
->setPropertyValue( aPropName
, aAny
);
599 OUString
aUseCommonPassPropName( RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") );
602 OUString
aCompressPropName( RTL_CONSTASCII_USTRINGPARAM("Compressed") );
603 sal_Bool bFalse
= sal_False
;
604 aAny
.setValue( &bFalse
, ::getBooleanCppuType() );
605 xSet
->setPropertyValue( aCompressPropName
, aAny
);
608 // even plain stream should be encrypted in encrypted documents
609 sal_Bool bTrue
= sal_True
;
610 aAny
.setValue( &bTrue
, ::getBooleanCppuType() );
611 xSet
->setPropertyValue( aUseCommonPassPropName
, aAny
);
613 // set buffer and create outputstream
614 uno::Reference
< io::XOutputStream
> xOutputStream
= xStream
->getOutputStream();
617 uno::Reference
< beans::XPropertySet
> xInfoSet
;
618 if( rArguments
.getLength() > 0 )
619 rArguments
.getConstArray()[0] >>= xInfoSet
;
620 DBG_ASSERT( xInfoSet
.is(), "missing property set" );
623 OUString
sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
624 xInfoSet
->setPropertyValue( sPropName
, makeAny( sStreamName
) );
628 bRet
= WriteThroughComponent(
629 xOutputStream
, xComponent
, rFactory
,
630 pServiceName
, rArguments
, rMediaDesc
);
632 catch ( uno::Exception
& )
640 sal_Bool
SwXMLWriter::WriteThroughComponent(
641 const uno::Reference
<io::XOutputStream
> & xOutputStream
,
642 const uno::Reference
<XComponent
> & xComponent
,
643 const uno::Reference
<XMultiServiceFactory
> & rFactory
,
644 const sal_Char
* pServiceName
,
645 const Sequence
<Any
> & rArguments
,
646 const Sequence
<PropertyValue
> & rMediaDesc
)
648 ASSERT( xOutputStream
.is(), "I really need an output stream!" );
649 ASSERT( xComponent
.is(), "Need component!" );
650 ASSERT( NULL
!= pServiceName
, "Need component name!" );
652 RTL_LOGFILE_CONTEXT_AUTHOR( aFilterLog
, "sw", LOGFILE_AUTHOR
,
653 "SwXMLWriter::WriteThroughComponent" );
656 uno::Reference
< io::XActiveDataSource
> xSaxWriter(
657 rFactory
->createInstance(
658 String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(
659 "com.sun.star.xml.sax.Writer")) ),
661 ASSERT( xSaxWriter
.is(), "can't instantiate XML writer" );
665 RTL_LOGFILE_CONTEXT_TRACE( aFilterLog
, "SAX-Writer created" );
667 // connect XML writer to output stream
668 xSaxWriter
->setOutputStream( xOutputStream
);
670 // prepare arguments (prepend doc handler to given arguments)
671 uno::Reference
<xml::sax::XDocumentHandler
> xDocHandler( xSaxWriter
,UNO_QUERY
);
672 Sequence
<Any
> aArgs( 1 + rArguments
.getLength() );
673 aArgs
[0] <<= xDocHandler
;
674 for(sal_Int32 i
= 0; i
< rArguments
.getLength(); i
++)
675 aArgs
[i
+1] = rArguments
[i
];
677 // get filter component
678 uno::Reference
< document::XExporter
> xExporter(
679 rFactory
->createInstanceWithArguments(
680 OUString::createFromAscii(pServiceName
), aArgs
), UNO_QUERY
);
681 ASSERT( xExporter
.is(),
682 "can't instantiate export filter component" );
683 if( !xExporter
.is() )
685 RTL_LOGFILE_CONTEXT_TRACE1( aFilterLog
, "%s instantiated.", pServiceName
);
687 // connect model and filter
688 xExporter
->setSourceDocument( xComponent
);
691 RTL_LOGFILE_CONTEXT_TRACE( aFilterLog
, "call filter()" );
692 uno::Reference
<XFilter
> xFilter( xExporter
, UNO_QUERY
);
693 return xFilter
->filter( rMediaDesc
);
697 // -----------------------------------------------------------------------
699 void GetXMLWriter( const String
& /*rName*/, const String
& rBaseURL
, WriterRef
& xRet
)
701 xRet
= new SwXMLWriter( rBaseURL
);
704 // -----------------------------------------------------------------------