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