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