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 <rtl/logfile.hxx>
21 : #include <rtl/strbuf.hxx>
22 : #include <com/sun/star/container/XChild.hpp>
23 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
24 : #include <com/sun/star/embed/ElementModes.hpp>
25 : #include <com/sun/star/xml/sax/SAXParseException.hpp>
26 : #include <comphelper/processfactory.hxx>
27 : #include <sfx2/docfile.hxx>
28 : #include <sfx2/docfilt.hxx>
29 : #include "drawdoc.hxx"
30 : #include <unotools/streamwrap.hxx>
31 : #include <svx/xmlgrhlp.hxx>
32 :
33 : #include "../../ui/inc/DrawDocShell.hxx"
34 :
35 : #include "sdxmlwrp.hxx"
36 : #include "strmname.h"
37 : #include <svx/xmleohlp.hxx>
38 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
39 : #include <com/sun/star/document/XFilter.hpp>
40 : #include <com/sun/star/document/XImporter.hpp>
41 : #include <com/sun/star/document/XExporter.hpp>
42 : #include <com/sun/star/lang/XServiceInfo.hpp>
43 : #include <com/sun/star/document/XGraphicObjectResolver.hpp>
44 : #include <com/sun/star/beans/PropertyAttribute.hpp>
45 : #include <com/sun/star/container/XNameAccess.hpp>
46 : #include <com/sun/star/packages/zip/ZipIOException.hpp>
47 :
48 : #include <com/sun/star/xml/sax/XErrorHandler.hpp>
49 : #include <com/sun/star/xml/sax/XEntityResolver.hpp>
50 : #include <com/sun/star/xml/sax/InputSource.hpp>
51 : #include <com/sun/star/xml/sax/XDTDHandler.hpp>
52 : #include <com/sun/star/xml/sax/Parser.hpp>
53 : #include <com/sun/star/xml/sax/Writer.hpp>
54 : #include <com/sun/star/io/XActiveDataSource.hpp>
55 : #include <com/sun/star/io/XActiveDataControl.hpp>
56 : #include <comphelper/componentcontext.hxx>
57 : #include <comphelper/genericpropertyset.hxx>
58 : #include <comphelper/propertysetinfo.hxx>
59 : #include <unotools/saveopt.hxx>
60 :
61 : // include necessary for XML progress bar at load time
62 : #include <svl/itemset.hxx>
63 : #include <svl/stritem.hxx>
64 : #include <svtools/sfxecode.hxx>
65 :
66 : #include "sderror.hxx"
67 : #include "sdresid.hxx"
68 : #include "glob.hrc"
69 :
70 : #include <sfx2/frame.hxx>
71 :
72 : using rtl::OUString;
73 : using namespace com::sun::star;
74 : using namespace com::sun::star::uno;
75 : using namespace com::sun::star::lang;
76 : using namespace com::sun::star::document;
77 : using namespace comphelper;
78 :
79 : #define SD_XML_READERROR 1234
80 :
81 : extern void TransformOOo2xDocument( SdDrawDocument* pDocument );
82 :
83 : //////////////////////////////////////////////////////////////////////////////
84 :
85 : #ifndef SEQTYPE
86 : #if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
87 : #define SEQTYPE(x) (new ::com::sun::star::uno::Type( x ))
88 : #else
89 : #define SEQTYPE(x) &(x)
90 : #endif
91 : #endif
92 :
93 : #define MAP_LEN(x) x, sizeof(x) - 1
94 :
95 : #define XML_STRING(i, x) sal_Char const i[sizeof(x)] = x
96 :
97 : XML_STRING( sXML_metaStreamName, "meta.xml");
98 : XML_STRING( sXML_styleStreamName, "styles.xml" );
99 : XML_STRING( sXML_contentStreamName, "content.xml" );
100 : XML_STRING( sXML_oldContentStreamName, "Content.xml" );
101 : XML_STRING( sXML_settingsStreamName, "settings.xml" );
102 :
103 : XML_STRING( sXML_export_impress_oasis_service, "com.sun.star.comp.Impress.XMLOasisExporter" );
104 : XML_STRING( sXML_export_impress_meta_oasis_service, "com.sun.star.comp.Impress.XMLOasisMetaExporter" );
105 : XML_STRING( sXML_export_impress_styles_oasis_service, "com.sun.star.comp.Impress.XMLOasisStylesExporter" );
106 : XML_STRING( sXML_export_impress_content_oasis_service, "com.sun.star.comp.Impress.XMLOasisContentExporter" );
107 : XML_STRING( sXML_export_impress_settings_oasis_service, "com.sun.star.comp.Impress.XMLOasisSettingsExporter" );
108 :
109 : XML_STRING( sXML_export_draw_oasis_service, "com.sun.star.comp.Draw.XMLOasisExporter" );
110 : XML_STRING( sXML_export_draw_meta_oasis_service, "com.sun.star.comp.Draw.XMLOasisMetaExporter" );
111 : XML_STRING( sXML_export_draw_styles_oasis_service, "com.sun.star.comp.Draw.XMLOasisStylesExporter" );
112 : XML_STRING( sXML_export_draw_content_oasis_service, "com.sun.star.comp.Draw.XMLOasisContentExporter" );
113 : XML_STRING( sXML_export_draw_settings_oasis_service, "com.sun.star.comp.Draw.XMLOasisSettingsExporter" );
114 :
115 : XML_STRING( sXML_import_impress_oasis_service, "com.sun.star.comp.Impress.XMLOasisImporter" );
116 : XML_STRING( sXML_import_impress_meta_oasis_service, "com.sun.star.comp.Impress.XMLOasisMetaImporter" );
117 : XML_STRING( sXML_import_impress_styles_oasis_service, "com.sun.star.comp.Impress.XMLOasisStylesImporter" );
118 : XML_STRING( sXML_import_impress_content_oasis_service, "com.sun.star.comp.Impress.XMLOasisContentImporter" );
119 : XML_STRING( sXML_import_impress_settings_oasis_service, "com.sun.star.comp.Impress.XMLOasisSettingsImporter" );
120 :
121 : XML_STRING( sXML_import_draw_oasis_service, "com.sun.star.comp.Draw.XMLOasisImporter" );
122 : XML_STRING( sXML_import_draw_meta_oasis_service, "com.sun.star.comp.Draw.XMLOasisMetaImporter" );
123 : XML_STRING( sXML_import_draw_styles_oasis_service, "com.sun.star.comp.Draw.XMLOasisStylesImporter" );
124 : XML_STRING( sXML_import_draw_content_oasis_service, "com.sun.star.comp.Draw.XMLOasisContentImporter" );
125 : XML_STRING( sXML_import_draw_settings_oasis_service, "com.sun.star.comp.Draw.XMLOasisSettingsImporter" );
126 :
127 : // OOo
128 : XML_STRING( sXML_export_impress_ooo_service, "com.sun.star.comp.Impress.XMLExporter" );
129 : XML_STRING( sXML_export_impress_meta_ooo_service, "com.sun.star.comp.Impress.XMLMetaExporter" );
130 : XML_STRING( sXML_export_impress_styles_ooo_service, "com.sun.star.comp.Impress.XMLStylesExporter" );
131 : XML_STRING( sXML_export_impress_content_ooo_service, "com.sun.star.comp.Impress.XMLContentExporter" );
132 : XML_STRING( sXML_export_impress_settings_ooo_service, "com.sun.star.comp.Impress.XMLSettingsExporter" );
133 :
134 : XML_STRING( sXML_export_draw_ooo_service, "com.sun.star.comp.Draw.XMLExporter" );
135 : XML_STRING( sXML_export_draw_meta_ooo_service, "com.sun.star.comp.Draw.XMLMetaExporter" );
136 : XML_STRING( sXML_export_draw_styles_ooo_service, "com.sun.star.comp.Draw.XMLStylesExporter" );
137 : XML_STRING( sXML_export_draw_content_ooo_service, "com.sun.star.comp.Draw.XMLContentExporter" );
138 : XML_STRING( sXML_export_draw_settings_ooo_service, "com.sun.star.comp.Draw.XMLSettingsExporter" );
139 :
140 : XML_STRING( sXML_import_impress_ooo_service, "com.sun.star.comp.Impress.XMLImporter" );
141 : XML_STRING( sXML_import_impress_meta_ooo_service, "com.sun.star.comp.Impress.XMLMetaImporter" );
142 : XML_STRING( sXML_import_impress_styles_ooo_service, "com.sun.star.comp.Impress.XMLStylesImporter" );
143 : XML_STRING( sXML_import_impress_content_ooo_service, "com.sun.star.comp.Impress.XMLContentImporter" );
144 : XML_STRING( sXML_import_impress_settings_ooo_service, "com.sun.star.comp.Impress.XMLSettingsImporter" );
145 :
146 : XML_STRING( sXML_import_draw_ooo_service, "com.sun.star.comp.Draw.XMLImporter" );
147 : XML_STRING( sXML_import_draw_meta_ooo_service, "com.sun.star.comp.Draw.XMLMetaImporter" );
148 : XML_STRING( sXML_import_draw_styles_ooo_service, "com.sun.star.comp.Draw.XMLStylesImporter" );
149 : XML_STRING( sXML_import_draw_content_ooo_service, "com.sun.star.comp.Draw.XMLContentImporter" );
150 : XML_STRING( sXML_import_draw_settings_ooo_service, "com.sun.star.comp.Draw.XMLSettingsImporter" );
151 :
152 : struct XML_SERVICEMAP
153 : {
154 : const sal_Char* mpService;
155 : const sal_Char* mpStream;
156 : };
157 :
158 : struct XML_SERVICES
159 : {
160 : const sal_Char* mpAll;
161 : const sal_Char* mpMeta;
162 : const sal_Char* mpStyles;
163 : const sal_Char* mpContent;
164 : const sal_Char* mpSettings;
165 : };
166 :
167 2 : XML_SERVICES* getServices( bool bImport, bool bDraw, sal_uLong nStoreVer )
168 : {
169 : static XML_SERVICES gServices[] =
170 : {
171 : { sXML_export_impress_oasis_service, sXML_export_impress_meta_oasis_service, sXML_export_impress_styles_oasis_service, sXML_export_impress_content_oasis_service, sXML_export_impress_settings_oasis_service },
172 : { sXML_export_draw_oasis_service, sXML_export_draw_meta_oasis_service, sXML_export_draw_styles_oasis_service, sXML_export_draw_content_oasis_service, sXML_export_draw_settings_oasis_service },
173 : { sXML_import_impress_oasis_service, sXML_import_impress_meta_oasis_service, sXML_import_impress_styles_oasis_service, sXML_import_impress_content_oasis_service, sXML_import_impress_settings_oasis_service },
174 : { sXML_import_draw_oasis_service, sXML_import_draw_meta_oasis_service, sXML_import_draw_styles_oasis_service, sXML_import_draw_content_oasis_service, sXML_import_draw_settings_oasis_service },
175 :
176 : { sXML_export_impress_ooo_service, sXML_export_impress_meta_ooo_service, sXML_export_impress_styles_ooo_service, sXML_export_impress_content_ooo_service, sXML_export_impress_settings_ooo_service },
177 : { sXML_export_draw_ooo_service, sXML_export_draw_meta_ooo_service, sXML_export_draw_styles_ooo_service, sXML_export_draw_content_ooo_service, sXML_export_draw_settings_ooo_service },
178 : { sXML_import_impress_ooo_service, sXML_import_impress_meta_ooo_service, sXML_import_impress_styles_ooo_service, sXML_import_impress_content_ooo_service, sXML_import_impress_settings_ooo_service },
179 : { sXML_import_draw_ooo_service, sXML_import_draw_meta_ooo_service, sXML_import_draw_styles_ooo_service, sXML_import_draw_content_ooo_service, sXML_import_draw_settings_ooo_service },
180 : };
181 :
182 2 : return &gServices[ (bImport ? 2 : 0) + ((nStoreVer == SOFFICE_FILEFORMAT_60) ? 4 : 0) + (bDraw ? 1 : 0 ) ];
183 : }
184 :
185 :
186 : // ----------------
187 : // - SdXMLWrapper -
188 : // ----------------
189 :
190 2 : SdXMLFilter::SdXMLFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell, sal_Bool bShowProgress, SdXMLFilterMode eFilterMode, sal_uLong nStoreVer ) :
191 2 : SdFilter( rMedium, rDocShell, bShowProgress ), meFilterMode( eFilterMode ), mnStoreVer( nStoreVer )
192 : {
193 2 : }
194 :
195 2 : SdXMLFilter::~SdXMLFilter(void)
196 : {
197 2 : }
198 :
199 8 : sal_Int32 ReadThroughComponent(
200 : Reference<io::XInputStream> xInputStream,
201 : Reference<XComponent> xModelComponent,
202 : const String& rStreamName,
203 : Reference<lang::XMultiServiceFactory> & rFactory,
204 : const sal_Char* pFilterName,
205 : Sequence<Any> rFilterArguments,
206 : const OUString& rName,
207 : sal_Bool bMustBeSuccessfull,
208 : sal_Bool bEncrypted )
209 : {
210 : DBG_ASSERT(xInputStream.is(), "input stream missing");
211 : DBG_ASSERT(xModelComponent.is(), "document missing");
212 : DBG_ASSERT(rFactory.is(), "factory missing");
213 : DBG_ASSERT(NULL != pFilterName,"I need a service name for the component!");
214 :
215 : RTL_LOGFILE_CONTEXT( aLog, "ReadThroughComponent" );
216 :
217 : // prepare ParserInputSrouce
218 8 : xml::sax::InputSource aParserInput;
219 8 : aParserInput.sSystemId = rName;
220 8 : aParserInput.aInputStream = xInputStream;
221 :
222 : // get parser
223 8 : Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(comphelper::getComponentContext(rFactory));
224 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "parser created" );
225 :
226 : // get filter
227 8 : OUString aFilterName(OUString::createFromAscii(pFilterName));
228 : Reference< xml::sax::XDocumentHandler > xFilter(
229 8 : rFactory->createInstanceWithArguments(aFilterName, rFilterArguments),
230 8 : UNO_QUERY );
231 : SAL_WARN_IF(!xFilter.is(), "sd", "Can't instantiate filter component: " << aFilterName);
232 8 : if( !xFilter.is() )
233 0 : return SD_XML_READERROR;
234 : RTL_LOGFILE_CONTEXT_TRACE1( aLog, "%s created", pFilterName );
235 :
236 : // connect parser and filter
237 8 : xParser->setDocumentHandler( xFilter );
238 :
239 : // connect model and filter
240 8 : Reference < XImporter > xImporter( xFilter, UNO_QUERY );
241 8 : xImporter->setTargetDocument( xModelComponent );
242 : // finally, parser the stream
243 : RTL_LOGFILE_CONTEXT_TRACE( aLog, "parsing stream" );
244 : try
245 : {
246 8 : xParser->parseStream( aParserInput );
247 : }
248 0 : catch (const xml::sax::SAXParseException& r)
249 : {
250 : // sax parser sends wrapped exceptions,
251 : // try to find the original one
252 0 : xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
253 0 : sal_Bool bTryChild = sal_True;
254 :
255 0 : while( bTryChild )
256 : {
257 0 : xml::sax::SAXException aTmp;
258 0 : if ( aSaxEx.WrappedException >>= aTmp )
259 0 : aSaxEx = aTmp;
260 : else
261 0 : bTryChild = sal_False;
262 0 : }
263 :
264 0 : packages::zip::ZipIOException aBrokenPackage;
265 0 : if ( aSaxEx.WrappedException >>= aBrokenPackage )
266 0 : return ERRCODE_IO_BROKENPACKAGE;
267 :
268 0 : if( bEncrypted )
269 0 : return ERRCODE_SFX_WRONGPASSWORD;
270 :
271 : #if OSL_DEBUG_LEVEL > 1
272 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
273 : "SAX parse exception caught while importing:\n"));
274 : aError.append(rtl::OUStringToOString(r.Message,
275 : RTL_TEXTENCODING_ASCII_US));
276 : OSL_FAIL(aError.getStr());
277 : #endif
278 :
279 0 : String sErr( String::CreateFromInt32( r.LineNumber ));
280 0 : sErr += ',';
281 0 : sErr += String::CreateFromInt32( r.ColumnNumber );
282 :
283 0 : if( rStreamName.Len() )
284 : {
285 : return *new TwoStringErrorInfo(
286 : (bMustBeSuccessfull ? ERR_FORMAT_FILE_ROWCOL
287 : : WARN_FORMAT_FILE_ROWCOL),
288 : rStreamName, sErr,
289 0 : ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
290 : }
291 : else
292 : {
293 : DBG_ASSERT( bMustBeSuccessfull, "Warnings are not supported" );
294 : return *new StringErrorInfo( ERR_FORMAT_ROWCOL, sErr,
295 0 : ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
296 0 : }
297 : }
298 0 : catch (const xml::sax::SAXException& r)
299 : {
300 0 : packages::zip::ZipIOException aBrokenPackage;
301 0 : if ( r.WrappedException >>= aBrokenPackage )
302 0 : return ERRCODE_IO_BROKENPACKAGE;
303 :
304 0 : if( bEncrypted )
305 0 : return ERRCODE_SFX_WRONGPASSWORD;
306 :
307 : #if OSL_DEBUG_LEVEL > 1
308 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
309 : "SAX exception caught while importing:\n"));
310 : aError.append(rtl::OUStringToOString(r.Message,
311 : RTL_TEXTENCODING_ASCII_US));
312 : OSL_FAIL(aError.getStr());
313 : #endif
314 0 : return SD_XML_READERROR;
315 : }
316 0 : catch (const packages::zip::ZipIOException& r)
317 : {
318 : #if OSL_DEBUG_LEVEL > 1
319 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
320 : "Zip exception caught while importing:\n"));
321 : aError.append(rtl::OUStringToOString(r.Message,
322 : RTL_TEXTENCODING_ASCII_US));
323 : OSL_FAIL(aError.getStr());
324 : #else
325 : (void)r;
326 : #endif
327 0 : return ERRCODE_IO_BROKENPACKAGE;
328 : }
329 0 : catch (const io::IOException& r)
330 : {
331 : #if OSL_DEBUG_LEVEL > 1
332 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
333 : "IO exception caught while importing:\n"));
334 : aError.append(rtl::OUStringToOString(r.Message,
335 : RTL_TEXTENCODING_ASCII_US));
336 : OSL_FAIL(aError.getStr());
337 : #else
338 : (void)r;
339 : #endif
340 0 : return SD_XML_READERROR;
341 : }
342 0 : catch (const uno::Exception& r)
343 : {
344 : #if OSL_DEBUG_LEVEL > 1
345 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
346 : "uno exception caught while importing:\n"));
347 : aError.append(rtl::OUStringToOString(r.Message,
348 : RTL_TEXTENCODING_ASCII_US));
349 : OSL_FAIL(aError.getStr());
350 : #else
351 : (void)r;
352 : #endif
353 0 : return SD_XML_READERROR;
354 : }
355 :
356 : // success!
357 8 : return 0;
358 : }
359 :
360 8 : sal_Int32 ReadThroughComponent(
361 : const uno::Reference < embed::XStorage >& xStorage,
362 : Reference<XComponent> xModelComponent,
363 : const sal_Char* pStreamName,
364 : const sal_Char* pCompatibilityStreamName,
365 : Reference<lang::XMultiServiceFactory> & rFactory,
366 : const sal_Char* pFilterName,
367 : Sequence<Any> rFilterArguments,
368 : const OUString& rName,
369 : sal_Bool bMustBeSuccessfull )
370 : {
371 : DBG_ASSERT(xStorage.is(), "Need storage!");
372 : DBG_ASSERT(NULL != pStreamName, "Please, please, give me a name!");
373 :
374 : // open stream (and set parser input)
375 8 : OUString sStreamName = OUString::createFromAscii(pStreamName);
376 8 : sal_Bool bContainsStream = sal_False;
377 : try
378 : {
379 8 : bContainsStream = xStorage->isStreamElement(sStreamName);
380 : }
381 0 : catch (const container::NoSuchElementException&)
382 : {
383 : }
384 :
385 8 : if (!bContainsStream )
386 : {
387 : // stream name not found! Then try the compatibility name.
388 : // if no stream can be opened, return immediatly with OK signal
389 :
390 : // do we even have an alternative name?
391 0 : if ( NULL == pCompatibilityStreamName )
392 0 : return 0;
393 :
394 : // if so, does the stream exist?
395 0 : sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
396 : try
397 : {
398 0 : bContainsStream = xStorage->isStreamElement(sStreamName);
399 : }
400 0 : catch (const container::NoSuchElementException&)
401 : {
402 : }
403 :
404 0 : if (! bContainsStream )
405 0 : return 0;
406 : }
407 :
408 : // set Base URL
409 8 : uno::Reference< beans::XPropertySet > xInfoSet;
410 8 : if( rFilterArguments.getLength() > 0 )
411 8 : rFilterArguments.getConstArray()[0] >>= xInfoSet;
412 : DBG_ASSERT( xInfoSet.is(), "missing property set" );
413 8 : if( xInfoSet.is() )
414 : {
415 8 : OUString sPropName( "StreamName" );
416 8 : xInfoSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
417 : }
418 :
419 : try
420 : {
421 : // get input stream
422 : Reference <io::XStream> xStream =
423 8 : xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
424 8 : Reference <beans::XPropertySet > xProps( xStream, uno::UNO_QUERY );
425 8 : if ( !xStream.is() || ! xProps.is() )
426 0 : return SD_XML_READERROR;
427 :
428 8 : Any aAny = xProps->getPropertyValue( "Encrypted" );
429 :
430 8 : sal_Bool bEncrypted = aAny.getValueType() == ::getBooleanCppuType() &&
431 8 : *(sal_Bool *)aAny.getValue();
432 :
433 8 : Reference <io::XInputStream> xInputStream = xStream->getInputStream();
434 :
435 : // read from the stream
436 : return ReadThroughComponent(
437 : xInputStream, xModelComponent, sStreamName, rFactory,
438 : pFilterName, rFilterArguments,
439 8 : rName, bMustBeSuccessfull, bEncrypted );
440 : }
441 0 : catch (const packages::WrongPasswordException&)
442 : {
443 0 : return ERRCODE_SFX_WRONGPASSWORD;
444 : }
445 0 : catch (const packages::zip::ZipIOException&)
446 : {
447 0 : return ERRCODE_IO_BROKENPACKAGE;
448 : }
449 0 : catch (const uno::Exception&)
450 : {}
451 :
452 0 : return SD_XML_READERROR;
453 : }
454 :
455 : // -----------------------------------------------------------------------------
456 :
457 2 : sal_Bool SdXMLFilter::Import( ErrCode& nError )
458 : {
459 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sd", "cl93746", "SdXMLFilter::Import" );
460 : #ifdef TIMELOG
461 : rtl::OString aFile(rtl::OUStringToOString(mrMedium.GetName(), RTL_TEXTENCODING_ASCII_US));
462 : RTL_LOGFILE_CONTEXT_TRACE1( aLog, "importing %s", aFile.getStr() );
463 : #endif
464 :
465 2 : sal_uInt32 nRet = 0;
466 :
467 : // Get service factory
468 : Reference< lang::XMultiServiceFactory > xServiceFactory =
469 2 : comphelper::getProcessServiceFactory();
470 : DBG_ASSERT( xServiceFactory.is(),
471 : "XMLReader::Read: got no service manager" );
472 2 : if( !xServiceFactory.is() )
473 0 : return sal_False;
474 :
475 : // -------------------------------------
476 :
477 2 : SdDrawDocument* pDoc = mrDocShell.GetDoc();
478 2 : pDoc->EnableUndo(false);
479 2 : pDoc->NewOrLoadCompleted( NEW_DOC );
480 2 : pDoc->CreateFirstPages();
481 2 : pDoc->StopWorkStartupDelay();
482 :
483 : // -------------------------------------
484 :
485 2 : mxModel->lockControllers();
486 :
487 : // -------------------------------------
488 :
489 : /** property map for import info set */
490 : PropertyMapEntry aImportInfoMap[] =
491 : {
492 : // necessary properties for XML progress bar at load time
493 2 : { MAP_LEN( "ProgressRange" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
494 2 : { MAP_LEN( "ProgressMax" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
495 2 : { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
496 2 : { MAP_LEN( "Preview" ), 0, &::getCppuType((const sal_Bool*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
497 2 : { MAP_LEN( "PageLayouts" ), 0, SEQTYPE(::getCppuType((const uno::Reference< container::XNameAccess >*)0)), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
498 : { MAP_LEN( "PrivateData" ), 0,
499 2 : &::getCppuType( (Reference<XInterface> *)0 ),
500 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
501 : { MAP_LEN( "BaseURI" ), 0,
502 2 : &::getCppuType( (OUString *)0 ),
503 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
504 : { MAP_LEN( "StreamRelPath" ), 0,
505 2 : &::getCppuType( (OUString *)0 ),
506 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
507 : { MAP_LEN( "StreamName" ), 0,
508 2 : &::getCppuType( (OUString *)0 ),
509 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
510 : { MAP_LEN( "BuildId" ), 0,
511 2 : &::getCppuType( (OUString *)0 ),
512 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
513 : { MAP_LEN( "OrganizerMode" ), 0,
514 2 : &::getBooleanCppuType(),
515 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
516 2 : { MAP_LEN( "SourceStorage" ), 0, &embed::XStorage::static_type(),
517 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
518 : { NULL, 0, 0, NULL, 0, 0 }
519 26 : };
520 :
521 2 : uno::Reference< beans::XPropertySet > xInfoSet( GenericPropertySet_CreateInstance( new PropertySetInfo( aImportInfoMap ) ) );
522 2 : xInfoSet->setPropertyValue( "Preview" , uno::makeAny( mrDocShell.GetDoc()->IsStarDrawPreviewMode() ) );
523 :
524 : // ---- get BuildId from parent container if available
525 :
526 2 : uno::Reference< container::XChild > xChild( mxModel, uno::UNO_QUERY );
527 2 : if( xChild.is() )
528 : {
529 2 : uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
530 2 : if( xParentSet.is() )
531 : {
532 0 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
533 0 : OUString sPropName( "BuildId" );
534 0 : if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
535 : {
536 0 : xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
537 0 : }
538 2 : }
539 : }
540 :
541 : // -------------------------------------
542 :
543 2 : Reference< io::XActiveDataSource > xSource;
544 2 : Reference< XInterface > xPipe;
545 2 : Reference< document::XGraphicObjectResolver > xGraphicResolver;
546 2 : SvXMLGraphicHelper *pGraphicHelper = 0;
547 2 : Reference< document::XEmbeddedObjectResolver > xObjectResolver;
548 2 : SvXMLEmbeddedObjectHelper *pObjectHelper = 0;
549 :
550 2 : Reference< lang::XComponent > xModelComp( mxModel, uno::UNO_QUERY );
551 :
552 : // -------------------------------------
553 :
554 : // try to get an XStatusIndicator from the Medium
555 2 : if( mbShowProgress )
556 : {
557 2 : SfxItemSet* pSet = mrMedium.GetItemSet();
558 2 : if(pSet)
559 : {
560 : const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
561 2 : pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
562 2 : if (pItem)
563 : {
564 0 : pItem->GetValue() >>= mxStatusIndicator;
565 : }
566 : }
567 :
568 2 : if(mxStatusIndicator.is())
569 : {
570 0 : sal_Int32 nProgressRange(1000000);
571 0 : sal_Int32 nProgressCurrent(0);
572 0 : OUString aMsg = String( SdResId( STR_LOAD_DOC ) );
573 0 : mxStatusIndicator->start(aMsg, nProgressRange);
574 :
575 : // set ProgressRange
576 0 : uno::Any aProgRange;
577 0 : aProgRange <<= nProgressRange;
578 0 : xInfoSet->setPropertyValue( "ProgressRange" , aProgRange);
579 :
580 : // set ProgressCurrent
581 0 : uno::Any aProgCurrent;
582 0 : aProgCurrent <<= nProgressCurrent;
583 0 : xInfoSet->setPropertyValue( "ProgressCurrent" , aProgCurrent);
584 : }
585 : }
586 :
587 : // -------------------------------------
588 : // get the input stream (storage or stream)
589 : // -------------------------------------
590 :
591 2 : SvStorageStreamRef xDocStream;
592 2 : Reference<io::XInputStream> xInputStream;
593 2 : uno::Reference < embed::XStorage > xStorage = mrMedium.GetStorage();
594 :
595 2 : OUString sSourceStorage( "SourceStorage");
596 2 : xInfoSet->setPropertyValue( sSourceStorage, Any( xStorage ) );
597 :
598 2 : if( !xStorage.is() )
599 0 : nRet = SD_XML_READERROR;
600 :
601 2 : if( 0 == nRet )
602 : {
603 : pGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
604 : GRAPHICHELPER_MODE_READ,
605 2 : sal_False );
606 2 : xGraphicResolver = pGraphicHelper;
607 : pObjectHelper = SvXMLEmbeddedObjectHelper::Create(
608 2 : xStorage, *pDoc->GetPersist(),
609 : EMBEDDEDOBJECTHELPER_MODE_READ,
610 2 : sal_False );
611 2 : xObjectResolver = pObjectHelper;
612 : }
613 :
614 : // Set base URI
615 2 : xInfoSet->setPropertyValue( "BaseURI" , makeAny( mrMedium.GetBaseURL() ) );
616 :
617 2 : if( 0 == nRet && SFX_CREATE_MODE_EMBEDDED == mrDocShell.GetCreateMode() )
618 : {
619 2 : OUString aName;
620 2 : if ( mrMedium.GetItemSet() )
621 : {
622 : const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
623 2 : mrMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
624 2 : if ( pDocHierarchItem )
625 0 : aName = pDocHierarchItem->GetValue();
626 : }
627 : else
628 0 : aName = "dummyObjectName" ;
629 :
630 2 : if( !aName.isEmpty() )
631 0 : xInfoSet->setPropertyValue( "StreamRelPath", Any( aName ) );
632 : }
633 :
634 2 : if (SDXMLMODE_Organizer == meFilterMode)
635 0 : xInfoSet->setPropertyValue("OrganizerMode", uno::makeAny(sal_True));
636 :
637 : // -------------------------------------
638 :
639 2 : if( 0 == nRet )
640 : {
641 :
642 : // prepare filter arguments
643 2 : Sequence<Any> aFilterArgs( 4 );
644 2 : Any *pArgs = aFilterArgs.getArray();
645 2 : *pArgs++ <<= xInfoSet;
646 2 : *pArgs++ <<= xGraphicResolver;
647 2 : *pArgs++ <<= xObjectResolver;
648 2 : *pArgs++ <<= mxStatusIndicator;
649 :
650 2 : Sequence<Any> aEmptyArgs( 2 );
651 2 : pArgs = aEmptyArgs.getArray();
652 2 : *pArgs++ <<= xInfoSet;
653 2 : *pArgs++ <<= mxStatusIndicator;
654 :
655 2 : const OUString aName( mrMedium.GetName() );
656 :
657 2 : XML_SERVICES* pServices = getServices( true, IsDraw(), mnStoreVer );
658 :
659 2 : sal_uInt32 nWarn = 0;
660 2 : sal_uInt32 nWarn2 = 0;
661 : // read storage streams
662 : // #i103539#: always read meta.xml for generator
663 : nWarn = ReadThroughComponent(
664 : xStorage, xModelComp, "meta.xml", "Meta.xml", xServiceFactory,
665 : pServices->mpMeta,
666 2 : aEmptyArgs, aName, sal_False );
667 :
668 2 : if( meFilterMode != SDXMLMODE_Organizer )
669 : {
670 : nWarn2 = ReadThroughComponent(
671 : xStorage, xModelComp, "settings.xml", NULL, xServiceFactory,
672 : pServices->mpSettings,
673 2 : aFilterArgs, aName, sal_False );
674 : }
675 :
676 : nRet = ReadThroughComponent(
677 : xStorage, xModelComp, "styles.xml", NULL, xServiceFactory,
678 : pServices->mpStyles,
679 2 : aFilterArgs, aName, sal_True );
680 :
681 2 : if( !nRet && (meFilterMode != SDXMLMODE_Organizer) )
682 : nRet = ReadThroughComponent(
683 : xStorage, xModelComp, "content.xml", "Content.xml", xServiceFactory,
684 : pServices->mpContent,
685 2 : aFilterArgs, aName, sal_True );
686 :
687 2 : if( !nRet )
688 : {
689 2 : if( nWarn )
690 0 : nRet = nWarn;
691 2 : else if( nWarn2 )
692 0 : nRet = nWarn2;
693 2 : }
694 : }
695 :
696 : // -------------------------------------
697 2 : if( pGraphicHelper )
698 2 : SvXMLGraphicHelper::Destroy( pGraphicHelper );
699 2 : xGraphicResolver = 0;
700 2 : if( pObjectHelper )
701 2 : SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
702 2 : xObjectResolver = 0;
703 :
704 2 : if( mxStatusIndicator.is() )
705 0 : mxStatusIndicator->end();
706 :
707 2 : if( mxModel.is() )
708 2 : mxModel->unlockControllers();
709 :
710 2 : if( nRet == 0 )
711 2 : pDoc->UpdateAllLinks();
712 :
713 2 : switch( nRet )
714 : {
715 2 : case 0: break;
716 0 : case SD_XML_READERROR: break;
717 : case ERRCODE_IO_BROKENPACKAGE:
718 0 : if( xStorage.is() )
719 : {
720 0 : nError = ERRCODE_IO_BROKENPACKAGE;
721 0 : break;
722 : }
723 : // fall through intented
724 : default:
725 : {
726 : // TODO/LATER: this is completely wrong! Filter code should never call ErrorHandler directly!
727 0 : ErrorHandler::HandleError( nRet );
728 0 : if( IsWarning( nRet ) )
729 0 : nRet = 0;
730 : }
731 : }
732 :
733 :
734 : // clear unused named items from item pool
735 :
736 2 : uno::Reference< lang::XMultiServiceFactory> xModelFactory( mxModel, uno::UNO_QUERY );
737 2 : if( xModelFactory.is() )
738 : {
739 : try
740 : {
741 2 : const OUString aName("~clear~" );
742 2 : uno::Reference< container::XNameContainer > xGradient( xModelFactory->createInstance( "com.sun.star.drawing.GradientTable" ), uno::UNO_QUERY );
743 2 : if( xGradient.is() )
744 2 : xGradient->removeByName( aName );
745 :
746 2 : uno::Reference< container::XNameContainer > xHatch( xModelFactory->createInstance( "com.sun.star.drawing.HatchTable" ), uno::UNO_QUERY );
747 2 : if( xHatch.is() )
748 2 : xHatch->removeByName( aName );
749 :
750 2 : uno::Reference< container::XNameContainer > xBitmap( xModelFactory->createInstance( "com.sun.star.drawing.BitmapTable" ), uno::UNO_QUERY );
751 2 : if( xBitmap.is() )
752 2 : xBitmap->removeByName( aName );
753 :
754 2 : uno::Reference< container::XNameContainer > xTransGradient( xModelFactory->createInstance( "com.sun.star.drawing.TransparencyGradientTable" ), uno::UNO_QUERY );
755 2 : if( xTransGradient.is() )
756 2 : xTransGradient->removeByName( aName );
757 :
758 2 : uno::Reference< container::XNameContainer > xMarker( xModelFactory->createInstance( "com.sun.star.drawing.MarkerTable" ), uno::UNO_QUERY );
759 2 : if( xMarker.is() )
760 2 : xMarker->removeByName( aName );
761 :
762 2 : uno::Reference< container::XNameContainer > xDashes( xModelFactory->createInstance( "com.sun.star.drawing.DashTable" ), uno::UNO_QUERY );
763 2 : if( xDashes.is() )
764 2 : xDashes->removeByName( aName );
765 : }
766 0 : catch (const Exception&)
767 : {
768 : OSL_FAIL("sd::SdXMLFilter::Import(), exception during clearing of unused named items");
769 : }
770 : }
771 :
772 : // set BuildId on XModel for later OLE object loading
773 2 : if( xInfoSet.is() )
774 : {
775 2 : uno::Reference< beans::XPropertySet > xModelSet( mxModel, uno::UNO_QUERY );
776 2 : if( xModelSet.is() )
777 : {
778 2 : uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
779 2 : const OUString sPropName( "BuildId" );
780 :
781 2 : OUString sBuildId;
782 2 : xInfoSet->getPropertyValue(sPropName) >>= sBuildId;
783 :
784 2 : if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sPropName) )
785 : {
786 2 : xModelSet->setPropertyValue( sPropName, Any( sBuildId ) );
787 : }
788 :
789 2 : bool bTransform = false;
790 :
791 2 : if( nRet == 0 )
792 : {
793 2 : if( !sBuildId.isEmpty() )
794 : {
795 2 : sal_Int32 nIndex = sBuildId.indexOf('$');
796 2 : if( nIndex != -1 )
797 : {
798 2 : sal_Int32 nUPD = sBuildId.copy( 0, nIndex ).toInt32();
799 :
800 2 : if( nUPD == 300 )
801 : {
802 0 : sal_Int32 nBuildId = sBuildId.copy( nIndex+1 ).toInt32();
803 0 : if( (nBuildId > 0) && (nBuildId < 9316) )
804 0 : bTransform = true; // treat OOo 3.0 beta1 as OOo 2.x
805 : }
806 2 : else if( (nUPD == 680) || ( nUPD >= 640 && nUPD <= 645 ) )
807 0 : bTransform = true;
808 : }
809 : }
810 : else
811 : {
812 : // check for binary formats
813 0 : const SfxFilter * pFilter = mrMedium.GetFilter();
814 0 : if( pFilter )
815 : {
816 0 : const String& rTypeName = pFilter->GetRealTypeName();
817 :
818 0 : if( (rTypeName.CompareToAscii( RTL_CONSTASCII_STRINGPARAM("impress_StarImpress" ) ) == 0) ||
819 0 : (rTypeName.CompareToAscii( RTL_CONSTASCII_STRINGPARAM("draw_StarDraw" ) ) == 0) )
820 : {
821 0 : bTransform = true;
822 : }
823 : }
824 : }
825 : }
826 :
827 2 : if( bTransform )
828 0 : TransformOOo2xDocument( pDoc );
829 2 : }
830 : }
831 :
832 2 : pDoc->EnableUndo(true);
833 2 : mrDocShell.ClearUndoBuffer();
834 2 : return nRet == 0;
835 : }
836 :
837 : // -----------------------------------------------------------------------------
838 :
839 0 : sal_Bool SdXMLFilter::Export()
840 : {
841 : #ifdef TIMELOG
842 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sd", "cl93746", "SdXMLFilter::Export" );
843 : rtl::OString aFile(rtl::OUStringToOString(mrMedium.GetName(), RTL_TEXTENCODING_ASCII_US));
844 : RTL_LOGFILE_CONTEXT_TRACE1( aLog, "exporting %s", aFile.getStr() );
845 : #endif
846 :
847 0 : SvXMLEmbeddedObjectHelper* pObjectHelper = NULL;
848 0 : SvXMLGraphicHelper* pGraphicHelper = NULL;
849 0 : sal_Bool bDocRet = sal_False;
850 :
851 0 : if( !mxModel.is() )
852 : {
853 : OSL_FAIL("Got NO Model in XMLExport");
854 0 : return sal_False;
855 : }
856 :
857 0 : sal_Bool bLocked = mxModel->hasControllersLocked();
858 :
859 : try
860 : {
861 0 : mxModel->lockControllers();
862 :
863 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel, uno::UNO_QUERY );
864 :
865 0 : if( !xServiceInfo.is() || !xServiceInfo->supportsService( "com.sun.star.drawing.GenericDrawingDocument" ) )
866 : {
867 : OSL_FAIL( "Model is no DrawingDocument in XMLExport" );
868 0 : return sal_False;
869 : }
870 :
871 0 : uno::Reference< lang::XMultiServiceFactory> xServiceFactory( ::comphelper::getProcessServiceFactory() );
872 0 : uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
873 :
874 0 : if( !xServiceFactory.is() )
875 : {
876 : OSL_FAIL( "got no service manager" );
877 0 : return sal_False;
878 : }
879 :
880 0 : uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext );
881 :
882 : /** property map for export info set */
883 : PropertyMapEntry aExportInfoMap[] =
884 : {
885 0 : { MAP_LEN( "ProgressRange" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
886 0 : { MAP_LEN( "ProgressMax" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
887 0 : { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
888 0 : { MAP_LEN( "UsePrettyPrinting"),0, &::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
889 :
890 0 : { MAP_LEN( "PageLayoutNames" ), 0, SEQTYPE(::getCppuType((const OUString*)0)), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
891 : { MAP_LEN( "BaseURI" ), 0,
892 0 : &::getCppuType( (OUString *)0 ),
893 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
894 : { MAP_LEN( "StreamRelPath" ), 0,
895 0 : &::getCppuType( (OUString *)0 ),
896 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
897 : { MAP_LEN( "StreamName" ), 0,
898 0 : &::getCppuType( (OUString *)0 ),
899 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
900 : { MAP_LEN( "StyleNames" ), 0,
901 0 : &::getCppuType( (Sequence<OUString>*)0 ),
902 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
903 : { MAP_LEN( "StyleFamilies" ), 0,
904 0 : &::getCppuType( (Sequence<sal_Int32>*)0 ),
905 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
906 0 : { MAP_LEN( "TargetStorage" ), 0, &embed::XStorage::static_type(),
907 : ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 },
908 :
909 : { NULL, 0, 0, NULL, 0, 0 }
910 0 : };
911 :
912 0 : uno::Reference< beans::XPropertySet > xInfoSet( GenericPropertySet_CreateInstance( new PropertySetInfo( aExportInfoMap ) ) );
913 :
914 :
915 0 : SvtSaveOptions aSaveOpt;
916 0 : OUString sUsePrettyPrinting("UsePrettyPrinting");
917 0 : sal_Bool bUsePrettyPrinting( aSaveOpt.IsPrettyPrinting() );
918 0 : xInfoSet->setPropertyValue( sUsePrettyPrinting, makeAny( bUsePrettyPrinting ) );
919 :
920 0 : const uno::Reference < embed::XStorage >& xStorage = mrMedium.GetOutputStorage();
921 :
922 : // Set base URI
923 0 : OUString sPropName( "BaseURI" );
924 0 : xInfoSet->setPropertyValue( sPropName, makeAny( mrMedium.GetBaseURL( true ) ) );
925 :
926 0 : OUString sTargetStorage( "TargetStorage" );
927 0 : xInfoSet->setPropertyValue( sTargetStorage, Any( xStorage ) );
928 :
929 0 : if( SFX_CREATE_MODE_EMBEDDED == mrDocShell.GetCreateMode() )
930 : {
931 0 : OUString aName;
932 0 : if ( mrMedium.GetItemSet() )
933 : {
934 : const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
935 0 : mrMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
936 0 : if ( pDocHierarchItem )
937 0 : aName = pDocHierarchItem->GetValue();
938 : }
939 :
940 0 : if( !aName.isEmpty() )
941 : {
942 0 : sPropName = OUString( "StreamRelPath" );
943 0 : xInfoSet->setPropertyValue( sPropName, makeAny( aName ) );
944 0 : }
945 : }
946 :
947 : // initialize descriptor
948 0 : uno::Sequence< beans::PropertyValue > aDescriptor( 1 );
949 0 : beans::PropertyValue* pProps = aDescriptor.getArray();
950 :
951 0 : pProps[0].Name = "FileName";
952 0 : pProps[0].Value <<= OUString( mrMedium.GetName() );
953 :
954 : {
955 0 : uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
956 0 : uno::Reference< document::XGraphicObjectResolver > xGrfResolver;
957 :
958 : // create helper for graphic and ole export if we have a storage
959 0 : if( xStorage.is() )
960 : {
961 0 : pObjectHelper = SvXMLEmbeddedObjectHelper::Create( xStorage, *mrDocShell.GetDoc()->GetPersist(), EMBEDDEDOBJECTHELPER_MODE_WRITE, sal_False );
962 0 : xObjectResolver = pObjectHelper;
963 :
964 0 : pGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_WRITE, sal_False );
965 0 : xGrfResolver = pGraphicHelper;
966 : }
967 :
968 0 : if(mbShowProgress)
969 : {
970 0 : CreateStatusIndicator();
971 0 : if(mxStatusIndicator.is())
972 : {
973 0 : sal_Int32 nProgressRange(1000000);
974 0 : sal_Int32 nProgressCurrent(0);
975 0 : OUString aMsg = String( SdResId( STR_SAVE_DOC ) );
976 0 : mxStatusIndicator->start(aMsg, nProgressRange);
977 :
978 : // set ProgressRange
979 0 : uno::Any aProgRange;
980 0 : aProgRange <<= nProgressRange;
981 0 : xInfoSet->setPropertyValue( "ProgressRange" , aProgRange);
982 :
983 : // set ProgressCurrent
984 0 : uno::Any aProgCurrent;
985 0 : aProgCurrent <<= nProgressCurrent;
986 0 : xInfoSet->setPropertyValue( "ProgressCurrent" , aProgCurrent);
987 : }
988 : }
989 :
990 0 : uno::Reference< lang::XComponent > xComponent( mxModel, uno::UNO_QUERY );
991 :
992 0 : XML_SERVICES* pServiceNames = getServices( false, IsDraw(), mnStoreVer );
993 :
994 0 : XML_SERVICEMAP aServices[5]; sal_uInt16 i = 0;
995 0 : aServices[i ].mpService = pServiceNames->mpStyles;
996 0 : aServices[i++].mpStream = sXML_styleStreamName;
997 :
998 0 : aServices[i ].mpService = pServiceNames->mpContent;
999 0 : aServices[i++].mpStream = sXML_contentStreamName;
1000 :
1001 0 : aServices[i ].mpService = pServiceNames->mpSettings;
1002 0 : aServices[i++].mpStream = sXML_settingsStreamName;
1003 :
1004 0 : if( mrDocShell.GetCreateMode() != SFX_CREATE_MODE_EMBEDDED )
1005 : {
1006 0 : aServices[i ].mpService = pServiceNames->mpMeta;
1007 0 : aServices[i++].mpStream = sXML_metaStreamName;
1008 : };
1009 :
1010 0 : aServices[i].mpService = NULL;
1011 0 : aServices[i].mpStream = NULL;
1012 :
1013 0 : XML_SERVICEMAP* pServices = aServices;
1014 :
1015 : // doc export
1016 0 : do
1017 : {
1018 : RTL_LOGFILE_CONTEXT_TRACE1( aLog, "exporting substream %s", pServices->mpStream );
1019 :
1020 0 : uno::Reference<io::XOutputStream> xDocOut;
1021 0 : if( xStorage.is() )
1022 : {
1023 0 : const OUString sDocName( OUString::createFromAscii( pServices->mpStream ) );
1024 : uno::Reference<io::XStream> xStream =
1025 0 : xStorage->openStreamElement( sDocName,
1026 0 : embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
1027 :
1028 : DBG_ASSERT(xStream.is(), "Can't create output stream in package!");
1029 0 : if( !xStream.is() )
1030 0 : return sal_False;
1031 :
1032 0 : xDocOut = xStream->getOutputStream();
1033 0 : Reference <beans::XPropertySet > xProps( xStream, uno::UNO_QUERY );
1034 0 : if( !xDocOut.is() || !xProps.is() )
1035 0 : return sal_False;
1036 :
1037 0 : uno::Any aAny; aAny <<= OUString( "text/xml");
1038 0 : xProps->setPropertyValue( "MediaType" , aAny);
1039 :
1040 : // encrypt all streams
1041 0 : xProps->setPropertyValue( "UseCommonStoragePasswordEncryption",
1042 0 : uno::makeAny( (sal_Bool)sal_True ) );
1043 :
1044 0 : const OUString sStreamName( "StreamName");
1045 0 : xInfoSet->setPropertyValue( sStreamName, Any( sDocName ) );
1046 : }
1047 :
1048 0 : uno::Reference< io::XActiveDataSource > xDocSrc( xWriter, uno::UNO_QUERY );
1049 0 : xDocSrc->setOutputStream( xDocOut );
1050 :
1051 0 : uno::Sequence< uno::Any > aArgs( 2 + ( mxStatusIndicator.is() ? 1 : 0 ) + ( xGrfResolver.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) );
1052 0 : uno::Any* pArgs = aArgs.getArray();
1053 0 : *pArgs++ <<= xInfoSet;
1054 0 : if( xGrfResolver.is() ) *pArgs++ <<= xGrfResolver;
1055 0 : if( xObjectResolver.is() ) *pArgs++ <<= xObjectResolver;
1056 0 : if( mxStatusIndicator.is() ) *pArgs++ <<= mxStatusIndicator;
1057 :
1058 0 : *pArgs <<= xWriter;
1059 :
1060 0 : uno::Reference< document::XFilter > xFilter( xServiceFactory->createInstanceWithArguments( OUString::createFromAscii( pServices->mpService ), aArgs ), uno::UNO_QUERY );
1061 0 : if( xFilter.is() )
1062 : {
1063 0 : uno::Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY );
1064 0 : if( xExporter.is() )
1065 : {
1066 0 : xExporter->setSourceDocument( xComponent );
1067 : // outputstream will be closed by SAX parser
1068 0 : bDocRet = xFilter->filter( aDescriptor );
1069 0 : }
1070 : }
1071 :
1072 0 : pServices++;
1073 : }
1074 : while( bDocRet && pServices->mpService );
1075 :
1076 0 : if(mbShowProgress)
1077 : {
1078 0 : if(mxStatusIndicator.is())
1079 0 : mxStatusIndicator->end();
1080 0 : }
1081 0 : }
1082 : }
1083 0 : catch (const uno::Exception &e)
1084 : {
1085 : #if OSL_DEBUG_LEVEL > 1
1086 : rtl::OStringBuffer aError(RTL_CONSTASCII_STRINGPARAM(
1087 : "uno Exception caught while exporting:\n"));
1088 : aError.append(rtl::OUStringToOString(e.Message,
1089 : RTL_TEXTENCODING_ASCII_US));
1090 : OSL_FAIL(aError.getStr());
1091 : #else
1092 : (void)e;
1093 : #endif
1094 0 : bDocRet = sal_False;
1095 : }
1096 0 : if ( !bLocked )
1097 0 : mxModel->unlockControllers();
1098 :
1099 0 : if( pGraphicHelper )
1100 0 : SvXMLGraphicHelper::Destroy( pGraphicHelper );
1101 :
1102 0 : if( pObjectHelper )
1103 0 : SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
1104 :
1105 0 : return bDocRet;
1106 9 : }
1107 :
1108 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|