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/ElementModes.hpp>
21 : #include <com/sun/star/embed/XTransactedObject.hpp>
22 : #include <svl/macitem.hxx>
23 : #include <svtools/unoevent.hxx>
24 : #include <sfx2/docfile.hxx>
25 : #include <unotools/streamwrap.hxx>
26 : #include <comphelper/processfactory.hxx>
27 : #include <com/sun/star/xml/sax/InputSource.hpp>
28 : #include <com/sun/star/io/XActiveDataSource.hpp>
29 : #include <com/sun/star/xml/sax/Parser.hpp>
30 : #include <com/sun/star/xml/sax/Writer.hpp>
31 : #include <com/sun/star/document/XStorageBasedDocument.hpp>
32 : #include <doc.hxx>
33 : #include <docsh.hxx>
34 : #include <shellio.hxx>
35 : #include <SwXMLTextBlocks.hxx>
36 : #include <SwXMLBlockImport.hxx>
37 : #include <SwXMLBlockExport.hxx>
38 : #include <swevent.hxx>
39 : #include <swerror.h>
40 :
41 : const char XMLN_BLOCKLIST[] = "BlockList.xml";
42 :
43 : using namespace ::com::sun::star;
44 : using namespace ::com::sun::star::uno;
45 : using namespace ::com::sun::star::container;
46 :
47 : using ::xmloff::token::XML_BLOCK_LIST;
48 : using ::xmloff::token::XML_UNFORMATTED_TEXT;
49 : using ::xmloff::token::GetXMLToken;
50 :
51 4 : sal_uLong SwXMLTextBlocks::GetDoc( sal_uInt16 nIdx )
52 : {
53 4 : String aFolderName ( GetPackageName ( nIdx ) );
54 :
55 4 : if (!IsOnlyTextBlock ( nIdx ) )
56 : {
57 : try
58 : {
59 0 : xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::READ );
60 0 : xMedium = new SfxMedium( xRoot, GetBaseURL(), OUString( "writer8" ) );
61 0 : SwReader aReader( *xMedium, aFolderName, pDoc );
62 0 : ReadXML->SetBlockMode( sal_True );
63 0 : aReader.Read( *ReadXML );
64 0 : ReadXML->SetBlockMode( sal_False );
65 : // Ole objects fails to display when inserted into document
66 : // because the ObjectReplacement folder ( and contents are missing )
67 0 : OUString sObjReplacements( "ObjectReplacements" );
68 0 : if ( xRoot->hasByName( sObjReplacements ) )
69 : {
70 0 : uno::Reference< document::XStorageBasedDocument > xDocStor( pDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW );
71 0 : uno::Reference< embed::XStorage > xStr( xDocStor->getDocumentStorage() );
72 0 : if ( xStr.is() )
73 : {
74 0 : xRoot->copyElementTo( sObjReplacements, xStr, sObjReplacements );
75 0 : uno::Reference< embed::XTransactedObject > xTrans( xStr, uno::UNO_QUERY );
76 0 : if ( xTrans.is() )
77 0 : xTrans->commit();
78 0 : }
79 0 : }
80 : }
81 0 : catch( uno::Exception& )
82 : {
83 : }
84 :
85 0 : xRoot = 0;
86 : }
87 : else
88 : {
89 4 : String aStreamName = aFolderName + OUString(".xml");
90 : try
91 : {
92 4 : xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::READ );
93 4 : uno::Reference < io::XStream > xStream = xRoot->openStreamElement( aStreamName, embed::ElementModes::READ );
94 :
95 : uno::Reference< uno::XComponentContext > xContext =
96 8 : comphelper::getProcessComponentContext();
97 :
98 8 : xml::sax::InputSource aParserInput;
99 4 : aParserInput.sSystemId = aNames[nIdx]->aPackageName;
100 :
101 4 : aParserInput.aInputStream = xStream->getInputStream();
102 :
103 : // get filter
104 : // uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, aCur, sal_True );
105 8 : uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xContext, *this, aCur, sal_True );
106 :
107 : // connect parser and filter
108 8 : uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
109 4 : xParser->setDocumentHandler( xFilter );
110 :
111 : // parse
112 : try
113 : {
114 4 : xParser->parseStream( aParserInput );
115 : }
116 0 : catch( xml::sax::SAXParseException& )
117 : {
118 : // re throw ?
119 : }
120 0 : catch( xml::sax::SAXException& )
121 : {
122 : // re throw ?
123 : }
124 0 : catch( io::IOException& )
125 : {
126 : // re throw ?
127 : }
128 :
129 4 : bInfoChanged = sal_False;
130 8 : MakeBlockText(aCur);
131 : }
132 0 : catch( uno::Exception& )
133 : {
134 : }
135 :
136 4 : xRoot = 0;
137 : }
138 4 : return 0;
139 : }
140 :
141 : // event description for autotext events; this constant should really be
142 : // taken from unocore/unoevents.cxx or ui/unotxt.cxx
143 : const struct SvEventDescription aAutotextEvents[] =
144 : {
145 : { SW_EVENT_START_INS_GLOSSARY, "OnInsertStart" },
146 : { SW_EVENT_END_INS_GLOSSARY, "OnInsertDone" },
147 : { 0, NULL }
148 : };
149 :
150 1 : sal_uLong SwXMLTextBlocks::GetMacroTable( sal_uInt16 nIdx,
151 : SvxMacroTableDtor& rMacroTbl,
152 : sal_Bool bFileAlreadyOpen )
153 : {
154 : // set current auto text
155 :
156 1 : aShort = aNames[nIdx]->aShort;
157 1 : aLong = aNames[nIdx]->aLong;
158 1 : aPackageName = aNames[nIdx]->aPackageName;
159 :
160 1 : sal_uLong nRet = 0;
161 :
162 : // open stream in proper sub-storage
163 1 : if( !bFileAlreadyOpen )
164 : {
165 1 : CloseFile();
166 1 : nRet = OpenFile ( sal_True );
167 : }
168 1 : if ( 0 == nRet )
169 : {
170 : try
171 : {
172 1 : xRoot = xBlkRoot->openStorageElement( aPackageName, embed::ElementModes::READ );
173 1 : long nTmp = SOT_FORMATSTR_ID_STARWRITER_60;
174 1 : bool bOasis = ( SotStorage::GetVersion( xRoot ) > nTmp );
175 :
176 1 : OUString sStreamName("atevent.xml");
177 1 : uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement(
178 1 : sStreamName, embed::ElementModes::READ );
179 : OSL_ENSURE(xDocStream.is(), "Can't create stream");
180 0 : if ( xDocStream.is() )
181 : {
182 0 : uno::Reference<io::XInputStream> xInputStream = xDocStream->getInputStream();
183 :
184 : // prepare ParserInputSrouce
185 0 : xml::sax::InputSource aParserInput;
186 0 : aParserInput.sSystemId = aName;
187 0 : aParserInput.aInputStream = xInputStream;
188 :
189 : // get service factory
190 : uno::Reference< uno::XComponentContext > xContext =
191 0 : comphelper::getProcessComponentContext();
192 :
193 : // get parser
194 0 : uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
195 :
196 : // create descriptor and reference to it. Either
197 : // both or neither must be kept because of the
198 : // reference counting!
199 : SvMacroTableEventDescriptor* pDescriptor =
200 0 : new SvMacroTableEventDescriptor(aAutotextEvents);
201 0 : uno::Reference<XNameReplace> xReplace = pDescriptor;
202 0 : Sequence<Any> aFilterArguments( 1 );
203 0 : aFilterArguments[0] <<= xReplace;
204 :
205 : // get filter
206 : OUString sFilterComponent = bOasis
207 : ? OUString("com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter")
208 0 : : OUString("com.sun.star.comp.Writer.XMLAutotextEventsImporter");
209 : uno::Reference< xml::sax::XDocumentHandler > xFilter(
210 0 : xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
211 0 : sFilterComponent, aFilterArguments, xContext),
212 0 : UNO_QUERY );
213 : OSL_ENSURE( xFilter.is(),
214 : "can't instantiate atevents filter");
215 0 : if ( xFilter.is() )
216 : {
217 : // connect parser and filter
218 0 : xParser->setDocumentHandler( xFilter );
219 :
220 : // connect model and filter
221 : uno::Reference<document::XImporter> xImporter( xFilter,
222 0 : UNO_QUERY );
223 :
224 : // we don't need a model
225 : // xImporter->setTargetDocument( xModelComponent );
226 :
227 : // parse the stream
228 : try
229 : {
230 0 : xParser->parseStream( aParserInput );
231 : }
232 0 : catch( xml::sax::SAXParseException& )
233 : {
234 : // workaround for #83452#: SetSize doesn't work
235 : // nRet = ERR_SWG_READ_ERROR;
236 : }
237 0 : catch( xml::sax::SAXException& )
238 : {
239 0 : nRet = ERR_SWG_READ_ERROR;
240 : }
241 0 : catch( io::IOException& )
242 : {
243 0 : nRet = ERR_SWG_READ_ERROR;
244 : }
245 :
246 : // and finally, copy macro into table
247 0 : if (0 == nRet)
248 0 : pDescriptor->copyMacrosIntoTable(rMacroTbl);
249 : }
250 : else
251 0 : nRet = ERR_SWG_READ_ERROR;
252 : }
253 : else
254 1 : nRet = ERR_SWG_READ_ERROR;
255 : }
256 2 : catch( uno::Exception& )
257 : {
258 1 : nRet = ERR_SWG_READ_ERROR;
259 : }
260 : }
261 : else
262 0 : nRet = ERR_SWG_READ_ERROR;
263 :
264 : // success!
265 1 : return nRet;
266 : }
267 :
268 :
269 0 : sal_uLong SwXMLTextBlocks::GetBlockText( const String& rShort, String& rText )
270 : {
271 0 : sal_uLong n = 0;
272 0 : sal_Bool bTextOnly = sal_True;
273 0 : String aFolderName = GeneratePackageName ( rShort );
274 0 : String aStreamName = aFolderName + OUString(".xml");
275 0 : rText.Erase();
276 :
277 : try
278 : {
279 0 : xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::READ );
280 0 : uno::Reference < container::XNameAccess > xAccess( xRoot, uno::UNO_QUERY );
281 0 : if ( !xAccess->hasByName( aStreamName ) || !xRoot->isStreamElement( aStreamName ) )
282 : {
283 0 : bTextOnly = sal_False;
284 0 : aStreamName = OUString("content.xml");
285 : }
286 :
287 0 : uno::Reference < io::XStream > xContents = xRoot->openStreamElement( aStreamName, embed::ElementModes::READ );
288 : uno::Reference< uno::XComponentContext > xContext =
289 0 : comphelper::getProcessComponentContext();
290 :
291 0 : xml::sax::InputSource aParserInput;
292 0 : aParserInput.sSystemId = aName;
293 0 : aParserInput.aInputStream = xContents->getInputStream();
294 :
295 : // get filter
296 : // #110680#
297 : // uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, rText, bTextOnly );
298 0 : uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xContext, *this, rText, bTextOnly );
299 :
300 : // connect parser and filter
301 0 : uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
302 0 : xParser->setDocumentHandler( xFilter );
303 :
304 : // parse
305 : try
306 : {
307 0 : xParser->parseStream( aParserInput );
308 : }
309 0 : catch( xml::sax::SAXParseException& )
310 : {
311 : // re throw ?
312 : }
313 0 : catch( xml::sax::SAXException& )
314 : {
315 : // re throw ?
316 : }
317 0 : catch( io::IOException& )
318 : {
319 : // re throw ?
320 : }
321 :
322 0 : xRoot = 0;
323 : }
324 0 : catch ( uno::Exception& )
325 : {
326 : OSL_FAIL( "Tried to open non-existent folder or stream!");
327 : }
328 :
329 0 : return n;
330 : }
331 :
332 6 : sal_uLong SwXMLTextBlocks::PutBlockText( const String& rShort, const String& ,
333 : const String& rText, const String& rPackageName )
334 : {
335 6 : GetIndex ( rShort );
336 : /*
337 : if (xBlkRoot->IsContained ( rPackageName ) )
338 : {
339 : xBlkRoot->Remove ( rPackageName );
340 : xBlkRoot->Commit ( );
341 : }
342 : */
343 6 : String aFolderName( rPackageName );
344 12 : String aStreamName = aFolderName + OUString(".xml");
345 :
346 : uno::Reference< uno::XComponentContext > xContext =
347 12 : comphelper::getProcessComponentContext();
348 :
349 12 : uno::Reference < xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
350 6 : sal_uLong nRes = 0;
351 :
352 : try
353 : {
354 6 : xRoot = xBlkRoot->openStorageElement( aFolderName, embed::ElementModes::WRITE );
355 6 : uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( aStreamName,
356 6 : embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE );
357 :
358 12 : uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY );
359 12 : OUString aMime ( "text/xml" );
360 12 : Any aAny;
361 6 : aAny <<= aMime;
362 6 : xSet->setPropertyValue("MediaType", aAny );
363 12 : uno::Reference < io::XOutputStream > xOut = xDocStream->getOutputStream();
364 12 : uno::Reference<io::XActiveDataSource> xSrc(xWriter, uno::UNO_QUERY);
365 6 : xSrc->setOutputStream(xOut);
366 :
367 : uno::Reference<xml::sax::XDocumentHandler> xHandler(xWriter,
368 12 : uno::UNO_QUERY);
369 :
370 12 : SwXMLTextBlockExport aExp( xContext, *this, GetXMLToken ( XML_UNFORMATTED_TEXT ), xHandler);
371 :
372 6 : aExp.exportDoc( rText );
373 :
374 12 : uno::Reference < embed::XTransactedObject > xTrans( xRoot, uno::UNO_QUERY );
375 6 : if ( xTrans.is() )
376 6 : xTrans->commit();
377 :
378 6 : if (! (nFlags & SWXML_NOROOTCOMMIT) )
379 : {
380 6 : uno::Reference < embed::XTransactedObject > xTmpTrans( xBlkRoot, uno::UNO_QUERY );
381 6 : if ( xTmpTrans.is() )
382 6 : xTmpTrans->commit();
383 6 : }
384 : }
385 0 : catch ( uno::Exception& )
386 : {
387 0 : nRes = ERR_SWG_WRITE_ERROR;
388 : }
389 :
390 6 : xRoot = 0;
391 :
392 : //TODO/LATER: error handling
393 : /*
394 : sal_uLong nErr = xBlkRoot->GetError();
395 : sal_uLong nRes = 0;
396 : if( nErr == SVSTREAM_DISK_FULL )
397 : nRes = ERR_W4W_WRITE_FULL;
398 : else if( nErr != SVSTREAM_OK )
399 : nRes = ERR_SWG_WRITE_ERROR;
400 : */
401 6 : if( !nRes ) // damit ueber GetText & nCur aufs Doc zugegriffen
402 6 : MakeBlockText( rText );
403 :
404 12 : return nRes;
405 : }
406 :
407 59 : void SwXMLTextBlocks::ReadInfo( void )
408 : {
409 : try
410 : {
411 59 : const OUString sDocName( XMLN_BLOCKLIST );
412 118 : uno::Reference < container::XNameAccess > xAccess( xBlkRoot, uno::UNO_QUERY );
413 59 : if ( xAccess.is() && xAccess->hasByName( sDocName ) && xBlkRoot->isStreamElement( sDocName ) )
414 : {
415 : uno::Reference< uno::XComponentContext > xContext =
416 57 : comphelper::getProcessComponentContext();
417 :
418 114 : xml::sax::InputSource aParserInput;
419 57 : aParserInput.sSystemId = sDocName;
420 :
421 114 : uno::Reference < io::XStream > xDocStream = xBlkRoot->openStreamElement( sDocName, embed::ElementModes::READ );
422 57 : aParserInput.aInputStream = xDocStream->getInputStream();
423 :
424 : // get filter
425 114 : uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLBlockListImport( xContext, *this );
426 :
427 : // connect parser and filter
428 114 : uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
429 57 : xParser->setDocumentHandler( xFilter );
430 :
431 : // parse
432 : try
433 : {
434 57 : xParser->parseStream( aParserInput );
435 : }
436 0 : catch( xml::sax::SAXParseException& )
437 : {
438 : // re throw ?
439 : }
440 0 : catch( xml::sax::SAXException& )
441 : {
442 : // re throw ?
443 : }
444 0 : catch( io::IOException& )
445 : {
446 : // re throw ?
447 57 : }
448 59 : }
449 : }
450 0 : catch ( uno::Exception& )
451 : {
452 : }
453 59 : }
454 17 : void SwXMLTextBlocks::WriteInfo( void )
455 : {
456 17 : if ( xBlkRoot.is() || 0 == OpenFile ( sal_False ) )
457 : {
458 : uno::Reference< uno::XComponentContext > xContext =
459 17 : comphelper::getProcessComponentContext();
460 :
461 34 : uno::Reference < xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext);
462 34 : OUString sDocName( XMLN_BLOCKLIST );
463 :
464 : /*
465 : if ( xBlkRoot->IsContained( sDocName) )
466 : {
467 : xBlkRoot->Remove ( sDocName );
468 : xBlkRoot->Commit();
469 : }
470 : */
471 :
472 : try
473 : {
474 17 : uno::Reference < io::XStream > xDocStream = xBlkRoot->openStreamElement( sDocName,
475 17 : embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE );
476 :
477 34 : uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY );
478 34 : OUString aMime ( "text/xml" );
479 34 : Any aAny;
480 17 : aAny <<= aMime;
481 17 : xSet->setPropertyValue("MediaType", aAny );
482 34 : uno::Reference < io::XOutputStream > xOut = xDocStream->getOutputStream();
483 34 : uno::Reference<io::XActiveDataSource> xSrc(xWriter, uno::UNO_QUERY);
484 17 : xSrc->setOutputStream(xOut);
485 :
486 34 : uno::Reference<xml::sax::XDocumentHandler> xHandler(xWriter, uno::UNO_QUERY);
487 :
488 34 : SwXMLBlockListExport aExp( xContext, *this, OUString(XMLN_BLOCKLIST), xHandler);
489 :
490 17 : aExp.exportDoc( XML_BLOCK_LIST );
491 :
492 34 : uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY );
493 17 : if ( xTrans.is() )
494 34 : xTrans->commit();
495 : }
496 0 : catch ( uno::Exception& )
497 : {
498 : }
499 :
500 17 : bInfoChanged = sal_False;
501 34 : return;
502 : }
503 : }
504 :
505 0 : sal_uLong SwXMLTextBlocks::SetMacroTable(
506 : sal_uInt16 nIdx,
507 : const SvxMacroTableDtor& rMacroTbl,
508 : sal_Bool bFileAlreadyOpen )
509 : {
510 : // set current autotext
511 0 : aShort = aNames[nIdx]->aShort;
512 0 : aLong = aNames[nIdx]->aLong;
513 0 : aPackageName = aNames[nIdx]->aPackageName;
514 :
515 : // start XML autotext event export
516 0 : sal_uLong nRes = 0;
517 :
518 : uno::Reference< uno::XComponentContext > xContext =
519 0 : comphelper::getProcessComponentContext();
520 :
521 : // Get model
522 : uno::Reference< lang::XComponent > xModelComp(
523 0 : pDoc->GetDocShell()->GetModel(), UNO_QUERY );
524 : OSL_ENSURE( xModelComp.is(), "XMLWriter::Write: got no model" );
525 0 : if( !xModelComp.is() )
526 0 : return ERR_SWG_WRITE_ERROR;
527 :
528 : // open stream in proper sub-storage
529 0 : if( !bFileAlreadyOpen )
530 : {
531 0 : CloseFile(); // close (it may be open in read-only-mode)
532 0 : nRes = OpenFile ( sal_False );
533 : }
534 :
535 0 : if ( 0 == nRes )
536 : {
537 : try
538 : {
539 0 : xRoot = xBlkRoot->openStorageElement( aPackageName, embed::ElementModes::WRITE );
540 0 : OUString sStreamName("atevent.xml" );
541 0 : long nTmp = SOT_FORMATSTR_ID_STARWRITER_60;
542 0 : bool bOasis = ( SotStorage::GetVersion( xRoot ) > nTmp );
543 :
544 0 : uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( sStreamName,
545 0 : embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE );
546 :
547 0 : uno::Reference < beans::XPropertySet > xSet( xDocStream, uno::UNO_QUERY );
548 0 : OUString aMime( "text/xml" );
549 0 : Any aAny;
550 0 : aAny <<= aMime;
551 0 : xSet->setPropertyValue("MediaType", aAny );
552 0 : uno::Reference < io::XOutputStream > xOutputStream = xDocStream->getOutputStream();
553 :
554 : // get XML writer
555 : uno::Reference< xml::sax::XWriter > xSaxWriter =
556 0 : xml::sax::Writer::create( xContext );
557 :
558 : // connect XML writer to output stream
559 0 : xSaxWriter->setOutputStream( xOutputStream );
560 : uno::Reference<xml::sax::XDocumentHandler> xDocHandler(
561 0 : xSaxWriter, UNO_QUERY);
562 :
563 : // construct events object
564 : uno::Reference<XNameAccess> xEvents =
565 0 : new SvMacroTableEventDescriptor(rMacroTbl,aAutotextEvents);
566 :
567 : // prepare arguments (prepend doc handler to given arguments)
568 0 : Sequence<Any> aParams(2);
569 0 : aParams[0] <<= xDocHandler;
570 0 : aParams[1] <<= xEvents;
571 :
572 :
573 : // get filter component
574 : OUString sFilterComponent = bOasis
575 : ? OUString("com.sun.star.comp.Writer.XMLOasisAutotextEventsExporter")
576 0 : : OUString("com.sun.star.comp.Writer.XMLAutotextEventsExporter");
577 : uno::Reference< document::XExporter > xExporter(
578 0 : xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
579 0 : sFilterComponent, aParams, xContext), UNO_QUERY);
580 : OSL_ENSURE( xExporter.is(),
581 : "can't instantiate export filter component" );
582 0 : if( xExporter.is() )
583 : {
584 : // connect model and filter
585 0 : xExporter->setSourceDocument( xModelComp );
586 :
587 : // filter!
588 0 : Sequence<beans::PropertyValue> aFilterProps( 0 );
589 : uno::Reference < document::XFilter > xFilter( xExporter,
590 0 : UNO_QUERY );
591 0 : xFilter->filter( aFilterProps );
592 : }
593 : else
594 0 : nRes = ERR_SWG_WRITE_ERROR;
595 :
596 : // finally, commit stream, sub-storage and storage
597 0 : uno::Reference < embed::XTransactedObject > xTmpTrans( xRoot, uno::UNO_QUERY );
598 0 : if ( xTmpTrans.is() )
599 0 : xTmpTrans->commit();
600 :
601 0 : if ( !bFileAlreadyOpen )
602 : {
603 0 : uno::Reference < embed::XTransactedObject > xTrans( xBlkRoot, uno::UNO_QUERY );
604 0 : if ( xTrans.is() )
605 0 : xTrans->commit();
606 : }
607 :
608 0 : xRoot = 0;
609 : }
610 0 : catch ( uno::Exception& )
611 : {
612 0 : nRes = ERR_SWG_WRITE_ERROR;
613 : }
614 :
615 0 : if( !bFileAlreadyOpen )
616 0 : CloseFile();
617 : }
618 : else
619 0 : nRes = ERR_SWG_WRITE_ERROR;
620 :
621 0 : return nRes;
622 99 : }
623 :
624 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|