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