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