xref: /trunk/main/sw/source/filter/xml/swxml.cxx (revision 2eda3cbf)
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_sw.hxx"
26 
27 #define _SVSTDARR_STRINGS
28 #include <rsc/rscsfx.hxx>
29 #include <tools/urlobj.hxx>
30 #include <com/sun/star/embed/XStorage.hpp>
31 #include <com/sun/star/embed/ElementModes.hpp>
32 #include <comphelper/processfactory.hxx>
33 #include <comphelper/componentcontext.hxx>
34 #include <com/sun/star/xml/sax/InputSource.hpp>
35 #include <com/sun/star/xml/sax/XParser.hpp>
36 #include <com/sun/star/io/XActiveDataControl.hpp>
37 #include <com/sun/star/text/XTextRange.hpp>
38 #include <com/sun/star/container/XChild.hpp>
39 #include <com/sun/star/beans/XPropertySetInfo.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/beans/NamedValue.hpp>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
44 #include <com/sun/star/io/XActiveDataSource.hpp>
45 #include <com/sun/star/packages/zip/ZipIOException.hpp>
46 #include <com/sun/star/packages/WrongPasswordException.hpp>
47 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
48 #include <svl/svstdarr.hxx>
49 #include <sfx2/docfile.hxx>
50 #include <svtools/sfxecode.hxx>
51 #include <svl/stritem.hxx>
52 #include <unotools/streamwrap.hxx>
53 #include <svx/xmlgrhlp.hxx>
54 #include <svx/xmleohlp.hxx>
55 #include <comphelper/genericpropertyset.hxx>
56 #include <rtl/logfile.hxx>
57 #include <sfx2/frame.hxx>
58 #include <unotools/ucbstreamhelper.hxx>
59 #include <swerror.h>
60 #include <errhdl.hxx>
61 #include <fltini.hxx>
62 #include <doc.hxx>
63 #include <docsh.hxx>
64 #include <unotextrange.hxx>
65 #include <swmodule.hxx>
66 #include <SwXMLSectionList.hxx>
67 #include <statstr.hrc>
68 #include <SwStyleNameMapper.hxx>
69 #include <poolfmt.hxx>
70 #include <numrule.hxx>
71 #include <paratr.hxx>
72 #include <svx/svdmodel.hxx>
73 #include <svx/svdpage.hxx>
74 #include <svx/svditer.hxx>
75 #include <svx/svdoole2.hxx>
76 #include <svx/svdograf.hxx>
77 #include <sfx2/docfilt.hxx>
78 #include <istyleaccess.hxx>
79 #define LOGFILE_AUTHOR "mb93740"
80 #include <sfx2/DocumentMetadataAccess.hxx>
81 #include <drawdoc.hxx>
82 
83 using namespace ::com::sun::star;
84 using namespace ::com::sun::star::uno;
85 using namespace ::com::sun::star::text;
86 using namespace ::com::sun::star::container;
87 using namespace ::com::sun::star::document;
88 using namespace ::com::sun::star::lang;
89 using ::rtl::OUString;
90 
91 
lcl_EnsureValidPam(SwPaM & rPam)92 void lcl_EnsureValidPam( SwPaM& rPam )
93 {
94     if( rPam.GetCntntNode() != NULL )
95     {
96         // set proper point content
97         if( rPam.GetCntntNode() != rPam.GetPoint()->nContent.GetIdxReg() )
98         {
99             rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
100         }
101         // else: point was already valid
102 
103         // if mark is invalid, we delete it
104         if( ( rPam.GetCntntNode( sal_False ) == NULL ) ||
105             ( rPam.GetCntntNode( sal_False ) != rPam.GetMark()->nContent.GetIdxReg() ) )
106         {
107             rPam.DeleteMark();
108         }
109     }
110     else
111     {
112         // point is not valid, so move it into the first content
113         rPam.DeleteMark();
114         rPam.GetPoint()->nNode =
115             *rPam.GetDoc()->GetNodes().GetEndOfContent().StartOfSectionNode();
116         ++ rPam.GetPoint()->nNode;
117         rPam.Move( fnMoveForward, fnGoCntnt ); // go into content
118     }
119 }
120 
XMLReader()121 XMLReader::XMLReader()
122 {
123 }
124 
GetReaderType()125 int XMLReader::GetReaderType()
126 {
127 	return SW_STORAGE_READER;
128 }
129 
130 /// read a component (file + filter version)
ReadThroughComponent(uno::Reference<io::XInputStream> xInputStream,uno::Reference<XComponent> xModelComponent,const String & rStreamName,uno::Reference<lang::XMultiServiceFactory> & rFactory,const sal_Char * pFilterName,const Sequence<Any> & rFilterArguments,const OUString & rName,sal_Bool bMustBeSuccessfull,sal_Bool bEncrypted)131 sal_Int32 ReadThroughComponent(
132 	uno::Reference<io::XInputStream> xInputStream,
133 	uno::Reference<XComponent> xModelComponent,
134 	const String& rStreamName,
135 	uno::Reference<lang::XMultiServiceFactory> & rFactory,
136 	const sal_Char* pFilterName,
137 	const Sequence<Any>& rFilterArguments,
138 	const OUString& rName,
139 	sal_Bool bMustBeSuccessfull,
140 	sal_Bool bEncrypted )
141 {
142 	DBG_ASSERT(xInputStream.is(), "input stream missing");
143 	DBG_ASSERT(xModelComponent.is(), "document missing");
144 	DBG_ASSERT(rFactory.is(), "factory missing");
145 	DBG_ASSERT(NULL != pFilterName,"I need a service name for the component!");
146 
147 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "sw", LOGFILE_AUTHOR, "ReadThroughComponent" );
148 
149 	// prepare ParserInputSrouce
150 	xml::sax::InputSource aParserInput;
151 	aParserInput.sSystemId = rName;
152 	aParserInput.aInputStream = xInputStream;
153 
154 	// get parser
155 	uno::Reference< xml::sax::XParser > xParser(
156 		rFactory->createInstance(
157 			OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
158 		UNO_QUERY );
159 	DBG_ASSERT( xParser.is(), "Can't create parser" );
160 	if( !xParser.is() )
161 		return ERR_SWG_READ_ERROR;
162     RTL_LOGFILE_CONTEXT_TRACE( aLog, "parser created" );
163 
164 	// get filter
165 	uno::Reference< xml::sax::XDocumentHandler > xFilter(
166 		rFactory->createInstanceWithArguments(
167 			OUString::createFromAscii(pFilterName), rFilterArguments),
168 		UNO_QUERY );
169 	DBG_ASSERT( xFilter.is(), "Can't instantiate filter component." );
170 	if( !xFilter.is() )
171 		return ERR_SWG_READ_ERROR;
172     RTL_LOGFILE_CONTEXT_TRACE1( aLog, "%s created", pFilterName );
173 
174 	// connect parser and filter
175 	xParser->setDocumentHandler( xFilter );
176 
177 	// connect model and filter
178 	uno::Reference < XImporter > xImporter( xFilter, UNO_QUERY );
179 	xImporter->setTargetDocument( xModelComponent );
180 
181 
182 #ifdef TIMELOG
183     // if we do profiling, we want to know the stream
184     ByteString aString( (String)rStreamName, RTL_TEXTENCODING_ASCII_US );
185     RTL_LOGFILE_TRACE_AUTHOR1( "sw", LOGFILE_AUTHOR,
186                                "ReadThroughComponent : parsing \"%s\"", aString.GetBuffer() );
187 #endif
188 
189 	// finally, parser the stream
190 	try
191 	{
192 		xParser->parseStream( aParserInput );
193 	}
194 	catch( xml::sax::SAXParseException& r )
195 	{
196         // sax parser sends wrapped exceptions,
197         // try to find the original one
198         xml::sax::SAXException aSaxEx = *(xml::sax::SAXException*)(&r);
199         sal_Bool bTryChild = sal_True;
200 
201         while( bTryChild )
202         {
203             xml::sax::SAXException aTmp;
204             if ( aSaxEx.WrappedException >>= aTmp )
205                 aSaxEx = aTmp;
206             else
207                 bTryChild = sal_False;
208         }
209 
210         packages::zip::ZipIOException aBrokenPackage;
211         if ( aSaxEx.WrappedException >>= aBrokenPackage )
212             return ERRCODE_IO_BROKENPACKAGE;
213 
214 		if( bEncrypted )
215 			return ERRCODE_SFX_WRONGPASSWORD;
216 
217 #if OSL_DEBUG_LEVEL > 1
218 		ByteString aError( "SAX parse exception caught while importing:\n" );
219 		aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US );
220 		DBG_ERROR( aError.GetBuffer() );
221 #endif
222 
223 		String sErr( String::CreateFromInt32( r.LineNumber ));
224 		sErr += ',';
225 		sErr += String::CreateFromInt32( r.ColumnNumber );
226 
227 		if( rStreamName.Len() )
228 		{
229 			return *new TwoStringErrorInfo(
230 							(bMustBeSuccessfull ? ERR_FORMAT_FILE_ROWCOL
231 										   	 	: WARN_FORMAT_FILE_ROWCOL),
232 					    	rStreamName, sErr,
233 							ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
234 		}
235 		else
236 		{
237 			ASSERT( bMustBeSuccessfull, "Warnings are not supported" );
238 			return *new StringErrorInfo( ERR_FORMAT_ROWCOL, sErr,
239 							 ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR );
240 		}
241 	}
242 	catch( xml::sax::SAXException& r)
243 	{
244         packages::zip::ZipIOException aBrokenPackage;
245         if ( r.WrappedException >>= aBrokenPackage )
246             return ERRCODE_IO_BROKENPACKAGE;
247 
248 		if( bEncrypted )
249 			return ERRCODE_SFX_WRONGPASSWORD;
250 
251 #if OSL_DEBUG_LEVEL > 1
252 		ByteString aError( "SAX exception caught while importing:\n" );
253 		aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US );
254 		DBG_ERROR( aError.GetBuffer() );
255 #endif
256 
257 		return ERR_SWG_READ_ERROR;
258 	}
259 	catch( packages::zip::ZipIOException& r)
260 	{
261 		(void)r;
262 #if OSL_DEBUG_LEVEL > 1
263 		ByteString aError( "Zip exception caught while importing:\n" );
264 		aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US );
265 		DBG_ERROR( aError.GetBuffer() );
266 #endif
267 		return ERRCODE_IO_BROKENPACKAGE;
268 	}
269 	catch( io::IOException& r)
270 	{
271 		(void)r;
272 #if OSL_DEBUG_LEVEL > 1
273 		ByteString aError( "IO exception caught while importing:\n" );
274 		aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US );
275 		DBG_ERROR( aError.GetBuffer() );
276 #endif
277 		return ERR_SWG_READ_ERROR;
278 	}
279 	catch( uno::Exception& r)
280 	{
281 		(void)r;
282 #if OSL_DEBUG_LEVEL > 1
283 		ByteString aError( "uno exception caught while importing:\n" );
284 		aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US );
285 		DBG_ERROR( aError.GetBuffer() );
286 #endif
287 		return ERR_SWG_READ_ERROR;
288 	}
289 
290 	// success!
291 	return 0;
292 }
293 
294 /// read a component (storage version)
ReadThroughComponent(uno::Reference<embed::XStorage> xStorage,uno::Reference<XComponent> xModelComponent,const sal_Char * pStreamName,const sal_Char * pCompatibilityStreamName,uno::Reference<lang::XMultiServiceFactory> & rFactory,const sal_Char * pFilterName,const Sequence<Any> & rFilterArguments,const OUString & rName,sal_Bool bMustBeSuccessfull)295 sal_Int32 ReadThroughComponent(
296 	uno::Reference<embed::XStorage> xStorage,
297 	uno::Reference<XComponent> xModelComponent,
298 	const sal_Char* pStreamName,
299 	const sal_Char* pCompatibilityStreamName,
300 	uno::Reference<lang::XMultiServiceFactory> & rFactory,
301 	const sal_Char* pFilterName,
302 	const Sequence<Any>& rFilterArguments,
303 	const OUString& rName,
304 	sal_Bool bMustBeSuccessfull)
305 {
306 	DBG_ASSERT(xStorage.is(), "Need storage!");
307 	DBG_ASSERT(NULL != pStreamName, "Please, please, give me a name!");
308 
309 	// open stream (and set parser input)
310 	OUString sStreamName = OUString::createFromAscii(pStreamName);
311 	sal_Bool bContainsStream = sal_False;
312 	try
313 	{
314 		bContainsStream = xStorage->isStreamElement(sStreamName);
315 	}
316 	catch( container::NoSuchElementException& )
317 	{
318 	}
319 
320 	if (!bContainsStream )
321 	{
322 		// stream name not found! Then try the compatibility name.
323 		// if no stream can be opened, return immediately with OK signal
324 
325 		// do we even have an alternative name?
326 		if ( NULL == pCompatibilityStreamName )
327 			return 0;
328 
329 		// if so, does the stream exist?
330 		sStreamName = OUString::createFromAscii(pCompatibilityStreamName);
331         try
332         {
333             bContainsStream = xStorage->isStreamElement(sStreamName);
334         }
335         catch( container::NoSuchElementException& )
336         {
337         }
338 
339         if (! bContainsStream )
340 			return 0;
341 	}
342 
343 	// set Base URL
344 	uno::Reference< beans::XPropertySet > xInfoSet;
345 	if( rFilterArguments.getLength() > 0 )
346 		rFilterArguments.getConstArray()[0] >>= xInfoSet;
347 	DBG_ASSERT( xInfoSet.is(), "missing property set" );
348 	if( xInfoSet.is() )
349 	{
350 		OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("StreamName") );
351 		xInfoSet->setPropertyValue( sPropName, makeAny( sStreamName ) );
352 	}
353 
354     try
355     {
356 		// get input stream
357     	uno::Reference <io::XStream> xStream = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
358     	uno::Reference <beans::XPropertySet > xProps( xStream, uno::UNO_QUERY );
359 
360         Any aAny = xProps->getPropertyValue(
361                 OUString( RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) );
362 
363         sal_Bool bEncrypted = aAny.getValueType() == ::getBooleanCppuType() &&
364                 *(sal_Bool *)aAny.getValue();
365 
366         uno::Reference <io::XInputStream> xInputStream = xStream->getInputStream();
367 
368         // read from the stream
369         return ReadThroughComponent(
370             xInputStream, xModelComponent, sStreamName, rFactory,
371             pFilterName, rFilterArguments,
372             rName, bMustBeSuccessfull, bEncrypted );
373 	}
374 	catch ( packages::WrongPasswordException& )
375 	{
376 		return ERRCODE_SFX_WRONGPASSWORD;
377 	}
378 	catch( packages::zip::ZipIOException& )
379 	{
380 		return ERRCODE_IO_BROKENPACKAGE;
381 	}
382 	catch ( uno::Exception& )
383 	{
384 		OSL_ENSURE( sal_False, "Error on import!\n" );
385 		// TODO/LATER: error handling
386 	}
387 
388 	return ERR_SWG_READ_ERROR;
389 }
390 
391 
lcl_AdjustOutlineStylesForOOo(SwDoc & _rDoc)392 void lcl_AdjustOutlineStylesForOOo( SwDoc& _rDoc )
393 {
394     // array containing the names of the default outline styles ('Heading 1',
395     // 'Heading 2', ..., 'Heading 10')
396     String aDefOutlStyleNames[ MAXLEVEL ];
397     {
398         String sStyleName;
399         for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
400         {
401             sStyleName =
402                 SwStyleNameMapper::GetProgName( static_cast< sal_uInt16 >(RES_POOLCOLL_HEADLINE1 + i),
403                                                 sStyleName );
404             aDefOutlStyleNames[i] = sStyleName;
405         }
406     }
407 
408     // array indicating, which outline level already has a style assigned.
409     bool aOutlineLevelAssigned[ MAXLEVEL ];
410     // array of the default outline styles, which are created for the document.
411     SwTxtFmtColl* aCreatedDefaultOutlineStyles[ MAXLEVEL ];
412 
413     {
414         for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
415         {
416             aOutlineLevelAssigned[ i ] = false;
417             aCreatedDefaultOutlineStyles[ i ] = 0L;
418         }
419     }
420 
421     // determine, which outline level has already a style assigned and
422     // which of the default outline styles is created.
423     const SwTxtFmtColls& rColls = *(_rDoc.GetTxtFmtColls());
424     for ( sal_uInt16 n = 1; n < rColls.Count(); ++n )
425     {
426         SwTxtFmtColl* pColl = rColls[ n ];
427 		//if ( pColl->GetOutlineLevel() != NO_NUMBERING ) //#outline level zhaojianwei
428         if ( pColl->IsAssignedToListLevelOfOutlineStyle() )
429         {
430 		//	aOutlineLevelAssigned[ pColl->GetOutlineLevel() ] = true;
431             aOutlineLevelAssigned[ pColl->GetAssignedOutlineStyleLevel() ] = true; //<-end,zhaojianwei
432         }
433 
434         for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
435         {
436             if ( aCreatedDefaultOutlineStyles[ i ] == 0L &&
437                  pColl->GetName() == aDefOutlStyleNames[i] )
438             {
439                 aCreatedDefaultOutlineStyles[ i ] = pColl;
440                 break;
441             }
442         }
443     }
444 
445     // assign already created default outline style to outline level, which
446     // doesn't have a style assigned to it.
447     const SwNumRule* pOutlineRule = _rDoc.GetOutlineNumRule();
448     for ( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
449     {
450         // #i73361#
451         // Do not change assignment of already created default outline style
452         // to a certain outline level.
453         if ( !aOutlineLevelAssigned[ i ] &&
454              aCreatedDefaultOutlineStyles[ i ] != 0 &&
455              ! aCreatedDefaultOutlineStyles[ i ]->IsAssignedToListLevelOfOutlineStyle() )
456         {
457             // apply outline level at created default outline style
458             aCreatedDefaultOutlineStyles[i]->AssignToListLevelOfOutlineStyle( i ); //#outline level added by zhaojianwei
459 
460             // apply outline numbering rule, if none is set.
461             const SfxPoolItem& rItem =
462                 aCreatedDefaultOutlineStyles[ i ]->GetFmtAttr( RES_PARATR_NUMRULE, sal_False );
463             if ( static_cast<const SwNumRuleItem&>(rItem).GetValue().Len() == 0 )
464             {
465                 SwNumRuleItem aItem( pOutlineRule->GetName() );
466                 aCreatedDefaultOutlineStyles[ i ]->SetFmtAttr( aItem );
467             }
468         }
469     }
470 
471 }
472 
473 
lcl_ConvertSdrOle2ObjsToSdrGrafObjs(SwDoc & _rDoc)474 void lcl_ConvertSdrOle2ObjsToSdrGrafObjs( SwDoc& _rDoc )
475 {
476     if ( _rDoc.GetDrawModel() &&
477          _rDoc.GetDrawModel()->GetPage( 0 ) )
478     {
479         const SdrPage& rSdrPage( *(_rDoc.GetDrawModel()->GetPage( 0 )) );
480 
481         // iterate recursive with group objects over all shapes on the draw page
482         SdrObjListIter aIter( rSdrPage );
483         while( aIter.IsMore() )
484         {
485             SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( aIter.Next() );
486             if( pOle2Obj )
487             {
488                 // found an ole2 shape
489                 SdrObjList* pObjList = pOle2Obj->GetObjList();
490 
491                 // get its graphic
492                 Graphic aGraphic;
493                 pOle2Obj->Connect();
494                 Graphic* pGraphic = pOle2Obj->GetGraphic();
495                 if( pGraphic )
496                     aGraphic = *pGraphic;
497                 pOle2Obj->Disconnect();
498 
499                 // create new graphic shape with the ole graphic and shape size
500                 SdrGrafObj* pGraphicObj = new SdrGrafObj( aGraphic, pOle2Obj->GetCurrentBoundRect() );
501                 // apply layer of ole2 shape at graphic shape
502                 pGraphicObj->SetLayer( pOle2Obj->GetLayer() );
503 
504                 // replace ole2 shape with the new graphic object and delete the ol2 shape
505                 SdrObject* pReplaced = pObjList->ReplaceObject( pGraphicObj, pOle2Obj->GetOrdNum() );
506                 SdrObject::Free( pReplaced );
507             }
508         }
509     }
510 }
511 
512 
Read(SwDoc & rDoc,const String & rBaseURL,SwPaM & rPaM,const String & rName)513 sal_uLong XMLReader::Read( SwDoc &rDoc, const String& rBaseURL, SwPaM &rPaM, const String & rName )
514 {
515 	// Get service factory
516 	uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
517 			comphelper::getProcessServiceFactory();
518 	ASSERT( xServiceFactory.is(),
519 			"XMLReader::Read: got no service manager" );
520 	if( !xServiceFactory.is() )
521 		return ERR_SWG_READ_ERROR;
522 
523 	uno::Reference< io::XActiveDataSource > xSource;
524 	uno::Reference< XInterface > xPipe;
525 	uno::Reference< document::XGraphicObjectResolver > xGraphicResolver;
526 	SvXMLGraphicHelper *pGraphicHelper = 0;
527 	uno::Reference< document::XEmbeddedObjectResolver > xObjectResolver;
528 	SvXMLEmbeddedObjectHelper *pObjectHelper = 0;
529 
530 	// get the input stream (storage or stream)
531 	uno::Reference<io::XInputStream> xInputStream;
532 	uno::Reference<embed::XStorage> xStorage;
533 	if( pMedium )
534 		xStorage = pMedium->GetStorage();
535 	else
536 		xStorage = xStg;
537 
538 	if( !xStorage.is() )
539 		return ERR_SWG_READ_ERROR;
540 
541 	pGraphicHelper = SvXMLGraphicHelper::Create( xStorage,
542 												 GRAPHICHELPER_MODE_READ,
543 												 sal_False );
544 	xGraphicResolver = pGraphicHelper;
545 	SfxObjectShell *pPersist = rDoc.GetPersist();
546 	if( pPersist )
547 	{
548 		pObjectHelper = SvXMLEmbeddedObjectHelper::Create(
549 										xStorage, *pPersist,
550 										EMBEDDEDOBJECTHELPER_MODE_READ,
551 										sal_False );
552 		xObjectResolver = pObjectHelper;
553 	}
554 
555 	// Get the docshell, the model, and finally the model's component
556 	SwDocShell *pDocSh = rDoc.GetDocShell();
557 	ASSERT( pDocSh, "XMLReader::Read: got no doc shell" );
558 	if( !pDocSh )
559 		return ERR_SWG_READ_ERROR;
560 	uno::Reference< lang::XComponent > xModelComp( pDocSh->GetModel(), UNO_QUERY );
561 	ASSERT( xModelComp.is(),
562 			"XMLReader::Read: got no model" );
563 	if( !xModelComp.is() )
564 		return ERR_SWG_READ_ERROR;
565 
566 
567 	// create and prepare the XPropertySet that gets passed through
568 	// the components, and the XStatusIndicator that shows progress to
569 	// the user.
570 
571 	// create XPropertySet with three properties for status indicator
572 	comphelper::PropertyMapEntry aInfoMap[] =
573 	{
574 		{ "ProgressRange", sizeof("ProgressRange")-1, 0,
575 			  &::getCppuType((sal_Int32*)0),
576 			  beans::PropertyAttribute::MAYBEVOID, 0},
577 		{ "ProgressMax", sizeof("ProgressMax")-1, 0,
578 			  &::getCppuType((sal_Int32*)0),
579 			  beans::PropertyAttribute::MAYBEVOID, 0},
580 		{ "ProgressCurrent", sizeof("ProgressCurrent")-1, 0,
581 			  &::getCppuType((sal_Int32*)0),
582 			  beans::PropertyAttribute::MAYBEVOID, 0},
583 		{ "NumberStyles", sizeof("NumberStyles")-1, 0,
584 			  &::getCppuType( (uno::Reference<container::XNameContainer> *) 0),
585 			  beans::PropertyAttribute::MAYBEVOID, 0},
586 		{ "RecordChanges", sizeof("RecordChanges")-1, 0,
587 			  &::getBooleanCppuType(),
588 			  beans::PropertyAttribute::MAYBEVOID, 0 },
589 		{ "ShowChanges", sizeof("ShowChanges")-1, 0,
590 			  &::getBooleanCppuType(),
591 			  beans::PropertyAttribute::MAYBEVOID, 0 },
592 		{ "RedlineProtectionKey", sizeof("RedlineProtectionKey")-1, 0,
593 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
594 			  new uno::Type(::getCppuType((Sequence<sal_Int8>*)0)),
595 #else
596 			  &::getCppuType((Sequence<sal_Int8>*)0),
597 #endif
598 			  beans::PropertyAttribute::MAYBEVOID, 0 },
599 		{ "PrivateData", sizeof("PrivateData")-1, 0,
600 			  &::getCppuType( (uno::Reference<XInterface> *)0 ),
601 			  beans::PropertyAttribute::MAYBEVOID, 0 },
602 		{ "BaseURI", sizeof("BaseURI")-1, 0,
603 			  &::getCppuType( (OUString *)0 ),
604 			  beans::PropertyAttribute::MAYBEVOID, 0 },
605 		{ "StreamRelPath", sizeof("StreamRelPath")-1, 0,
606 			  &::getCppuType( (OUString *)0 ),
607 			  beans::PropertyAttribute::MAYBEVOID, 0 },
608 		{ "StreamName", sizeof("StreamName")-1, 0,
609 			  &::getCppuType( (OUString *)0 ),
610 			  beans::PropertyAttribute::MAYBEVOID, 0 },
611 		// properties for insert modes
612 		{ "StyleInsertModeFamilies", sizeof("StyleInsertModeFamilies")-1, 0,
613 			  &::getCppuType((Sequence<OUString>*)0),
614 			  beans::PropertyAttribute::MAYBEVOID, 0 },
615 		{ "StyleInsertModeOverwrite", sizeof("StyleInsertModeOverwrite")-1, 0,
616 			  &::getBooleanCppuType(),
617 			  beans::PropertyAttribute::MAYBEVOID, 0 },
618 		{ "TextInsertModeRange", sizeof("TextInsertModeRange")-1, 0,
619 			  &::getCppuType( (uno::Reference<text::XTextRange> *) 0),
620 			  beans::PropertyAttribute::MAYBEVOID, 0},
621 		{ "AutoTextMode", sizeof("AutoTextMode")-1, 0,
622 			  &::getBooleanCppuType(),
623 			  beans::PropertyAttribute::MAYBEVOID, 0 },
624 		{ "OrganizerMode", sizeof("OrganizerMode")-1, 0,
625 			  &::getBooleanCppuType(),
626 			  beans::PropertyAttribute::MAYBEVOID, 0 },
627 		// --> OD 2004-08-10 #i28749# - Add property, which indicates, if the
628 		// shape position attributes are given in horizontal left-to-right layout.
629 		// This is the case for the OpenOffice.org file format.
630 		{ "ShapePositionInHoriL2R", sizeof("ShapePositionInHoriL2R")-1, 0,
631               &::getBooleanCppuType(),
632               beans::PropertyAttribute::MAYBEVOID, 0 },
633         // <--
634 		{ "BuildId", sizeof("BuildId")-1, 0,
635 			  &::getCppuType( (OUString *)0 ),
636               beans::PropertyAttribute::MAYBEVOID, 0 },
637         // --> OD 2007-12-19 #152540#
638         // Add property, which indicates, if a text document in OpenOffice.org
639         // file format is read.
640         // Note: Text documents read via the binary filter are also finally
641         //       read using the OpenOffice.org file format. Thus, e.g. for text
642         //       documents in StarOffice 5.2 binary file format this property
643         //       will be sal_True.
644         { "TextDocInOOoFileFormat", sizeof("TextDocInOOoFileFormat")-1, 0,
645               &::getBooleanCppuType(),
646               beans::PropertyAttribute::MAYBEVOID, 0 },
647 		// <--
648 		{ NULL, 0, 0, NULL, 0, 0 }
649 	};
650 	uno::Reference< beans::XPropertySet > xInfoSet(
651 				comphelper::GenericPropertySet_CreateInstance(
652 							new comphelper::PropertySetInfo( aInfoMap ) ) );
653 
654 	// ---- get BuildId from parent container if available
655 
656 	uno::Reference< container::XChild > xChild( xModelComp, uno::UNO_QUERY );
657 	if( xChild.is() )
658 	{
659 		uno::Reference< beans::XPropertySet > xParentSet( xChild->getParent(), uno::UNO_QUERY );
660 		if( xParentSet.is() )
661 		{
662 			uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xParentSet->getPropertySetInfo() );
663 			OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BuildId" ) );
664 			if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(sPropName) )
665 			{
666 				xInfoSet->setPropertyValue( sPropName, xParentSet->getPropertyValue(sPropName) );
667 			}
668 		}
669 	}
670 
671 	// try to get an XStatusIndicator from the Medium
672 	uno::Reference<task::XStatusIndicator> xStatusIndicator;
673 
674 	if (pDocSh->GetMedium())
675 	{
676 		SfxItemSet* pSet = pDocSh->GetMedium()->GetItemSet();
677 		if (pSet)
678 		{
679             const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>(
680                 pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) );
681             if (pItem)
682             {
683                 pItem->GetValue() >>= xStatusIndicator;
684             }
685 		}
686 	}
687 
688 
689 	// set progress range and start status indicator
690 	sal_Int32 nProgressRange(1000000);
691 	if (xStatusIndicator.is())
692 	{
693 		xStatusIndicator->start(SW_RESSTR(STR_STATSTR_SWGREAD), nProgressRange);
694 	}
695 	uno::Any aProgRange;
696 	aProgRange <<= nProgressRange;
697 	OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM("ProgressRange"));
698 	xInfoSet->setPropertyValue(sProgressRange, aProgRange);
699 
700 	::comphelper::ComponentContext aContext( xServiceFactory );
701 	Reference< container::XNameAccess > xLateInitSettings(
702 		aContext.createComponent( "com.sun.star.document.NamedPropertyValues" ), UNO_QUERY_THROW );
703 	beans::NamedValue aLateInitSettings(
704 		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LateInitSettings" ) ),
705 		makeAny( xLateInitSettings )
706 	);
707 
708 	// prepare filter arguments, WARNING: the order is important!
709 	Sequence<Any> aFilterArgs( 5 );
710 	Any *pArgs = aFilterArgs.getArray();
711 	*pArgs++ <<= xInfoSet;
712 	*pArgs++ <<= xStatusIndicator;
713 	*pArgs++ <<= xGraphicResolver;
714 	*pArgs++ <<= xObjectResolver;
715 	*pArgs++ <<= aLateInitSettings;
716 
717 	Sequence<Any> aEmptyArgs( 3 );
718 	pArgs = aEmptyArgs.getArray();
719 	*pArgs++ <<= xInfoSet;
720 	*pArgs++ <<= xStatusIndicator;
721 
722 	// prepare for special modes
723 	if( aOpt.IsFmtsOnly() )
724 	{
725 		sal_Int32 nCount =
726 			(aOpt.IsFrmFmts() ? 1 : 0) +
727 			(aOpt.IsPageDescs() ? 1 : 0) +
728 			(aOpt.IsTxtFmts() ? 2 : 0) +
729 			(aOpt.IsNumRules() ? 1 : 0);
730 
731 		Sequence< OUString> aFamiliesSeq( nCount );
732 		OUString *pSeq = aFamiliesSeq.getArray();
733 		if( aOpt.IsFrmFmts() )
734 			// SFX_STYLE_FAMILY_FRAME;
735 			*pSeq++ = OUString::createFromAscii("FrameStyles");
736 		if( aOpt.IsPageDescs() )
737 			// SFX_STYLE_FAMILY_PAGE;
738 			*pSeq++ = OUString::createFromAscii("PageStyles");
739 		if( aOpt.IsTxtFmts() )
740 		{
741 			// (SFX_STYLE_FAMILY_CHAR|SFX_STYLE_FAMILY_PARA);
742 			*pSeq++ = OUString::createFromAscii("CharacterStyles");
743 			*pSeq++ = OUString::createFromAscii("ParagraphStyles");
744 		}
745 		if( aOpt.IsNumRules() )
746 			// SFX_STYLE_FAMILY_PSEUDO;
747 			*pSeq++ = OUString::createFromAscii("NumberingStyles");
748 
749 		OUString sStyleInsertModeFamilies(
750 				RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeFamilies"));
751 		xInfoSet->setPropertyValue( sStyleInsertModeFamilies,
752 									makeAny(aFamiliesSeq) );
753 
754 		OUString sStyleInsertModeOverwrite(
755 				RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeOverwrite"));
756 		sal_Bool bTmp = !aOpt.IsMerge();
757 		Any aAny;
758 		aAny.setValue( &bTmp, ::getBooleanCppuType() );
759 		xInfoSet->setPropertyValue( sStyleInsertModeOverwrite, aAny );
760 	}
761 	else if( bInsertMode )
762 	{
763 		const uno::Reference<text::XTextRange> xInsertTextRange =
764 			SwXTextRange::CreateXTextRange(rDoc, *rPaM.GetPoint(), 0);
765 		OUString sTextInsertModeRange(
766 				RTL_CONSTASCII_USTRINGPARAM("TextInsertModeRange"));
767 		xInfoSet->setPropertyValue( sTextInsertModeRange,
768 									makeAny(xInsertTextRange) );
769 	}
770 	else
771 	{
772 		rPaM.GetBound(true).nContent.Assign(0, 0);
773 		rPaM.GetBound(false).nContent.Assign(0, 0);
774 	}
775 
776 	if( IsBlockMode() )
777 	{
778 		OUString sAutoTextMode(
779 				RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
780 		sal_Bool bTmp = sal_True;
781 		Any aAny;
782 		aAny.setValue( &bTmp, ::getBooleanCppuType() );
783 		xInfoSet->setPropertyValue( sAutoTextMode, aAny );
784 	}
785 	if( IsOrganizerMode() )
786 	{
787 		OUString sOrganizerMode(
788 				RTL_CONSTASCII_USTRINGPARAM("OrganizerMode"));
789 		sal_Bool bTmp = sal_True;
790 		Any aAny;
791 		aAny.setValue( &bTmp, ::getBooleanCppuType() );
792 		xInfoSet->setPropertyValue( sOrganizerMode, aAny );
793 	}
794 
795 	// Set base URI
796 	// there is ambiguity which medium should be used here
797 	// for now the own medium has a preference
798 	SfxMedium* pMedDescrMedium = pMedium ? pMedium : pDocSh->GetMedium();
799 	OSL_ENSURE( pMedDescrMedium, "There is no medium to get MediaDescriptor from!\n" );
800 
801 	::rtl::OUString aBaseURL( rBaseURL );
802 	OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("BaseURI") );
803 	xInfoSet->setPropertyValue( sPropName, makeAny( aBaseURL ) );
804 
805 	// TODO/LATER: separate links from usual embedded objects
806 	::rtl::OUString StreamPath;
807 	if( SFX_CREATE_MODE_EMBEDDED == rDoc.GetDocShell()->GetCreateMode() )
808 	{
809 		if ( pMedDescrMedium && pMedDescrMedium->GetItemSet() )
810 		{
811 			const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>(
812                 pMedDescrMedium->GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) );
813 			if ( pDocHierarchItem )
814                 StreamPath = pDocHierarchItem->GetValue();
815 		}
816         else
817         {
818             StreamPath = ::rtl::OUString::createFromAscii( "dummyObjectName" );
819         }
820 
821         if( StreamPath.getLength() )
822         {
823 			sPropName = OUString(RTL_CONSTASCII_USTRINGPARAM("StreamRelPath"));
824             xInfoSet->setPropertyValue( sPropName, makeAny( StreamPath ) );
825         }
826 	}
827 
828 	rDoc.acquire();	// prevent deletion
829 	sal_uInt32 nRet = 0;
830 
831 	// save redline mode into import info property set
832 	Any aAny;
833 	sal_Bool bTmp;
834 	OUString sShowChanges( RTL_CONSTASCII_USTRINGPARAM("ShowChanges") );
835 	bTmp = IDocumentRedlineAccess::IsShowChanges( rDoc.GetRedlineMode() );
836 	aAny.setValue( &bTmp, ::getBooleanCppuType() );
837 	xInfoSet->setPropertyValue( sShowChanges, aAny );
838 	OUString sRecordChanges( RTL_CONSTASCII_USTRINGPARAM("RecordChanges") );
839 	bTmp = IDocumentRedlineAccess::IsRedlineOn(rDoc.GetRedlineMode());
840 	aAny.setValue( &bTmp, ::getBooleanCppuType() );
841 	xInfoSet->setPropertyValue( sRecordChanges, aAny );
842 	OUString sRedlineProtectionKey( RTL_CONSTASCII_USTRINGPARAM("RedlineProtectionKey") );
843 	aAny <<= rDoc.GetRedlinePassword();
844 	xInfoSet->setPropertyValue( sRedlineProtectionKey, aAny );
845 
846 
847 	// force redline mode to "none"
848 	rDoc.SetRedlineMode_intern( nsRedlineMode_t::REDLINE_NONE );
849 
850 	const sal_Bool bOASIS = ( SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60 );
851 	// --> OD 2004-08-10 #i28749# - set property <ShapePositionInHoriL2R>
852 	{
853         const sal_Bool bShapePositionInHoriL2R = !bOASIS;
854         xInfoSet->setPropertyValue(
855                 OUString(RTL_CONSTASCII_USTRINGPARAM("ShapePositionInHoriL2R")),
856                 makeAny( bShapePositionInHoriL2R ) );
857     }
858     // <--
859     // --> OD 2007-12-19 #152540#
860     {
861         const sal_Bool bTextDocInOOoFileFormat = !bOASIS;
862         xInfoSet->setPropertyValue(
863                 OUString(RTL_CONSTASCII_USTRINGPARAM("TextDocInOOoFileFormat")),
864                 makeAny( bTextDocInOOoFileFormat ) );
865     }
866     // <--
867 
868 	sal_uInt32 nWarnRDF = 0;
869 	if ( !(IsOrganizerMode() || IsBlockMode() || aOpt.IsFmtsOnly() ||
870            bInsertMode) )
871 	{
872         // RDF metadata - must be read before styles/content
873         // N.B.: embedded documents have their own manifest.rdf!
874         try
875         {
876             const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(xModelComp,
877                 uno::UNO_QUERY_THROW);
878             const uno::Reference<rdf::XURI> xBaseURI( ::sfx2::createBaseURI(
879                 aContext.getUNOContext(), xStorage, aBaseURL, StreamPath) );
880             const uno::Reference<task::XInteractionHandler> xHandler(
881                 pDocSh->GetMedium()->GetInteractionHandler() );
882             xDMA->loadMetadataFromStorage(xStorage, xBaseURI, xHandler);
883         }
884         catch (lang::WrappedTargetException & e)
885         {
886             ucb::InteractiveAugmentedIOException iaioe;
887             if (e.TargetException >>= iaioe)
888             {
889                 // import error that was not ignored by InteractionHandler!
890                 nWarnRDF = ERR_SWG_READ_ERROR;
891             }
892             else
893             {
894                 nWarnRDF = WARN_SWG_FEATURES_LOST; // uhh... something wrong?
895             }
896         }
897         catch (uno::Exception &)
898         {
899             nWarnRDF = WARN_SWG_FEATURES_LOST; // uhh... something went wrong?
900         }
901 	}
902 
903 	// read storage streams
904 
905 	// #i103539#: always read meta.xml for generator
906 	sal_uInt32 const nWarn = ReadThroughComponent(
907         xStorage, xModelComp, "meta.xml", "Meta.xml", xServiceFactory,
908         (bOASIS ? "com.sun.star.comp.Writer.XMLOasisMetaImporter"
909                 : "com.sun.star.comp.Writer.XMLMetaImporter"),
910         aEmptyArgs, rName, sal_False );
911 
912 	sal_uInt32 nWarn2 = 0;
913 	if( !(IsOrganizerMode() || IsBlockMode() || aOpt.IsFmtsOnly() ||
914 		  bInsertMode) )
915 	{
916 		nWarn2 = ReadThroughComponent(
917 			xStorage, xModelComp, "settings.xml", NULL, xServiceFactory,
918 			(bOASIS ? "com.sun.star.comp.Writer.XMLOasisSettingsImporter"
919 					: "com.sun.star.comp.Writer.XMLSettingsImporter"),
920 			aFilterArgs, rName, sal_False );
921 	}
922 
923 	nRet = ReadThroughComponent(
924 		xStorage, xModelComp, "styles.xml", NULL, xServiceFactory,
925 		(bOASIS ? "com.sun.star.comp.Writer.XMLOasisStylesImporter"
926 				: "com.sun.star.comp.Writer.XMLStylesImporter"),
927 		aFilterArgs, rName, sal_True );
928 
929 	if( !nRet && !(IsOrganizerMode() || aOpt.IsFmtsOnly()) )
930 		nRet = ReadThroughComponent(
931 		   xStorage, xModelComp, "content.xml", "Content.xml", xServiceFactory,
932 			(bOASIS ? "com.sun.star.comp.Writer.XMLOasisContentImporter"
933 					: "com.sun.star.comp.Writer.XMLContentImporter"),
934 		   aFilterArgs, rName, sal_True );
935 
936 	if( !(IsOrganizerMode() || IsBlockMode() || bInsertMode ||
937 		  aOpt.IsFmtsOnly() ) )
938 	{
939 		OUString sStreamName( RTL_CONSTASCII_USTRINGPARAM("layout-cache") );
940 		try
941 		{
942             uno::Reference < io::XStream > xStm = xStorage->openStreamElement( sStreamName, embed::ElementModes::READ );
943             SvStream* pStrm2 = utl::UcbStreamHelper::CreateStream( xStm );
944             if( !pStrm2->GetError() )
945                 rDoc.ReadLayoutCache( *pStrm2 );
946             delete pStrm2;
947 		}
948 		catch ( uno::Exception& )
949 		{
950 		}
951 	}
952 
953 	// Notify Math objects
954 	if( bInsertMode )
955 		rDoc.PrtOLENotify( sal_False );
956 	else if ( rDoc.IsOLEPrtNotifyPending() )
957 		rDoc.PrtOLENotify( sal_True );
958 
959 	nRet = nRet ? nRet : (nWarn ? nWarn : (nWarn2 ? nWarn2 : nWarnRDF ) );
960 
961 	aOpt.ResetAllFmtsOnly();
962 
963 	// redline password
964 	aAny = xInfoSet->getPropertyValue( sRedlineProtectionKey );
965 	Sequence<sal_Int8> aKey;
966 	aAny >>= aKey;
967 	rDoc.SetRedlinePassword( aKey );
968 
969 	// restore redline mode from import info property set
970 	sal_Int16 nRedlineMode = nsRedlineMode_t::REDLINE_SHOW_INSERT;
971 	aAny = xInfoSet->getPropertyValue( sShowChanges );
972 	if ( *(sal_Bool*)aAny.getValue() )
973 		nRedlineMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
974 	aAny = xInfoSet->getPropertyValue( sRecordChanges );
975 	if ( *(sal_Bool*)aAny.getValue() || (aKey.getLength() > 0) )
976 		nRedlineMode |= nsRedlineMode_t::REDLINE_ON;
977 	else
978 		nRedlineMode |= nsRedlineMode_t::REDLINE_NONE;
979 
980 	// ... restore redline mode
981 	// (First set bogus mode to make sure the mode in SetRedlineMode()
982 	//  is different from its previous mode.)
983 	rDoc.SetRedlineMode_intern((RedlineMode_t)( ~nRedlineMode ));
984 	rDoc.SetRedlineMode( (RedlineMode_t)( nRedlineMode ));
985 
986 	// #103728# move Pam into valid content
987 	lcl_EnsureValidPam( rPaM );
988 
989 	if( pGraphicHelper )
990 		SvXMLGraphicHelper::Destroy( pGraphicHelper );
991 	xGraphicResolver = 0;
992 	if( pObjectHelper )
993 		SvXMLEmbeddedObjectHelper::Destroy( pObjectHelper );
994 	xObjectResolver = 0;
995 	rDoc.release();
996 
997 	if ( !bOASIS )
998 	{
999 		// --> OD 2005-09-06 #i44177# - assure that for documents in OpenOffice.org
1000 		// file format the relation between outline numbering rule and styles is
1001 		// filled-up accordingly.
1002 		// Note: The OpenOffice.org file format, which has no content that applies
1003 		//       a certain style, which is related to the outline numbering rule,
1004 		//       has lost the information, that this certain style is related to
1005 		//       the outline numbering rule.
1006 		// --> OD 2008-12-17 #i70748# - only for templates
1007 		if ( pMedium && pMedium->GetFilter() &&
1008 			pMedium->GetFilter()->IsOwnTemplateFormat() )
1009 		{
1010 			lcl_AdjustOutlineStylesForOOo( rDoc );
1011 		}
1012 		// <--
1013 		// Fix #i58251#: Unfortunately is the static default different to SO7 behavior,
1014 		// so we have to set a dynamic default after importing SO7
1015 		rDoc.SetDefault( SfxBoolItem( RES_ROW_SPLIT, sal_False ) );
1016 	}
1017 	// <--
1018 
1019 	rDoc.PropagateOutlineRule();
1020 
1021 	// --> OD 2006-03-14 #i62875#
1022 	if ( rDoc.get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) && !docfunc::ExistsDrawObjs( rDoc ) )
1023 	{
1024 		rDoc.set(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE, false);
1025 	}
1026 	// <--
1027 
1028 	// --> OD 2006-02-22 #b6382898#
1029 	// Convert all instances of <SdrOle2Obj> into <SdrGrafObj>, because the
1030 	// Writer doesn't support such objects.
1031 	lcl_ConvertSdrOle2ObjsToSdrGrafObjs( rDoc );
1032 	// <--
1033 
1034 	// set BuildId on XModel for later OLE object loading
1035 	if( xInfoSet.is() )
1036 	{
1037 		uno::Reference< beans::XPropertySet > xModelSet( xModelComp, uno::UNO_QUERY );
1038 		if( xModelSet.is() )
1039 		{
1040 			uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() );
1041 			OUString sName( RTL_CONSTASCII_USTRINGPARAM("BuildId" ) );
1042 			if( xModelSetInfo.is() && xModelSetInfo->hasPropertyByName(sName) )
1043 			{
1044 				xModelSet->setPropertyValue( sName, xInfoSet->getPropertyValue(sName) );
1045 			}
1046 		}
1047 	}
1048 
1049 	if (xStatusIndicator.is())
1050 	{
1051 		xStatusIndicator->end();
1052 	}
1053 
1054 	rDoc.GetIStyleAccess().clearCaches(); // Clear Automatic-Style-Caches(shared_pointer!)
1055 	return nRet;
1056 }
1057 
1058 	// read the sections of the document, which is equal to the medium.
1059 	// returns the count of it
GetSectionList(SfxMedium & rMedium,SvStrings & rStrings) const1060 sal_uInt16 XMLReader::GetSectionList( SfxMedium& rMedium,
1061 									SvStrings& rStrings ) const
1062 {
1063 	uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
1064 			comphelper::getProcessServiceFactory();
1065 	ASSERT( xServiceFactory.is(),
1066 			"XMLReader::Read: got no service manager" );
1067 	uno::Reference < embed::XStorage > xStg2;
1068 	if( xServiceFactory.is() && ( xStg2 = rMedium.GetStorage() ).is() )
1069 	{
1070 		try
1071 		{
1072 
1073 			xml::sax::InputSource aParserInput;
1074 			OUString sDocName( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) );
1075 			aParserInput.sSystemId = sDocName;
1076 
1077 			uno::Reference < io::XStream > xStm = xStg2->openStreamElement( sDocName, embed::ElementModes::READ );
1078 			aParserInput.aInputStream = xStm->getInputStream();
1079 
1080 			// get parser
1081 			uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
1082 				OUString::createFromAscii("com.sun.star.xml.sax.Parser") );
1083 			ASSERT( xXMLParser.is(),
1084 				"XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
1085 			if( xXMLParser.is() )
1086 			{
1087 				// get filter
1088 				// #110680#
1089 				uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLSectionList( xServiceFactory, rStrings );
1090 
1091 				// connect parser and filter
1092 				uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
1093 				xParser->setDocumentHandler( xFilter );
1094 
1095 				// parse
1096 				xParser->parseStream( aParserInput );
1097 			}
1098 		}
1099 		catch( xml::sax::SAXParseException& )
1100 		{
1101 			// re throw ?
1102 		}
1103 		catch( xml::sax::SAXException& )
1104 		{
1105 			// re throw ?
1106 		}
1107 		catch( io::IOException& )
1108 		{
1109 			// re throw ?
1110 		}
1111 		catch( packages::WrongPasswordException& )
1112 		{
1113 			// re throw ?
1114 		}
1115 	}
1116 	return rStrings.Count();
1117 }
1118 
1119