1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include <com/sun/star/text/XTextDocument.hpp>
28 #include <com/sun/star/text/XTextRange.hpp>
29 #include <com/sun/star/drawing/XDrawPage.hpp>
30 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
31 #include <com/sun/star/container/XIndexAccess.hpp>
32 #include <xmloff/xmlnmspe.hxx>
33 #include <xmloff/xmltkmap.hxx>
34 #include <xmloff/xmlictxt.hxx>
35 #include <xmloff/txtimp.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <xmloff/XMLTextShapeImportHelper.hxx>
38 #include <xmloff/XMLFontStylesContext.hxx>
39 #include <xmloff/ProgressBarHelper.hxx>
40 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
41 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
42 #include <doc.hxx>
43 #include <TextCursorHelper.hxx>
44 #include <unotext.hxx>
45 #include <unotextrange.hxx>
46 #include "unocrsr.hxx"
47 #include <poolfmt.hxx>
48 #include <ndtxt.hxx>
49 #include <editsh.hxx>
50 #include "xmlimp.hxx"
51 #include <xmloff/DocumentSettingsContext.hxx>
52 #include <docsh.hxx>
53 #include <editeng/unolingu.hxx>
54 #include <svx/svdmodel.hxx>
55 #include <svx/xmlgrhlp.hxx>
56 #include <svx/xmleohlp.hxx>
57 #include <sfx2/printer.hxx>
58 #include <ForbiddenCharactersEnum.hxx>
59 #include <xmloff/xmluconv.hxx>
60 #include <unotools/saveopt.hxx>
61 #include <tools/diagnose_ex.h>
62 #include <hash_set>
63 #include <stringhash.hxx>
64
65 // for locking SolarMutex: svapp + mutex
66 #include <vcl/svapp.hxx>
67 #include <vos/mutex.hxx>
68 #include <unotxdoc.hxx> // for initXForms()
69
70 #include <xmloff/xmlmetai.hxx>
71 #include <xmloff/xformsimport.hxx>
72
73 using ::rtl::OUString;
74
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::text;
78 using namespace ::com::sun::star::lang;
79 using namespace ::com::sun::star::beans;
80 using namespace ::com::sun::star::container;
81 using namespace ::com::sun::star::i18n;
82 using namespace ::com::sun::star::drawing;
83 using namespace ::com::sun::star::xforms;
84 using namespace ::xmloff::token;
85 using namespace ::std;
86
87 struct OUStringEquals
88 {
operator ()OUStringEquals89 sal_Bool operator()( const rtl::OUString &r1,
90 const rtl::OUString &r2) const
91 {
92 return r1 == r2;
93 }
94 };
95
96 //----------------------------------------------------------------------------
97
98 enum SwXMLDocTokens
99 {
100 XML_TOK_DOC_FONTDECLS,
101 XML_TOK_DOC_STYLES,
102 XML_TOK_DOC_AUTOSTYLES,
103 XML_TOK_DOC_MASTERSTYLES,
104 XML_TOK_DOC_META,
105 XML_TOK_DOC_BODY,
106 XML_TOK_DOC_SCRIPT,
107 XML_TOK_DOC_SETTINGS,
108 XML_TOK_DOC_XFORMS,
109 XML_TOK_OFFICE_END=XML_TOK_UNKNOWN
110 };
111
112 static __FAR_DATA SvXMLTokenMapEntry aDocTokenMap[] =
113 {
114 { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS, XML_TOK_DOC_FONTDECLS },
115 { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
116 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
117 { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES, XML_TOK_DOC_MASTERSTYLES },
118 { XML_NAMESPACE_OFFICE, XML_META, XML_TOK_DOC_META },
119 { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_DOC_BODY },
120 { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT },
121 { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
122 { XML_NAMESPACE_XFORMS, XML_MODEL, XML_TOK_DOC_XFORMS },
123 XML_TOKEN_MAP_END
124 };
125
126 // ----------------------------------------------------------------------------
127
128 class SwXMLBodyContext_Impl : public SvXMLImportContext
129 {
GetSwImport() const130 const SwXMLImport& GetSwImport() const
131 { return (const SwXMLImport&)GetImport(); }
GetSwImport()132 SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
133
134 public:
135
136 SwXMLBodyContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
137 const OUString& rLName,
138 const Reference< xml::sax::XAttributeList > & xAttrList );
139 virtual ~SwXMLBodyContext_Impl();
140
141 TYPEINFO();
142
143 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
144 const OUString& rLocalName,
145 const Reference< xml::sax::XAttributeList > & xAttrList );
146 };
147
SwXMLBodyContext_Impl(SwXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> &)148 SwXMLBodyContext_Impl::SwXMLBodyContext_Impl( SwXMLImport& rImport,
149 sal_uInt16 nPrfx, const OUString& rLName,
150 const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
151 SvXMLImportContext( rImport, nPrfx, rLName )
152 {
153 }
154
~SwXMLBodyContext_Impl()155 SwXMLBodyContext_Impl::~SwXMLBodyContext_Impl()
156 {
157 }
158
159 TYPEINIT1( SwXMLBodyContext_Impl, SvXMLImportContext );
160
CreateChildContext(sal_uInt16,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> &)161 SvXMLImportContext *SwXMLBodyContext_Impl::CreateChildContext(
162 sal_uInt16 /*nPrefix*/,
163 const OUString& rLocalName,
164 const Reference< xml::sax::XAttributeList > & /*xAttrList*/ )
165 {
166 return GetSwImport().CreateBodyContentContext( rLocalName );
167 }
168
169 // ----------------------------------------------------------------------------
170
171 // --> OD 2006-10-11 #i69629#
172 // enhance class <SwXMLDocContext_Impl> in order to be able to create subclasses
173 // NB: virtually inherit so we can multiply inherit properly
174 // in SwXMLOfficeDocContext_Impl
175 class SwXMLDocContext_Impl : public virtual SvXMLImportContext
176 {
177 // --> OD 2006-10-11 #i69629#
178 protected:
179 // <--
GetSwImport() const180 const SwXMLImport& GetSwImport() const
181 { return (const SwXMLImport&)GetImport(); }
GetSwImport()182 SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
183
184 public:
185
186 SwXMLDocContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
187 const OUString& rLName,
188 const Reference< xml::sax::XAttributeList > & xAttrList );
189 virtual ~SwXMLDocContext_Impl();
190
191 TYPEINFO();
192
193 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
194 const OUString& rLocalName,
195 const Reference< xml::sax::XAttributeList > & xAttrList );
196 };
197
SwXMLDocContext_Impl(SwXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> &)198 SwXMLDocContext_Impl::SwXMLDocContext_Impl( SwXMLImport& rImport,
199 sal_uInt16 nPrfx, const OUString& rLName,
200 const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
201 SvXMLImportContext( rImport, nPrfx, rLName )
202 {
203 }
204
~SwXMLDocContext_Impl()205 SwXMLDocContext_Impl::~SwXMLDocContext_Impl()
206 {
207 }
208
209 TYPEINIT1( SwXMLDocContext_Impl, SvXMLImportContext );
210
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)211 SvXMLImportContext *SwXMLDocContext_Impl::CreateChildContext(
212 sal_uInt16 nPrefix,
213 const OUString& rLocalName,
214 const Reference< xml::sax::XAttributeList > & xAttrList )
215 {
216 SvXMLImportContext *pContext = 0;
217
218 const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
219 switch( rTokenMap.Get( nPrefix, rLocalName ) )
220 {
221 case XML_TOK_DOC_FONTDECLS:
222 pContext = GetSwImport().CreateFontDeclsContext( rLocalName,
223 xAttrList );
224 break;
225 case XML_TOK_DOC_STYLES:
226 GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
227 pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
228 sal_False );
229 break;
230 case XML_TOK_DOC_AUTOSTYLES:
231 // don't use the autostyles from the styles-document for the progress
232 if ( ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
233 GetSwImport().GetProgressBarHelper()->Increment
234 ( PROGRESS_BAR_STEP );
235 pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
236 sal_True );
237 break;
238 // case XML_TOK_DOC_USESTYLES:
239 // pContext = GetSwImport().CreateUseStylesContext( rLocalName,
240 // xAttrList );
241 // break;
242 case XML_TOK_DOC_MASTERSTYLES:
243 pContext = GetSwImport().CreateMasterStylesContext( rLocalName,
244 xAttrList );
245 break;
246 case XML_TOK_DOC_META:
247 DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
248 break;
249 case XML_TOK_DOC_SCRIPT:
250 pContext = GetSwImport().CreateScriptContext( rLocalName );
251 break;
252 case XML_TOK_DOC_BODY:
253 GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
254 pContext = new SwXMLBodyContext_Impl( GetSwImport(), nPrefix,
255 rLocalName, xAttrList );
256 break;
257 case XML_TOK_DOC_SETTINGS:
258 pContext = new XMLDocumentSettingsContext( GetImport(), nPrefix, rLocalName, xAttrList );
259 break;
260 case XML_TOK_DOC_XFORMS:
261 pContext = createXFormsModelContext(GetImport(), nPrefix, rLocalName);
262 break;
263 }
264
265 if( !pContext )
266 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
267
268
269 return pContext;
270 }
271
272 // --> OD 2006-10-11 #i69629#
273 // new subclass <SwXMLOfficeDocContext_Impl> of class <SwXMLDocContext_Impl>
274 class SwXMLOfficeDocContext_Impl :
275 public SwXMLDocContext_Impl, public SvXMLMetaDocumentContext
276 {
277 public:
278
279 SwXMLOfficeDocContext_Impl( SwXMLImport& rImport,
280 sal_uInt16 nPrfx,
281 const OUString& rLName,
282 const Reference< xml::sax::XAttributeList > & xAttrList,
283 const Reference< document::XDocumentProperties >& xDocProps,
284 const Reference< xml::sax::XDocumentHandler >& xDocBuilder);
285 virtual ~SwXMLOfficeDocContext_Impl();
286
287 TYPEINFO();
288
289 virtual SvXMLImportContext *CreateChildContext(
290 sal_uInt16 nPrefix,
291 const OUString& rLocalName,
292 const Reference< xml::sax::XAttributeList > & xAttrList );
293 };
294
SwXMLOfficeDocContext_Impl(SwXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList,const Reference<document::XDocumentProperties> & xDocProps,const Reference<xml::sax::XDocumentHandler> & xDocBuilder)295 SwXMLOfficeDocContext_Impl::SwXMLOfficeDocContext_Impl(
296 SwXMLImport& rImport,
297 sal_uInt16 nPrfx,
298 const OUString& rLName,
299 const Reference< xml::sax::XAttributeList > & xAttrList,
300 const Reference< document::XDocumentProperties >& xDocProps,
301 const Reference< xml::sax::XDocumentHandler >& xDocBuilder) :
302 SvXMLImportContext( rImport, nPrfx, rLName ),
303 SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList ),
304 SvXMLMetaDocumentContext( rImport, nPrfx, rLName, xDocProps, xDocBuilder)
305 {
306 }
307
~SwXMLOfficeDocContext_Impl()308 SwXMLOfficeDocContext_Impl::~SwXMLOfficeDocContext_Impl()
309 {
310 }
311
312 TYPEINIT1( SwXMLOfficeDocContext_Impl, SwXMLDocContext_Impl );
313
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)314 SvXMLImportContext* SwXMLOfficeDocContext_Impl::CreateChildContext(
315 sal_uInt16 nPrefix,
316 const OUString& rLocalName,
317 const Reference< xml::sax::XAttributeList > & xAttrList )
318 {
319 const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
320
321 // assign paragraph styles to list levels of outline style after all styles
322 // are imported and finished. This is the case, when <office:body> starts
323 // in flat OpenDocument file format.
324 {
325 if ( rTokenMap.Get( nPrefix, rLocalName ) == XML_TOK_DOC_BODY )
326 {
327 GetImport().GetTextImport()->SetOutlineStyles( sal_True );
328 }
329 }
330
331 // behave like meta base class iff we encounter office:meta
332 if ( XML_TOK_DOC_META == rTokenMap.Get( nPrefix, rLocalName ) ) {
333 return SvXMLMetaDocumentContext::CreateChildContext(
334 nPrefix, rLocalName, xAttrList );
335 } else {
336 return SwXMLDocContext_Impl::CreateChildContext(
337 nPrefix, rLocalName, xAttrList );
338 }
339 }
340 // <--
341
342 // --> OD 2006-10-11 #i69629#
343 // new subclass <SwXMLDocStylesContext_Impl> of class <SwXMLDocContext_Impl>
344 class SwXMLDocStylesContext_Impl : public SwXMLDocContext_Impl
345 {
346 public:
347
348 SwXMLDocStylesContext_Impl( SwXMLImport& rImport,
349 sal_uInt16 nPrfx,
350 const OUString& rLName,
351 const Reference< xml::sax::XAttributeList > & xAttrList );
352 virtual ~SwXMLDocStylesContext_Impl();
353
354 TYPEINFO();
355
356 virtual void EndElement();
357 };
358
SwXMLDocStylesContext_Impl(SwXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const Reference<xml::sax::XAttributeList> & xAttrList)359 SwXMLDocStylesContext_Impl::SwXMLDocStylesContext_Impl(
360 SwXMLImport& rImport,
361 sal_uInt16 nPrfx,
362 const OUString& rLName,
363 const Reference< xml::sax::XAttributeList > & xAttrList ) :
364 SvXMLImportContext( rImport, nPrfx, rLName ),
365 SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList )
366 {
367 }
368
~SwXMLDocStylesContext_Impl()369 SwXMLDocStylesContext_Impl::~SwXMLDocStylesContext_Impl()
370 {
371 }
372
373 TYPEINIT1( SwXMLDocStylesContext_Impl, SwXMLDocContext_Impl );
374
EndElement()375 void SwXMLDocStylesContext_Impl::EndElement()
376 {
377 // assign paragraph styles to list levels of outline style after all styles
378 // are imported and finished.
379 SwXMLImport& rSwImport = dynamic_cast<SwXMLImport&>( GetImport());
380 GetImport().GetTextImport()->SetOutlineStyles(
381 (rSwImport.GetStyleFamilyMask() & SFX_STYLE_FAMILY_PARA ) ? sal_True : sal_False);
382 // <--
383 }
384 // <--
385 //----------------------------------------------------------------------------
386
GetDocElemTokenMap()387 const SvXMLTokenMap& SwXMLImport::GetDocElemTokenMap()
388 {
389 if( !pDocElemTokenMap )
390 pDocElemTokenMap = new SvXMLTokenMap( aDocTokenMap );
391
392 return *pDocElemTokenMap;
393 }
394
CreateContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)395 SvXMLImportContext *SwXMLImport::CreateContext(
396 sal_uInt16 nPrefix,
397 const OUString& rLocalName,
398 const Reference< xml::sax::XAttributeList > & xAttrList )
399 {
400 SvXMLImportContext *pContext = 0;
401
402 // --> OD 2006-10-11 #i69629#
403 // own subclasses for <office:document> and <office:document-styles>
404 if( XML_NAMESPACE_OFFICE==nPrefix &&
405 // ( IsXMLToken( rLocalName, XML_DOCUMENT ) ||
406 // ( IsXMLToken( rLocalName, XML_DOCUMENT_META ) ||
407 ( IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) ||
408 // IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) ||
409 IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ))
410 pContext = new SwXMLDocContext_Impl( *this, nPrefix, rLocalName,
411 xAttrList );
412 else if ( XML_NAMESPACE_OFFICE==nPrefix &&
413 IsXMLToken( rLocalName, XML_DOCUMENT_META ) )
414 {
415 pContext = CreateMetaContext(rLocalName);
416 }
417 else if ( XML_NAMESPACE_OFFICE==nPrefix &&
418 IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) )
419 {
420 pContext = new SwXMLDocStylesContext_Impl( *this, nPrefix, rLocalName,
421 xAttrList );
422 }
423 else if ( XML_NAMESPACE_OFFICE==nPrefix &&
424 IsXMLToken( rLocalName, XML_DOCUMENT ) )
425 {
426 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
427 mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
428 "com.sun.star.xml.dom.SAXDocumentBuilder")),
429 uno::UNO_QUERY_THROW);
430 uno::Reference<document::XDocumentProperties> const xDocProps(
431 GetDocumentProperties());
432 // flat OpenDocument file format
433 pContext = new SwXMLOfficeDocContext_Impl( *this, nPrefix, rLocalName,
434 xAttrList, xDocProps, xDocBuilder);
435 }
436 // <--
437 else
438 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
439
440 return pContext;
441 }
442
443 // #110680#
SwXMLImport(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,sal_uInt16 nImportFlags)444 SwXMLImport::SwXMLImport(
445 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
446 sal_uInt16 nImportFlags)
447 : SvXMLImport( xServiceFactory, nImportFlags ),
448 pSttNdIdx( 0 ),
449 pTableItemMapper( 0 ),
450 pDocElemTokenMap( 0 ),
451 pTableElemTokenMap( 0 ),
452 pTableCellAttrTokenMap( 0 ),
453 pGraphicResolver( 0 ),
454 pEmbeddedResolver( 0 ),
455 nStyleFamilyMask( SFX_STYLE_FAMILY_ALL ),
456 bLoadDoc( sal_True ),
457 bInsert( sal_False ),
458 bBlock( sal_False ),
459 bShowProgress( sal_True ),
460 bOrganizerMode( sal_False ),
461 bInititedXForms( sal_False ),
462 bPreserveRedlineMode( sal_True )
463 {
464 _InitItemImport();
465
466 }
467
468 #ifdef XML_CORE_API
469 // #110680#
SwXMLImport(const uno::Reference<lang::XMultiServiceFactory> xServiceFactory,SwDoc & rDoc,const SwPaM & rPaM,sal_Bool bLDoc,sal_Bool bInsertMode,sal_uInt16 nStyleFamMask,const uno::Reference<frame::XModel> & rModel,const uno::Reference<document::XGraphicObjectResolver> & rEGO,SvStorage * pPkg)470 SwXMLImport::SwXMLImport(
471 const uno::Reference< lang::XMultiServiceFactory > xServiceFactory,
472 SwDoc& rDoc,
473 const SwPaM& rPaM,
474 sal_Bool bLDoc,
475 sal_Bool bInsertMode,
476 sal_uInt16 nStyleFamMask,
477 const uno::Reference< frame::XModel > & rModel,
478 const uno::Reference< document::XGraphicObjectResolver > & rEGO,
479 SvStorage *pPkg )
480 : SvXMLImport( xServiceFactory, rModel, rEGO ),
481 bLoadDoc( bLDoc ),
482 bInsert( bInsertMode ),
483 nStyleFamilyMask( nStyleFamMask ),
484 pDocElemTokenMap( 0 ),
485 pTableElemTokenMap( 0 ),
486 pTableCellAttrTokenMap( 0 ),
487 pTableItemMapper( 0 ),
488 pSttNdIdx( 0 ),
489 bShowProgress( sal_True ),
490 bPreserveRedlineMode( sal_True ),
491 xPackage( pPkg )
492 {
493 _InitItemImport();
494
495 Reference < XTextRange > xTextRange =
496 SwXTextRange::CreateTextRangeFromPosition( &rDoc, *rPaM.GetPoint(), 0 );
497 Reference < XText > xText = xTextRange->getText();
498 Reference < XTextCursor > xTextCursor =
499 xText->createTextCursorByRange( xTextRange );
500 GetTextImport()->SetCursor( xTextCursor );
501 }
502 #endif
503
~SwXMLImport()504 SwXMLImport::~SwXMLImport() throw ()
505 {
506 delete pDocElemTokenMap;
507 delete pTableElemTokenMap;
508 delete pTableCellAttrTokenMap;
509 _FinitItemImport();
510 }
511
setTextInsertMode(const Reference<XTextRange> & rInsertPos)512 void SwXMLImport::setTextInsertMode(
513 const Reference< XTextRange > & rInsertPos )
514 {
515 bInsert = sal_True;
516
517 Reference < XText > xText = rInsertPos->getText();
518 Reference < XTextCursor > xTextCursor =
519 xText->createTextCursorByRange( rInsertPos );
520 GetTextImport()->SetCursor( xTextCursor );
521 }
522
setStyleInsertMode(sal_uInt16 nFamilies,sal_Bool bOverwrite)523 void SwXMLImport::setStyleInsertMode( sal_uInt16 nFamilies,
524 sal_Bool bOverwrite )
525 {
526 bInsert = !bOverwrite;
527 nStyleFamilyMask = nFamilies;
528 bLoadDoc = sal_False;
529 }
530
setBlockMode()531 void SwXMLImport::setBlockMode( )
532 {
533 bBlock = sal_True;
534 }
535
setOrganizerMode()536 void SwXMLImport::setOrganizerMode( )
537 {
538 bOrganizerMode = sal_True;
539 }
540
getUnoTunnelId()541 const Sequence< sal_Int8 > & SwXMLImport::getUnoTunnelId() throw()
542 {
543 static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
544 return aSeq;
545 }
546
getSomething(const Sequence<sal_Int8> & rId)547 sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId )
548 throw(RuntimeException)
549 {
550 if( rId.getLength() == 16
551 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
552 rId.getConstArray(), 16 ) )
553 {
554 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
555 }
556 return SvXMLImport::getSomething( rId );
557 }
558
lcl_xml_GetSwXTextCursor(const Reference<XTextCursor> & rTextCursor)559 OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
560 {
561 Reference<XUnoTunnel> xCrsrTunnel( rTextCursor, UNO_QUERY );
562 ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
563 if( !xCrsrTunnel.is() )
564 return 0;
565 OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
566 sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
567 ASSERT( pTxtCrsr, "SwXTextCursor missing" );
568 return pTxtCrsr;
569 }
570
startDocument(void)571 void SwXMLImport::startDocument( void )
572 throw( xml::sax::SAXException, uno::RuntimeException )
573 {
574 // delegate to parent
575 SvXMLImport::startDocument();
576
577 DBG_ASSERT( GetModel().is(), "model is missing" );
578 if( !GetModel().is() )
579 return;
580
581 // this method will modify the document directly -> lock SolarMutex
582 vos::OGuard aGuard(Application::GetSolarMutex());
583
584
585 Reference< XPropertySet > xImportInfo( getImportInfo() );
586 Reference< XPropertySetInfo > xPropertySetInfo;
587 if( xImportInfo.is() )
588 xPropertySetInfo = xImportInfo->getPropertySetInfo();
589 if( xPropertySetInfo.is() )
590 {
591 Any aAny;
592 // insert style mode?
593 OUString sStyleInsertModeFamilies(
594 RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeFamilies"));
595 if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeFamilies) )
596 {
597 aAny = xImportInfo->getPropertyValue(sStyleInsertModeFamilies);
598 Sequence< OUString> aFamiliesSeq;
599 if( aAny >>= aFamiliesSeq )
600 {
601 OUString sFrameStyles( RTL_CONSTASCII_USTRINGPARAM ( "FrameStyles" ) );
602 OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM ( "PageStyles" ) );
603 OUString sCharacterStyles( RTL_CONSTASCII_USTRINGPARAM ( "CharacterStyles" ) );
604 OUString sParagraphStyles( RTL_CONSTASCII_USTRINGPARAM ( "ParagraphStyles" ) );
605 OUString sNumberingStyles( RTL_CONSTASCII_USTRINGPARAM ( "NumberingStyles" ) );
606 sal_uInt16 nFamilyMask = 0U;
607 sal_Int32 nCount = aFamiliesSeq.getLength();
608 const OUString *pSeq = aFamiliesSeq.getConstArray();
609 for( sal_Int32 i=0; i < nCount; i++ )
610 {
611 const OUString& rFamily = pSeq[i];
612 if( rFamily==sFrameStyles )
613 nFamilyMask |= SFX_STYLE_FAMILY_FRAME;
614 else if( rFamily==sPageStyles )
615 nFamilyMask |= SFX_STYLE_FAMILY_PAGE;
616 else if( rFamily==sCharacterStyles )
617 nFamilyMask |= SFX_STYLE_FAMILY_CHAR;
618 else if( rFamily==sParagraphStyles )
619 nFamilyMask |= SFX_STYLE_FAMILY_PARA;
620 else if( rFamily==sNumberingStyles )
621 nFamilyMask |= SFX_STYLE_FAMILY_PSEUDO;
622 }
623
624 sal_Bool bOverwrite = sal_False;
625 OUString sStyleInsertModeOverwrite(
626 RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeOverwrite"));
627 if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeOverwrite) )
628 {
629 aAny = xImportInfo->getPropertyValue(sStyleInsertModeOverwrite);
630 if( aAny.getValueType() == ::getBooleanCppuType() &&
631 *static_cast<const sal_Bool*>(aAny.getValue()) )
632 bOverwrite = sal_True;
633 }
634
635 setStyleInsertMode( nFamilyMask, bOverwrite );
636 }
637 }
638
639 // text insert mode?
640 OUString sTextInsertModeRange(
641 RTL_CONSTASCII_USTRINGPARAM("TextInsertModeRange"));
642 if( xPropertySetInfo->hasPropertyByName(sTextInsertModeRange) )
643 {
644 aAny = xImportInfo->getPropertyValue(sTextInsertModeRange);
645 Reference<XTextRange> xInsertTextRange;
646 if( aAny >>= xInsertTextRange )
647 setTextInsertMode( xInsertTextRange );
648 }
649
650 // auto text mode
651 OUString sAutoTextMode(
652 RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
653 if( xPropertySetInfo->hasPropertyByName(sAutoTextMode) )
654 {
655 aAny = xImportInfo->getPropertyValue(sAutoTextMode);
656 if( aAny.getValueType() == ::getBooleanCppuType() &&
657 *static_cast<const sal_Bool*>(aAny.getValue()) )
658 setBlockMode();
659 }
660
661 // organizer mode
662 OUString sOrganizerMode(
663 RTL_CONSTASCII_USTRINGPARAM("OrganizerMode"));
664 if( xPropertySetInfo->hasPropertyByName(sOrganizerMode) )
665 {
666 aAny = xImportInfo->getPropertyValue(sOrganizerMode);
667 if( aAny.getValueType() == ::getBooleanCppuType() &&
668 *static_cast<const sal_Bool*>(aAny.getValue()) )
669 setOrganizerMode();
670 }
671 }
672
673 // There only is a text cursor by now if we are in insert mode. In any
674 // other case we have to create one at the start of the document.
675 // We also might change into the insert mode later, so we have to make
676 // sure to first set the insert mode and then create the text import
677 // helper. Otherwise it won't have the insert flag set!
678 OTextCursorHelper *pTxtCrsr = 0;
679 Reference < XTextCursor > xTextCursor;
680 if( HasTextImport() )
681 xTextCursor = GetTextImport()->GetCursor();
682 if( !xTextCursor.is() )
683 {
684 Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
685 Reference < XText > xText = xTextDoc->getText();
686 xTextCursor = xText->createTextCursor();
687 SwCrsrShell *pCrsrSh = 0;
688 SwDoc *pDoc = 0;
689 if( IMPORT_ALL == getImportFlags() )
690 {
691 pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
692 ASSERT( pTxtCrsr, "SwXTextCursor missing" );
693 if( !pTxtCrsr )
694 return;
695
696 pDoc = pTxtCrsr->GetDoc();
697 ASSERT( pDoc, "SwDoc missing" );
698 if( !pDoc )
699 return;
700
701 // Is there a edit shell. If yes, then we are currently inserting
702 // a document. We then have to insert at the current edit shell's
703 // cursor position. That not quite clean code, but there is no other
704 // way currently.
705 pCrsrSh = pDoc->GetEditShell();
706 }
707 if( pCrsrSh )
708 {
709 const uno::Reference<text::XTextRange> xInsertTextRange(
710 SwXTextRange::CreateXTextRange(
711 *pDoc, *pCrsrSh->GetCrsr()->GetPoint(), 0 ) );
712 setTextInsertMode( xInsertTextRange );
713 xTextCursor = GetTextImport()->GetCursor();
714 pTxtCrsr = 0;
715 }
716 else
717 GetTextImport()->SetCursor( xTextCursor );
718 }
719
720 if( (getImportFlags() & (IMPORT_CONTENT|IMPORT_MASTERSTYLES)) == 0 )
721 return;
722
723 if( !pTxtCrsr )
724 pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
725 ASSERT( pTxtCrsr, "SwXTextCursor missing" );
726 if( !pTxtCrsr )
727 return;
728
729 SwDoc *pDoc = pTxtCrsr->GetDoc();
730 ASSERT( pDoc, "SwDoc missing" );
731 if( !pDoc )
732 return;
733
734 if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
735 {
736 pSttNdIdx = new SwNodeIndex( pDoc->GetNodes() );
737 if( IsInsertMode() )
738 {
739 SwPaM *pPaM = pTxtCrsr->GetPaM();
740 const SwPosition* pPos = pPaM->GetPoint();
741
742 // Split once and remember the node that has been splitted.
743 pDoc->SplitNode( *pPos, false );
744 *pSttNdIdx = pPos->nNode.GetIndex()-1;
745
746 // Split again.
747 pDoc->SplitNode( *pPos, false );
748
749 // Insert all content into the new node
750 pPaM->Move( fnMoveBackward );
751 pDoc->SetTxtFmtColl
752 ( *pPaM, pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD, false ) );
753 }
754 }
755
756 // We need a draw model to be able to set the z order
757 // --> OD 2005-08-08 #i52858# - method name changed
758 pDoc->GetOrCreateDrawModel();
759 // <--
760
761 // SJ: #i49801# locking the modell to disable repaints
762 SdrModel* pDrawModel = pDoc->GetDrawModel();
763 if ( pDrawModel )
764 pDrawModel->setLock( sal_True );
765
766 if( !GetGraphicResolver().is() )
767 {
768 pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_READ );
769 Reference< document::XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
770 SetGraphicResolver( xGraphicResolver );
771 }
772
773 if( !GetEmbeddedResolver().is() )
774 {
775 SfxObjectShell *pPersist = pDoc->GetPersist();
776 if( pPersist )
777 {
778 pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
779 *pPersist,
780 EMBEDDEDOBJECTHELPER_MODE_READ );
781 Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
782 SetEmbeddedResolver( xEmbeddedResolver );
783 }
784 }
785 }
786
endDocument(void)787 void SwXMLImport::endDocument( void )
788 throw( xml::sax::SAXException, uno::RuntimeException )
789 {
790 DBG_ASSERT( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
791 if( !GetModel().is() )
792 return;
793
794 // this method will modify the document directly -> lock SolarMutex
795 vos::OGuard aGuard(Application::GetSolarMutex());
796
797 if( pGraphicResolver )
798 SvXMLGraphicHelper::Destroy( pGraphicResolver );
799 if( pEmbeddedResolver )
800 SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
801 // Clear the shape import to sort the shapes (and not in the
802 // destructor that might be called after the import has finished
803 // for Java filters.
804 if( HasShapeImport() )
805 ClearShapeImport();
806
807
808 SwDoc *pDoc = 0;
809 if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
810 {
811 Reference<XUnoTunnel> xCrsrTunnel( GetTextImport()->GetCursor(),
812 UNO_QUERY);
813 ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
814 OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
815 sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
816 ASSERT( pTxtCrsr, "SwXTextCursor missing" );
817 SwPaM *pPaM = pTxtCrsr->GetPaM();
818 if( IsInsertMode() && pSttNdIdx->GetIndex() )
819 {
820 // If we are in insert mode, join the splitted node that is in front
821 // of the new content with the first new node. Or in other words:
822 // Revert the first split node.
823 SwTxtNode* pTxtNode = pSttNdIdx->GetNode().GetTxtNode();
824 SwNodeIndex aNxtIdx( *pSttNdIdx );
825 if( pTxtNode && pTxtNode->CanJoinNext( &aNxtIdx ) &&
826 pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex() )
827 {
828 // If the PaM points to the first new node, move the PaM to the
829 // end of the previous node.
830 if( pPaM && pPaM->GetPoint()->nNode == aNxtIdx )
831 {
832 pPaM->GetPoint()->nNode = *pSttNdIdx;
833 pPaM->GetPoint()->nContent.Assign( pTxtNode,
834 pTxtNode->GetTxt().Len() );
835 }
836
837 #ifdef DBG_UTIL
838 // !!! This should be impossible !!!!
839 ASSERT( pSttNdIdx->GetIndex()+1 !=
840 pPaM->GetBound( sal_True ).nNode.GetIndex(),
841 "PaM.Bound1 point to new node " );
842 ASSERT( pSttNdIdx->GetIndex()+1 !=
843 pPaM->GetBound( sal_False ).nNode.GetIndex(),
844 "PaM.Bound2 points to new node" );
845
846 if( pSttNdIdx->GetIndex()+1 ==
847 pPaM->GetBound( sal_True ).nNode.GetIndex() )
848 {
849 sal_uInt16 nCntPos =
850 pPaM->GetBound( sal_True ).nContent.GetIndex();
851 pPaM->GetBound( sal_True ).nContent.Assign( pTxtNode,
852 pTxtNode->GetTxt().Len() + nCntPos );
853 }
854 if( pSttNdIdx->GetIndex()+1 ==
855 pPaM->GetBound( sal_False ).nNode.GetIndex() )
856 {
857 sal_uInt16 nCntPos =
858 pPaM->GetBound( sal_False ).nContent.GetIndex();
859 pPaM->GetBound( sal_False ).nContent.Assign( pTxtNode,
860 pTxtNode->GetTxt().Len() + nCntPos );
861 }
862 #endif
863 // If the first new node isn't empty, convert the node's text
864 // attributes into hints. Otherwise, set the new node's
865 // paragraph style at the previous (empty) node.
866 SwTxtNode* pDelNd = aNxtIdx.GetNode().GetTxtNode();
867 if( pTxtNode->GetTxt().Len() )
868 pDelNd->FmtToTxtAttr( pTxtNode );
869 else
870 pTxtNode->ChgFmtColl( pDelNd->GetTxtColl() );
871 pTxtNode->JoinNext();
872 }
873 }
874
875 SwPosition* pPos = pPaM->GetPoint();
876 DBG_ASSERT( !pPos->nContent.GetIndex(), "last paragraph isn't empty" );
877 if( !pPos->nContent.GetIndex() )
878 {
879 SwTxtNode* pCurrNd;
880 sal_uLong nNodeIdx = pPos->nNode.GetIndex();
881 pDoc = pPaM->GetDoc();
882
883 DBG_ASSERT( pPos->nNode.GetNode().IsCntntNode(),
884 "insert position is not a content node" );
885 if( !IsInsertMode() )
886 {
887 // If we're not in insert mode, the last node is deleted.
888 const SwNode *pPrev = pDoc->GetNodes()[nNodeIdx -1];
889 if( pPrev->IsCntntNode() ||
890 ( pPrev->IsEndNode() &&
891 pPrev->StartOfSectionNode()->IsSectionNode() ) )
892 {
893 SwCntntNode* pCNd = pPaM->GetCntntNode();
894 if( pCNd && pCNd->StartOfSectionIndex()+2 <
895 pCNd->EndOfSectionIndex() )
896 {
897 pPaM->GetBound(sal_True).nContent.Assign( 0, 0 );
898 pPaM->GetBound(sal_False).nContent.Assign( 0, 0 );
899 pDoc->GetNodes().Delete( pPaM->GetPoint()->nNode );
900 }
901 }
902 }
903 else if( 0 != (pCurrNd = pDoc->GetNodes()[nNodeIdx]->GetTxtNode()) )
904 {
905 // Id we're in insert mode, the empty node is joined with
906 // the next and the previous one.
907 if( pCurrNd->CanJoinNext( &pPos->nNode ))
908 {
909 SwTxtNode* pNextNd = pPos->nNode.GetNode().GetTxtNode();
910 pPos->nContent.Assign( pNextNd, 0 );
911 pPaM->SetMark(); pPaM->DeleteMark();
912 pNextNd->JoinPrev();
913
914 // Remove line break that has been inserted by the import,
915 // but only if one has been inserted!
916 if( pNextNd->CanJoinPrev(/* &pPos->nNode*/ ) &&
917 *pSttNdIdx != pPos->nNode )
918 {
919 // SwTxtNode* pPrevNd = pPos->nNode.GetNode().GetTxtNode();
920 // pPos->nContent.Assign( pPrevNd, 0 );
921 // pPaM->SetMark(); pPaM->DeleteMark();
922 // pPrevNd->JoinNext();
923 pNextNd->JoinPrev();
924 }
925 }
926 else if( !pCurrNd->GetTxt().Len() )
927 {
928 pPos->nContent.Assign( 0, 0 );
929 pPaM->SetMark(); pPaM->DeleteMark();
930 pDoc->GetNodes().Delete( pPos->nNode, 1 );
931 pPaM->Move( fnMoveBackward );
932 }
933 }
934 }
935 }
936
937 /* #108146# Was called too early. Moved from
938 SwXMLBodyContext_Impl::EndElement */
939
940 GetTextImport()->RedlineAdjustStartNodeCursor( sal_False );
941
942 if( (getImportFlags() & IMPORT_CONTENT) != 0 ||
943 ((getImportFlags() & IMPORT_MASTERSTYLES) != 0 && IsStylesOnlyMode()) )
944 {
945 // pDoc might be 0. In this case UpdateTxtCollCondition is looking
946 // for it itself.
947 UpdateTxtCollConditions( pDoc );
948 }
949
950 GetTextImport()->ResetCursor();
951
952 delete pSttNdIdx;
953 pSttNdIdx = 0;
954
955 if( (getImportFlags() == IMPORT_ALL ) )
956 {
957 // Notify math objects. If we are in the package filter this will
958 // be done by the filter object itself
959 if( IsInsertMode() )
960 pDoc->PrtOLENotify( sal_False );
961 else if ( pDoc->IsOLEPrtNotifyPending() )
962 pDoc->PrtOLENotify( sal_True );
963 }
964
965 // SJ: #i49801# -> now permitting repaints
966 if ( pDoc )
967 {
968 SdrModel* pDrawModel = pDoc->GetDrawModel();
969 if ( pDrawModel )
970 pDrawModel->setLock( sal_False );
971 }
972
973 // #i90243#
974 if ( bInititedXForms )
975 {
976 Reference< xforms::XFormsSupplier > xFormsSupp( GetModel(), UNO_QUERY );
977 Reference< XNameAccess > xXForms;
978 if ( xFormsSupp.is() )
979 xXForms = xFormsSupp->getXForms().get();
980
981 if ( xXForms.is() )
982 {
983 try
984 {
985 Sequence< beans::PropertyValue > aXFormsSettings;
986
987 ::rtl::OUString sXFormsSettingsName( GetXMLToken( XML_XFORM_MODEL_SETTINGS ) );
988 if ( xLateInitSettings.is() && xLateInitSettings->hasByName( sXFormsSettingsName ) )
989 {
990 OSL_VERIFY( xLateInitSettings->getByName( sXFormsSettingsName ) >>= aXFormsSettings );
991 applyXFormsSettings( xXForms, aXFormsSettings );
992 }
993 }
994 catch( const Exception& )
995 {
996 DBG_UNHANDLED_EXCEPTION();
997 }
998 }
999 }
1000
1001 // delegate to parent: takes care of error handling
1002 SvXMLImport::endDocument();
1003 }
1004
1005
1006 // Locally derive XMLTextShapeImportHelper, so we can take care of the
1007 // form import This is Writer, but not text specific, so it should go
1008 // here!
1009 class SvTextShapeImportHelper : public XMLTextShapeImportHelper
1010 {
1011 // hold own reference form import helper, because the SvxImport
1012 // stored in the superclass, from whom we originally got the
1013 // reference, is already destroyed when we want to use it in the
1014 // destructor
1015 UniReference< ::xmloff::OFormLayerXMLImport > rFormImport;
1016
1017 // hold reference to the one page (if it exists) for calling startPage()
1018 // and endPage. If !xPage.is(), then this document doesn't have a
1019 // XDrawPage.
1020 Reference<drawing::XDrawPage> xPage;
1021
1022 public:
1023
1024 SvTextShapeImportHelper(SvXMLImport& rImp);
1025 virtual ~SvTextShapeImportHelper();
1026 };
1027
SvTextShapeImportHelper(SvXMLImport & rImp)1028 SvTextShapeImportHelper::SvTextShapeImportHelper(SvXMLImport& rImp) :
1029 XMLTextShapeImportHelper(rImp)
1030 {
1031 Reference<drawing::XDrawPageSupplier> xSupplier(rImp.GetModel(),UNO_QUERY);
1032 if (xSupplier.is())
1033 {
1034 if (rImp.GetFormImport().is())
1035 {
1036 rImp.GetFormImport()->startPage(xSupplier->getDrawPage());
1037 rFormImport = rImp.GetFormImport();
1038 }
1039
1040 xPage = xSupplier->getDrawPage();
1041 Reference<XShapes> xShapes( xPage, UNO_QUERY );
1042 XMLShapeImportHelper::startPage( xShapes );
1043 }
1044 }
1045
~SvTextShapeImportHelper()1046 SvTextShapeImportHelper::~SvTextShapeImportHelper()
1047 {
1048 rFormImport->endPage();
1049
1050 if (xPage.is())
1051 {
1052 Reference<XShapes> xShapes( xPage, UNO_QUERY );
1053 XMLShapeImportHelper::endPage(xShapes);
1054 }
1055 }
1056
1057
CreateShapeImport()1058 XMLShapeImportHelper* SwXMLImport::CreateShapeImport()
1059 {
1060 return new SvTextShapeImportHelper( *this );
1061 }
1062
CreateFontDeclsContext(const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)1063 SvXMLImportContext *SwXMLImport::CreateFontDeclsContext(
1064 const OUString& rLocalName,
1065 const Reference< xml::sax::XAttributeList > & xAttrList )
1066 {
1067 XMLFontStylesContext *pFSContext =
1068 new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
1069 rLocalName, xAttrList,
1070 gsl_getSystemTextEncoding() );
1071 SetFontDecls( pFSContext );
1072 return pFSContext;
1073 }
SetViewSettings(const Sequence<PropertyValue> & aViewProps)1074 void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
1075 {
1076 if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || IsOrganizerMode() || !GetModel().is() )
1077 return;
1078
1079 // this method will modify the document directly -> lock SolarMutex
1080 vos::OGuard aGuard(Application::GetSolarMutex());
1081
1082 Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1083 Reference < XText > xText = xTextDoc->getText();
1084 Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1085 ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
1086 if( !xTextTunnel.is() )
1087 return;
1088
1089 SwXText *pText = reinterpret_cast< SwXText *>(
1090 sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1091 ASSERT( pText, "SwXText missing" );
1092 if( !pText )
1093 return;
1094
1095 SwDoc *pDoc = pText->GetDoc();
1096 Rectangle aRect;
1097 if( pDoc->GetDocShell() )
1098 aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
1099 //TODO/LATER: why that cast?!
1100 //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea();
1101
1102 sal_Int32 nCount = aViewProps.getLength();
1103 const PropertyValue *pValue = aViewProps.getConstArray();
1104
1105 sal_Int64 nTmp = 0;
1106 sal_Bool bShowRedlineChanges = sal_False, bBrowseMode = sal_False;
1107 sal_Bool bChangeShowRedline = sal_False, bChangeBrowseMode = sal_False;
1108
1109 //TODO/LATER: why that cast?!
1110 sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
1111 //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MAP_TWIP;
1112
1113 for (sal_Int32 i = 0; i < nCount ; i++)
1114 {
1115 if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaTop" ) ) )
1116 {
1117 pValue->Value >>= nTmp;
1118 aRect.setY( static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp) );
1119 }
1120 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaLeft" ) ) )
1121 {
1122 pValue->Value >>= nTmp;
1123 aRect.setX( static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp) );
1124 }
1125 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaWidth" ) ) )
1126 {
1127 pValue->Value >>= nTmp;
1128 Size aSize( aRect.GetSize() );
1129 aSize.Width() = static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp);
1130 aRect.SetSize( aSize );
1131 }
1132 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaHeight" ) ) )
1133 {
1134 pValue->Value >>= nTmp;
1135 Size aSize( aRect.GetSize() );
1136 aSize.Height() = static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp);
1137 aRect.SetSize( aSize );
1138 }
1139 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowRedlineChanges" ) ) )
1140 {
1141 bShowRedlineChanges = *(sal_Bool *)(pValue->Value.getValue());
1142 bChangeShowRedline = sal_True;
1143 }
1144 // #105372#: Headers and footers are not displayed in BrowseView anymore
1145 // else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowHeaderWhileBrowsing" ) ) )
1146 // else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowFooterWhileBrowsing" ) ) )
1147 else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "InBrowseMode" ) ) )
1148 {
1149 bBrowseMode = *(sal_Bool *)(pValue->Value.getValue());
1150 bChangeBrowseMode = sal_True;
1151 }
1152 pValue++;
1153 }
1154 if( pDoc->GetDocShell() )
1155 pDoc->GetDocShell()->SetVisArea ( aRect );
1156
1157 if (bChangeBrowseMode)
1158 pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bBrowseMode );
1159
1160 if (bChangeShowRedline)
1161 GetTextImport()->SetShowChanges( bShowRedlineChanges );
1162 }
1163
SetConfigurationSettings(const Sequence<PropertyValue> & aConfigProps)1164 void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aConfigProps)
1165 {
1166 // this method will modify the document directly -> lock SolarMutex
1167 vos::OGuard aGuard(Application::GetSolarMutex());
1168
1169 Reference< lang::XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
1170 if( !xFac.is() )
1171 return;
1172
1173 Reference< XPropertySet > xProps( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), UNO_QUERY );
1174 if( !xProps.is() )
1175 return;
1176
1177 Reference< XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
1178 if( !xInfo.is() )
1179 return;
1180
1181 hash_set< String, StringHashRef, StringEqRef > aSet;
1182 aSet.insert(String("ForbiddenCharacters", RTL_TEXTENCODING_ASCII_US));
1183 aSet.insert(String("IsKernAsianPunctuation", RTL_TEXTENCODING_ASCII_US));
1184 aSet.insert(String("CharacterCompressionType", RTL_TEXTENCODING_ASCII_US));
1185 aSet.insert(String("LinkUpdateMode", RTL_TEXTENCODING_ASCII_US));
1186 aSet.insert(String("FieldAutoUpdate", RTL_TEXTENCODING_ASCII_US));
1187 aSet.insert(String("ChartAutoUpdate", RTL_TEXTENCODING_ASCII_US));
1188 aSet.insert(String("AddParaTableSpacing", RTL_TEXTENCODING_ASCII_US));
1189 aSet.insert(String("AddParaTableSpacingAtStart", RTL_TEXTENCODING_ASCII_US));
1190 aSet.insert(String("PrintAnnotationMode", RTL_TEXTENCODING_ASCII_US));
1191 aSet.insert(String("PrintBlackFonts", RTL_TEXTENCODING_ASCII_US));
1192 aSet.insert(String("PrintControls", RTL_TEXTENCODING_ASCII_US));
1193 aSet.insert(String("PrintDrawings", RTL_TEXTENCODING_ASCII_US));
1194 aSet.insert(String("PrintGraphics", RTL_TEXTENCODING_ASCII_US));
1195 aSet.insert(String("PrintLeftPages", RTL_TEXTENCODING_ASCII_US));
1196 aSet.insert(String("PrintPageBackground", RTL_TEXTENCODING_ASCII_US));
1197 aSet.insert(String("PrintProspect", RTL_TEXTENCODING_ASCII_US));
1198 aSet.insert(String("PrintReversed", RTL_TEXTENCODING_ASCII_US));
1199 aSet.insert(String("PrintRightPages", RTL_TEXTENCODING_ASCII_US));
1200 aSet.insert(String("PrintFaxName", RTL_TEXTENCODING_ASCII_US));
1201 aSet.insert(String("PrintPaperFromSetup", RTL_TEXTENCODING_ASCII_US));
1202 aSet.insert(String("PrintTables", RTL_TEXTENCODING_ASCII_US));
1203 aSet.insert(String("PrintSingleJobs", RTL_TEXTENCODING_ASCII_US));
1204 aSet.insert(String("UpdateFromTemplate", RTL_TEXTENCODING_ASCII_US));
1205 aSet.insert(String("PrinterIndependentLayout", RTL_TEXTENCODING_ASCII_US));
1206 aSet.insert(String("PrintEmptyPages", RTL_TEXTENCODING_ASCII_US));
1207
1208 sal_Int32 nCount = aConfigProps.getLength();
1209 const PropertyValue* pValues = aConfigProps.getConstArray();
1210
1211 SvtSaveOptions aSaveOpt;
1212 sal_Bool bIsUserSetting = aSaveOpt.IsLoadUserSettings();
1213 sal_Bool bSet = bIsUserSetting;
1214
1215 // for some properties we don't want to use the application
1216 // default if they're missing. So we watch for them in the loop
1217 // below, and set them if not found
1218 bool bPrinterIndependentLayout = false;
1219 bool bUseOldNumbering = false; // #111955#
1220 bool bOutlineLevelYieldsOutlineRule = false;
1221 bool bAddExternalLeading = false;
1222 bool bAddParaSpacingToTableCells = false;
1223 bool bUseFormerLineSpacing = false;
1224 bool bUseFormerObjectPositioning = false;
1225 bool bUseFormerTextWrapping = false;
1226 bool bConsiderWrapOnObjPos = false;
1227 bool bIgnoreFirstLineIndentInNumbering = false;
1228 bool bDoNotJustifyLinesWithManualBreak = false;
1229 bool bDoNotResetParaAttrsForNumFont = false;
1230 bool bLoadReadonly = false;
1231 bool bDoNotCaptureDrawObjsOnPage( false );
1232 bool bClipAsCharacterAnchoredWriterFlyFrames( false );
1233 bool bUnixForceZeroExtLeading = false;
1234 bool bUseOldPrinterMetrics = false;
1235
1236 static const OUString sRedlineProtectionKey( RTL_CONSTASCII_USTRINGPARAM( "RedlineProtectionKey" ) );
1237
1238 // Set current database properties in certain order
1239 // Thus, keep these properties during loop and set them afterwards in valid order
1240 static const OUString sCurrentDatabaseDataSource( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseDataSource" ) );
1241 uno::Any aCurrentDatabaseDataSource;
1242 static const OUString sCurrentDatabaseCommand( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseCommand" ) );
1243 uno::Any aCurrentDatabaseCommand;
1244 static const OUString sCurrentDatabaseCommandType( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseCommandType" ) );
1245 uno::Any aCurrentDatabaseCommandType;
1246
1247 while( nCount-- )
1248 {
1249 if( !bIsUserSetting )
1250 {
1251 // test over the hash value if the entry is in the table.
1252 String aStr(pValues->Name);
1253
1254 bSet = aSet.find(aStr) == aSet.end();
1255 }
1256
1257 if( bSet )
1258 {
1259 try
1260 {
1261 if( xInfo->hasPropertyByName( pValues->Name ) )
1262 {
1263 if( pValues->Name.equals( sRedlineProtectionKey ) )
1264 {
1265 Sequence<sal_Int8> aKey;
1266 pValues->Value >>= aKey;
1267 GetTextImport()->SetChangesProtectionKey( aKey );
1268 }
1269 else if ( !aCurrentDatabaseDataSource.hasValue()
1270 && pValues->Name.equals( sCurrentDatabaseDataSource ) )
1271 {
1272 aCurrentDatabaseDataSource = pValues->Value;
1273 }
1274 else if ( !aCurrentDatabaseCommand.hasValue()
1275 && pValues->Name.equals( sCurrentDatabaseCommand ) )
1276 {
1277 aCurrentDatabaseCommand = pValues->Value;
1278 }
1279 else if ( !aCurrentDatabaseCommandType.hasValue()
1280 && pValues->Name.equals( sCurrentDatabaseCommandType ) )
1281 {
1282 aCurrentDatabaseCommandType = pValues->Value;
1283 }
1284 else
1285 {
1286 xProps->setPropertyValue( pValues->Name, pValues->Value );
1287 }
1288 }
1289
1290 // did we find any of the non-default cases?
1291 if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrinterIndependentLayout")) )
1292 bPrinterIndependentLayout = true;
1293 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("AddExternalLeading")) )
1294 bAddExternalLeading = true;
1295 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("AddParaSpacingToTableCells")) )
1296 bAddParaSpacingToTableCells = true;
1297 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseFormerLineSpacing")) )
1298 bUseFormerLineSpacing = true;
1299 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseFormerObjectPositioning")) )
1300 bUseFormerObjectPositioning = true;
1301 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseFormerTextWrapping")) )
1302 bUseFormerTextWrapping = true;
1303 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseOldNumbering")) )
1304 bUseOldNumbering = true;
1305 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("OutlineLevelYieldsNumbering")) )
1306 bOutlineLevelYieldsOutlineRule = true;
1307 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ConsiderTextWrapOnObjPos")) )
1308 bConsiderWrapOnObjPos = true;
1309 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("IgnoreFirstLineIndentInNumbering")) )
1310 bIgnoreFirstLineIndentInNumbering = true;
1311 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("DoNotJustifyLinesWithManualBreak")) )
1312 bDoNotJustifyLinesWithManualBreak = true;
1313 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("DoNotResetParaAttrsForNumFont")) )
1314 bDoNotResetParaAttrsForNumFont = true;
1315 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("LoadReadonly")) )
1316 bLoadReadonly = true;
1317 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("DoNotCaptureDrawObjsOnPage")) )
1318 bDoNotCaptureDrawObjsOnPage = true;
1319 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ClipAsCharacterAnchoredWriterFlyFrames")) )
1320 bClipAsCharacterAnchoredWriterFlyFrames = true;
1321 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UnxForceZeroExtLeading")) )
1322 bUnixForceZeroExtLeading = true;
1323 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseOldPrinterMetrics")) )
1324 bUseOldPrinterMetrics = true;
1325 }
1326 catch( Exception& )
1327 {
1328 DBG_ERROR( "SwXMLImport::SetConfigurationSettings: Exception!" );
1329 }
1330 }
1331 pValues++;
1332 }
1333
1334 // apply current database properties
1335 {
1336 if ( aCurrentDatabaseDataSource.hasValue() )
1337 {
1338 xProps->setPropertyValue( sCurrentDatabaseDataSource, aCurrentDatabaseDataSource );
1339 }
1340 if ( aCurrentDatabaseCommand.hasValue() )
1341 {
1342 xProps->setPropertyValue( sCurrentDatabaseCommand, aCurrentDatabaseCommand );
1343 }
1344 if ( aCurrentDatabaseCommandType.hasValue() )
1345 {
1346 xProps->setPropertyValue( sCurrentDatabaseCommandType, aCurrentDatabaseCommandType );
1347 }
1348 }
1349
1350 // finally, treat the non-default cases
1351
1352 // introduce boolean, that indicates a document, written by version prior SO8.
1353 const bool bDocumentPriorSO8 = !bConsiderWrapOnObjPos;
1354
1355 if( ! bPrinterIndependentLayout )
1356 {
1357 Any aAny;
1358 sal_Int16 nTmp = document::PrinterIndependentLayout::DISABLED;
1359 aAny <<= nTmp;
1360 xProps->setPropertyValue(
1361 OUString( RTL_CONSTASCII_USTRINGPARAM("PrinterIndependentLayout") ),
1362 aAny );
1363 }
1364
1365 if( ! bAddExternalLeading )
1366 {
1367 xProps->setPropertyValue(
1368 OUString( RTL_CONSTASCII_USTRINGPARAM("AddExternalLeading")), makeAny( false ) );
1369 }
1370
1371 if( ! bUseFormerLineSpacing )
1372 {
1373 xProps->setPropertyValue(
1374 OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerLineSpacing")), makeAny( true ) );
1375 }
1376
1377 if( !bUseFormerObjectPositioning )
1378 {
1379 xProps->setPropertyValue(
1380 OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerObjectPositioning")), makeAny( true ) );
1381 }
1382
1383 if( !bUseOldNumbering )
1384 {
1385 Any aAny;
1386 sal_Bool bOldNum = true;
1387 aAny.setValue(&bOldNum, ::getBooleanCppuType());
1388 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("UseOldNumbering")), aAny );
1389 }
1390
1391 if( !bOutlineLevelYieldsOutlineRule )
1392 {
1393 Any aAny;
1394 sal_Bool bTmp = true;
1395 aAny.setValue(&bTmp, ::getBooleanCppuType());
1396 xProps->setPropertyValue
1397 (OUString( RTL_CONSTASCII_USTRINGPARAM
1398 ("OutlineLevelYieldsNumbering")),
1399 aAny );
1400 }
1401
1402 if( !bAddParaSpacingToTableCells )
1403 {
1404 xProps->setPropertyValue(
1405 OUString( RTL_CONSTASCII_USTRINGPARAM("AddParaSpacingToTableCells")), makeAny( false ) );
1406 }
1407
1408 if( !bUseFormerTextWrapping )
1409 {
1410 xProps->setPropertyValue(
1411 OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerTextWrapping")), makeAny( true ) );
1412 }
1413
1414 if( !bConsiderWrapOnObjPos )
1415 {
1416 xProps->setPropertyValue(
1417 OUString( RTL_CONSTASCII_USTRINGPARAM("ConsiderTextWrapOnObjPos")), makeAny( false ) );
1418 }
1419
1420 // FME 2005-05-27 #i47448#
1421 // For SO7pp4, part of the 'new numbering' stuff has been backported from
1422 // SO8. Unfortunately, only part of it and by using the same compatibility option
1423 // like in SO8. Therefore documents generated with SO7pp4, containing
1424 // numbered paragraphs with first line indent differ between SO7pp4 and
1425 // SO8. In order to fix this for SO8pp1, I introduce a new compatiblity
1426 // flag 'bIgnoreFirstLineIndentInNumbering'. This flag has to be set for all
1427 // documents < SO8, but not for SO8. So if the property is not present, the
1428 // flag will be set to 'true'. SO8 documents surely have the
1429 // 'ConsiderWrapOnObjPos' property set (no matter if 'true' or 'false'),
1430 // therefore the correct condition to set this flag is this:
1431 if( !bIgnoreFirstLineIndentInNumbering && bDocumentPriorSO8 )
1432 {
1433 xProps->setPropertyValue(
1434 OUString( RTL_CONSTASCII_USTRINGPARAM("IgnoreFirstLineIndentInNumbering")), makeAny( true ) );
1435 }
1436
1437 // This flag has to be set for all documents < SO8
1438 if ( !bDoNotJustifyLinesWithManualBreak && bDocumentPriorSO8 )
1439 {
1440 xProps->setPropertyValue(
1441 OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotJustifyLinesWithManualBreak")), makeAny( true ) );
1442 }
1443 // <--
1444
1445 // This flag has to be set for all documents < SO8
1446 if ( !bDoNotResetParaAttrsForNumFont && bDocumentPriorSO8 )
1447 {
1448 xProps->setPropertyValue(
1449 OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotResetParaAttrsForNumFont")), makeAny( true ) );
1450 }
1451
1452 if ( !bLoadReadonly )
1453 {
1454 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("LoadReadonly") ), makeAny( false ) );
1455 }
1456
1457 // This flag has to be set for all documents < SO8
1458 if ( !bDoNotCaptureDrawObjsOnPage && bDocumentPriorSO8 )
1459 {
1460 xProps->setPropertyValue(
1461 OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotCaptureDrawObjsOnPage") ), makeAny( true ) );
1462 }
1463
1464 // This flag has to be set for all documents < SO8
1465 if ( !bClipAsCharacterAnchoredWriterFlyFrames && bDocumentPriorSO8 )
1466 {
1467 xProps->setPropertyValue(
1468 OUString( RTL_CONSTASCII_USTRINGPARAM("ClipAsCharacterAnchoredWriterFlyFrames") ), makeAny( true ) );
1469 }
1470
1471 if ( !bUnixForceZeroExtLeading )
1472 {
1473 xProps->setPropertyValue(
1474 OUString( RTL_CONSTASCII_USTRINGPARAM("UnxForceZeroExtLeading") ), makeAny( true ) );
1475 }
1476
1477 if ( !bUseOldPrinterMetrics )
1478 {
1479 xProps->setPropertyValue(
1480 OUString( RTL_CONSTASCII_USTRINGPARAM("UseOldPrinterMetrics") ), makeAny( true ) );
1481 }
1482 // <--
1483
1484 Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1485 Reference < XText > xText = xTextDoc->getText();
1486 Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1487 ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
1488 if( xTextTunnel.is() )
1489 {
1490 SwXText *pText = reinterpret_cast< SwXText *>(
1491 sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1492 ASSERT( pText, "SwXText missing" );
1493 if( pText )
1494 {
1495 SwDoc *pDoc = pText->GetDoc();
1496 if( pDoc )
1497 {
1498 SfxPrinter *pPrinter = pDoc->getPrinter( false );
1499 if( pPrinter )
1500 {
1501 // If the printer is known, then the OLE objects will
1502 // already have correct sizes, and we don't have to call
1503 // PrtOLENotify again. Otherwise we have to call it.
1504 // The flag might be set from setting the printer, so it
1505 // it is required to clear it.
1506 pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
1507
1508 // FME 2007-05-14 #147385# old printer metrics compatibility
1509 if ( pDoc->get(IDocumentSettingAccess::USE_OLD_PRINTER_METRICS ) &&
1510 !pDoc->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
1511 {
1512 pPrinter->Compat_OldPrinterMetrics( true );
1513 pDoc->GetDocShell()->UpdateFontList();
1514 }
1515 }
1516 }
1517 }
1518 }
1519 }
1520
1521
SetDocumentSpecificSettings(const::rtl::OUString & _rSettingsGroupName,const Sequence<PropertyValue> & _rSettings)1522 void SwXMLImport::SetDocumentSpecificSettings(
1523 const ::rtl::OUString& _rSettingsGroupName,
1524 const Sequence< PropertyValue>& _rSettings )
1525 {
1526 // the only doc-specific settings group we know so far are the XForms settings
1527 if ( !IsXMLToken( _rSettingsGroupName, XML_XFORM_MODEL_SETTINGS ) )
1528 return;
1529
1530 // preserve the settings for a later iteration - we are currently reading the settings.xml,
1531 // the content.xml will be read later, by another instance of SwXMLImport
1532 OSL_ENSURE( xLateInitSettings.is(), "SwXMLImport::SetDocumentSpecificSettings: no storage for those settings!" );
1533 if ( !xLateInitSettings.is() )
1534 return;
1535
1536 try
1537 {
1538 if ( xLateInitSettings->hasByName( _rSettingsGroupName ) )
1539 {
1540 xLateInitSettings->replaceByName( _rSettingsGroupName, makeAny( _rSettings ) );
1541 OSL_ENSURE( false, "SwXMLImport::SetDocumentSpecificSettings: already have settings for this model!" );
1542 }
1543 else
1544 xLateInitSettings->insertByName( _rSettingsGroupName, makeAny( _rSettings ) );
1545 }
1546 catch( const Exception& )
1547 {
1548 DBG_UNHANDLED_EXCEPTION();
1549 }
1550 }
1551
initialize(const Sequence<Any> & aArguments)1552 void SwXMLImport::initialize(
1553 const Sequence<Any>& aArguments )
1554 throw( uno::Exception, uno::RuntimeException)
1555 {
1556 // delegate to super class
1557 SvXMLImport::initialize(aArguments);
1558
1559 // we are only looking for a PropertyValue "PreserveRedlineMode"
1560 sal_Int32 nLength = aArguments.getLength();
1561 for(sal_Int32 i = 0; i < nLength; i++)
1562 {
1563 beans::PropertyValue aValue;
1564 if ( aArguments[i] >>= aValue )
1565 {
1566 if (aValue.Name.equalsAsciiL(
1567 RTL_CONSTASCII_STRINGPARAM("PreserveRedlineMode")))
1568 {
1569 OSL_VERIFY( aValue.Value >>= bPreserveRedlineMode );
1570 }
1571 continue;
1572 }
1573
1574 beans::NamedValue aNamedValue;
1575 if ( aArguments[i] >>= aNamedValue )
1576 {
1577 if (aNamedValue.Name.equalsAsciiL(
1578 RTL_CONSTASCII_STRINGPARAM("LateInitSettings")))
1579 {
1580 OSL_VERIFY( aNamedValue.Value >>= xLateInitSettings );
1581 }
1582 }
1583 }
1584 }
1585
1586
1587 //
1588 // UNO component registration helper functions
1589 //
1590
SwXMLImport_getImplementationName()1591 OUString SAL_CALL SwXMLImport_getImplementationName() throw()
1592 {
1593 return OUString( RTL_CONSTASCII_USTRINGPARAM(
1594 "com.sun.star.comp.Writer.XMLOasisImporter" ) );
1595 }
1596
SwXMLImport_getSupportedServiceNames()1597 uno::Sequence< OUString > SAL_CALL SwXMLImport_getSupportedServiceNames()
1598 throw()
1599 {
1600 const OUString aServiceName( SwXMLImport_getImplementationName() );
1601 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1602 return aSeq;
1603 }
1604
SwXMLImport_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1605 uno::Reference< uno::XInterface > SAL_CALL SwXMLImport_createInstance(
1606 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1607 throw( uno::Exception )
1608 {
1609 // #110680#
1610 // return (cppu::OWeakObject*)new SwXMLImport(IMPORT_ALL);
1611 return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_ALL );
1612 }
1613
SwXMLImportStyles_getImplementationName()1614 OUString SAL_CALL SwXMLImportStyles_getImplementationName() throw()
1615 {
1616 return OUString( RTL_CONSTASCII_USTRINGPARAM(
1617 "com.sun.star.comp.Writer.XMLOasisStylesImporter" ) );
1618 }
1619
SwXMLImportStyles_getSupportedServiceNames()1620 uno::Sequence< OUString > SAL_CALL SwXMLImportStyles_getSupportedServiceNames()
1621 throw()
1622 {
1623 const OUString aServiceName( SwXMLImportStyles_getImplementationName() );
1624 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1625 return aSeq;
1626 }
1627
SwXMLImportStyles_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1628 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportStyles_createInstance(
1629 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1630 throw( uno::Exception )
1631 {
1632 // #110680#
1633 //return (cppu::OWeakObject*)new SwXMLImport(
1634 // IMPORT_STYLES | IMPORT_MASTERSTYLES | IMPORT_AUTOSTYLES |
1635 // IMPORT_FONTDECLS );
1636 return (cppu::OWeakObject*)new SwXMLImport(
1637 rSMgr,
1638 IMPORT_STYLES | IMPORT_MASTERSTYLES | IMPORT_AUTOSTYLES |
1639 IMPORT_FONTDECLS );
1640 }
1641
SwXMLImportContent_getImplementationName()1642 OUString SAL_CALL SwXMLImportContent_getImplementationName() throw()
1643 {
1644 return OUString( RTL_CONSTASCII_USTRINGPARAM(
1645 "com.sun.star.comp.Writer.XMLOasisContentImporter" ) );
1646 }
1647
SwXMLImportContent_getSupportedServiceNames()1648 uno::Sequence< OUString > SAL_CALL SwXMLImportContent_getSupportedServiceNames()
1649 throw()
1650 {
1651 const OUString aServiceName( SwXMLImportContent_getImplementationName() );
1652 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1653 return aSeq;
1654 }
1655
SwXMLImportContent_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1656 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportContent_createInstance(
1657 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1658 throw( uno::Exception )
1659 {
1660 // #110680#
1661 //return (cppu::OWeakObject*)new SwXMLImport(
1662 // IMPORT_AUTOSTYLES | IMPORT_CONTENT | IMPORT_SCRIPTS |
1663 // IMPORT_FONTDECLS );
1664 return (cppu::OWeakObject*)new SwXMLImport(
1665 rSMgr,
1666 IMPORT_AUTOSTYLES | IMPORT_CONTENT | IMPORT_SCRIPTS |
1667 IMPORT_FONTDECLS );
1668 }
1669
SwXMLImportMeta_getImplementationName()1670 OUString SAL_CALL SwXMLImportMeta_getImplementationName() throw()
1671 {
1672 return OUString( RTL_CONSTASCII_USTRINGPARAM(
1673 "com.sun.star.comp.Writer.XMLOasisMetaImporter" ) );
1674 }
1675
SwXMLImportMeta_getSupportedServiceNames()1676 uno::Sequence< OUString > SAL_CALL SwXMLImportMeta_getSupportedServiceNames()
1677 throw()
1678 {
1679 const OUString aServiceName( SwXMLImportMeta_getImplementationName() );
1680 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1681 return aSeq;
1682 }
1683
SwXMLImportMeta_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1684 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportMeta_createInstance(
1685 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1686 throw( uno::Exception )
1687 {
1688 // #110680#
1689 // return (cppu::OWeakObject*)new SwXMLImport( IMPORT_META );
1690 return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_META );
1691 }
1692
SwXMLImportSettings_getImplementationName()1693 OUString SAL_CALL SwXMLImportSettings_getImplementationName() throw()
1694 {
1695 return OUString( RTL_CONSTASCII_USTRINGPARAM(
1696 "com.sun.star.comp.Writer.XMLOasisSettingsImporter" ) );
1697 }
1698
SwXMLImportSettings_getSupportedServiceNames()1699 uno::Sequence< OUString > SAL_CALL SwXMLImportSettings_getSupportedServiceNames()
1700 throw()
1701 {
1702 const OUString aServiceName( SwXMLImportSettings_getImplementationName() );
1703 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1704 return aSeq;
1705 }
1706
SwXMLImportSettings_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1707 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportSettings_createInstance(
1708 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1709 throw( uno::Exception )
1710 {
1711 // #110680#
1712 // return (cppu::OWeakObject*)new SwXMLImport( IMPORT_SETTINGS );
1713 return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_SETTINGS );
1714 }
1715
1716
1717 // XServiceInfo
1718 // override empty method from parent class
getImplementationName()1719 OUString SAL_CALL SwXMLImport::getImplementationName()
1720 throw(RuntimeException)
1721 {
1722 switch( getImportFlags() )
1723 {
1724 case IMPORT_ALL:
1725 return SwXMLImport_getImplementationName();
1726 case (IMPORT_STYLES|IMPORT_MASTERSTYLES|IMPORT_AUTOSTYLES|IMPORT_FONTDECLS):
1727 return SwXMLImportStyles_getImplementationName();
1728 case (IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS):
1729 return SwXMLImportContent_getImplementationName();
1730 case IMPORT_META:
1731 return SwXMLImportMeta_getImplementationName();
1732 case IMPORT_SETTINGS:
1733 return SwXMLImportSettings_getImplementationName();
1734 default:
1735 // generic name for 'unknown' cases
1736 return OUString( RTL_CONSTASCII_USTRINGPARAM(
1737 "com.sun.star.comp.Writer.SwXMLImport" ) );
1738 }
1739 }
1740
GetDocFromXMLImport(SvXMLImport & rImport)1741 SwDoc* SwImport::GetDocFromXMLImport( SvXMLImport& rImport )
1742 {
1743 uno::Reference<lang::XUnoTunnel> xModelTunnel( rImport.GetModel(), uno::UNO_QUERY );
1744 SwXTextDocument *pTxtDoc = reinterpret_cast< SwXTextDocument *>(
1745 sal::static_int_cast< sal_IntPtr >( xModelTunnel->getSomething(SwXTextDocument::getUnoTunnelId() )));
1746 ASSERT( pTxtDoc, "Where is my model?" )
1747 ASSERT( pTxtDoc->GetDocShell(), "Where is my shell?" )
1748 SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
1749 ASSERT( pDoc, "Where is my document?" )
1750 return pDoc;
1751 }
1752
1753
initXForms()1754 void SwXMLImport::initXForms()
1755 {
1756 // obtain SwDoc
1757 Reference<XUnoTunnel> xDocTunnel( GetModel(), UNO_QUERY );
1758 if( ! xDocTunnel.is() )
1759 return;
1760 SwXTextDocument* pXTextDocument = reinterpret_cast<SwXTextDocument*>(
1761 xDocTunnel->getSomething( SwXTextDocument::getUnoTunnelId() ) );
1762 if( pXTextDocument == NULL )
1763 return;
1764
1765 SwDoc *pDoc = pXTextDocument->GetDocShell()->GetDoc();
1766
1767 // init XForms (if not already done)
1768 // (no default model, since we'll load the models)
1769 if( ! pDoc->isXForms() )
1770 pDoc->initXForms( false );
1771
1772 bInititedXForms = sal_True;
1773 }
1774