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