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