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