xref: /trunk/main/sw/source/filter/xml/xmlimp.cxx (revision 26ea3662)
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 	throw(RuntimeException)
545 {
546     if( rId.getLength() == 16
547         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
548 										rId.getConstArray(), 16 ) )
549     {
550 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
551     }
552 	return SvXMLImport::getSomething( rId );
553 }
554 
lcl_xml_GetSwXTextCursor(const Reference<XTextCursor> & rTextCursor)555 OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
556 {
557 	Reference<XUnoTunnel> xCrsrTunnel( rTextCursor, UNO_QUERY );
558 	ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
559 	if( !xCrsrTunnel.is() )
560 		return 0;
561 	OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
562 			sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething(	OTextCursorHelper::getUnoTunnelId() )));
563 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
564 	return pTxtCrsr;
565 }
566 
startDocument(void)567 void SwXMLImport::startDocument( void )
568 	throw( xml::sax::SAXException, uno::RuntimeException )
569 {
570     // delegate to parent
571     SvXMLImport::startDocument();
572 
573 	DBG_ASSERT( GetModel().is(), "model is missing" );
574 	if( !GetModel().is() )
575 		return;
576 
577     // this method will modify the document directly -> lock SolarMutex
578 	vos::OGuard aGuard(Application::GetSolarMutex());
579 
580 
581 	Reference< XPropertySet > xImportInfo( getImportInfo() );
582 	Reference< XPropertySetInfo > xPropertySetInfo;
583    	if( xImportInfo.is() )
584 		xPropertySetInfo = xImportInfo->getPropertySetInfo();
585 	if( xPropertySetInfo.is() )
586 	{
587 		Any aAny;
588 		// insert style mode?
589 		OUString sStyleInsertModeFamilies(
590 				RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeFamilies"));
591 		if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeFamilies) )
592 		{
593 			aAny = xImportInfo->getPropertyValue(sStyleInsertModeFamilies);
594 			Sequence< OUString> aFamiliesSeq;
595 			if( aAny >>= aFamiliesSeq )
596 			{
597 				OUString sFrameStyles( RTL_CONSTASCII_USTRINGPARAM ( "FrameStyles" ) );
598 				OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM ( "PageStyles" ) );
599 				OUString sCharacterStyles( RTL_CONSTASCII_USTRINGPARAM ( "CharacterStyles" ) );
600 				OUString sParagraphStyles( RTL_CONSTASCII_USTRINGPARAM ( "ParagraphStyles" ) );
601 				OUString sNumberingStyles( RTL_CONSTASCII_USTRINGPARAM ( "NumberingStyles" ) );
602 				sal_uInt16 nFamilyMask = 0U;
603 				sal_Int32 nCount = aFamiliesSeq.getLength();
604 				const OUString *pSeq = aFamiliesSeq.getConstArray();
605 				for( sal_Int32 i=0; i < nCount; i++ )
606 				{
607 					const OUString& rFamily = pSeq[i];
608         			if( rFamily==sFrameStyles )
609 						nFamilyMask |= SFX_STYLE_FAMILY_FRAME;
610 					else if( rFamily==sPageStyles )
611 						nFamilyMask |= SFX_STYLE_FAMILY_PAGE;
612 					else if( rFamily==sCharacterStyles )
613 						nFamilyMask |= SFX_STYLE_FAMILY_CHAR;
614 					else if( rFamily==sParagraphStyles )
615 						nFamilyMask |= SFX_STYLE_FAMILY_PARA;
616 					else if( rFamily==sNumberingStyles )
617 						nFamilyMask |= SFX_STYLE_FAMILY_PSEUDO;
618 				}
619 
620 				sal_Bool bOverwrite = sal_False;
621 				OUString sStyleInsertModeOverwrite(
622 					RTL_CONSTASCII_USTRINGPARAM("StyleInsertModeOverwrite"));
623 				if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeOverwrite) )
624 				{
625 					aAny = xImportInfo->getPropertyValue(sStyleInsertModeOverwrite);
626 					if( aAny.getValueType() == ::getBooleanCppuType() &&
627 						*static_cast<const sal_Bool*>(aAny.getValue()) )
628 						bOverwrite = sal_True;
629 				}
630 
631 				setStyleInsertMode( nFamilyMask, bOverwrite );
632 			}
633 		}
634 
635 		// text insert mode?
636 		OUString sTextInsertModeRange(
637 				RTL_CONSTASCII_USTRINGPARAM("TextInsertModeRange"));
638 		if( xPropertySetInfo->hasPropertyByName(sTextInsertModeRange) )
639 		{
640 			aAny = xImportInfo->getPropertyValue(sTextInsertModeRange);
641 			Reference<XTextRange> xInsertTextRange;
642 			if( aAny >>= xInsertTextRange )
643 				setTextInsertMode( xInsertTextRange );
644 		}
645 
646 		// auto text mode
647 		OUString sAutoTextMode(
648 				RTL_CONSTASCII_USTRINGPARAM("AutoTextMode"));
649 		if( xPropertySetInfo->hasPropertyByName(sAutoTextMode) )
650 		{
651 			aAny = xImportInfo->getPropertyValue(sAutoTextMode);
652 			if( aAny.getValueType() == ::getBooleanCppuType() &&
653 				*static_cast<const sal_Bool*>(aAny.getValue()) )
654 					setBlockMode();
655 		}
656 
657 		// organizer mode
658 		OUString sOrganizerMode(
659 				RTL_CONSTASCII_USTRINGPARAM("OrganizerMode"));
660 		if( xPropertySetInfo->hasPropertyByName(sOrganizerMode) )
661 		{
662 			aAny = xImportInfo->getPropertyValue(sOrganizerMode);
663 			if( aAny.getValueType() == ::getBooleanCppuType() &&
664 				*static_cast<const sal_Bool*>(aAny.getValue()) )
665 					setOrganizerMode();
666 		}
667 	}
668 
669 	// There only is a text cursor by now if we are in insert mode. In any
670 	// other case we have to create one at the start of the document.
671 	// We also might change into the insert mode later, so we have to make
672 	// sure to first set the insert mode and then create the text import
673 	// helper. Otherwise it won't have the insert flag set!
674 	OTextCursorHelper *pTxtCrsr = 0;
675 	Reference < XTextCursor > xTextCursor;
676 	if( HasTextImport() )
677    		xTextCursor = GetTextImport()->GetCursor();
678 	if( !xTextCursor.is() )
679 	{
680 		Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
681 		Reference < XText > xText = xTextDoc->getText();
682 		xTextCursor = xText->createTextCursor();
683 		SwCrsrShell *pCrsrSh = 0;
684 		SwDoc *pDoc = 0;
685 		if( IMPORT_ALL == getImportFlags() )
686 		{
687 			pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
688 			ASSERT( pTxtCrsr, "SwXTextCursor missing" );
689 			if( !pTxtCrsr )
690 				return;
691 
692 			pDoc = pTxtCrsr->GetDoc();
693 			ASSERT( pDoc, "SwDoc missing" );
694 			if( !pDoc )
695 				return;
696 
697 			// Is there a edit shell. If yes, then we are currently inserting
698 			// a document. We then have to insert at the current edit shell's
699 			// cursor position. That not quite clean code, but there is no other
700 			// way currently.
701 			pCrsrSh = pDoc->GetEditShell();
702 		}
703 		if( pCrsrSh )
704 		{
705             const uno::Reference<text::XTextRange> xInsertTextRange(
706                 SwXTextRange::CreateXTextRange(
707                     *pDoc, *pCrsrSh->GetCrsr()->GetPoint(), 0 ) );
708 			setTextInsertMode( xInsertTextRange );
709 			xTextCursor = GetTextImport()->GetCursor();
710 			pTxtCrsr = 0;
711 		}
712 		else
713 			GetTextImport()->SetCursor( xTextCursor );
714 	}
715 
716 	if( (getImportFlags() & (IMPORT_CONTENT|IMPORT_MASTERSTYLES)) == 0 )
717 		return;
718 
719 	if( !pTxtCrsr  )
720 		pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
721 	ASSERT( pTxtCrsr, "SwXTextCursor missing" );
722 	if( !pTxtCrsr )
723 		return;
724 
725 	SwDoc *pDoc = pTxtCrsr->GetDoc();
726 	ASSERT( pDoc, "SwDoc missing" );
727 	if( !pDoc )
728 		return;
729 
730 	if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
731 	{
732 		pSttNdIdx = new SwNodeIndex( pDoc->GetNodes() );
733 		if( IsInsertMode() )
734 		{
735 			SwPaM *pPaM = pTxtCrsr->GetPaM();
736 			const SwPosition* pPos = pPaM->GetPoint();
737 
738 			// Split once and remember the node that has been splitted.
739 			pDoc->SplitNode( *pPos, false );
740 			*pSttNdIdx = pPos->nNode.GetIndex()-1;
741 
742 			// Split again.
743 			pDoc->SplitNode( *pPos, false );
744 
745 			// Insert all content into the new node
746 			pPaM->Move( fnMoveBackward );
747 			pDoc->SetTxtFmtColl
748                 ( *pPaM, pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD, false ) );
749 		}
750 	}
751 
752 	// We need a draw model to be able to set the z order
753     // --> OD 2005-08-08 #i52858# - method name changed
754     pDoc->GetOrCreateDrawModel();
755     // <--
756 
757 	// SJ: #i49801# locking the modell to disable repaints
758 	SwDrawModel* pDrawModel = pDoc->GetDrawModel();
759 	if ( pDrawModel )
760 		pDrawModel->setLock( sal_True );
761 
762 	if( !GetGraphicResolver().is() )
763 	{
764 		pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_READ );
765 		Reference< document::XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
766 		SetGraphicResolver( xGraphicResolver );
767 	}
768 
769 	if( !GetEmbeddedResolver().is() )
770 	{
771         SfxObjectShell *pPersist = pDoc->GetPersist();
772 		if( pPersist )
773 		{
774 			pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
775 											*pPersist,
776 											EMBEDDEDOBJECTHELPER_MODE_READ );
777 			Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
778 			SetEmbeddedResolver( xEmbeddedResolver );
779 		}
780 	}
781 }
782 
endDocument(void)783 void SwXMLImport::endDocument( void )
784 	throw( xml::sax::SAXException, uno::RuntimeException )
785 {
786 	DBG_ASSERT( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
787 	if( !GetModel().is() )
788 		return;
789 
790     // this method will modify the document directly -> lock SolarMutex
791 	vos::OGuard aGuard(Application::GetSolarMutex());
792 
793 	if( pGraphicResolver )
794 		SvXMLGraphicHelper::Destroy( pGraphicResolver );
795 	if( pEmbeddedResolver )
796 	    SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
797 	// Clear the shape import to sort the shapes  (and not in the
798 	// destructor that might be called after the import has finished
799 	// for Java filters.
800 	if( HasShapeImport() )
801 		ClearShapeImport();
802 
803 
804 	SwDoc *pDoc = 0;
805 	if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
806 	{
807 		Reference<XUnoTunnel> xCrsrTunnel( GetTextImport()->GetCursor(),
808 									   	   UNO_QUERY);
809 		ASSERT( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
810 		OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
811 				sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
812 		ASSERT( pTxtCrsr, "SwXTextCursor missing" );
813 		SwPaM *pPaM = pTxtCrsr->GetPaM();
814 		if( IsInsertMode() && pSttNdIdx->GetIndex() )
815 		{
816 			// If we are in insert mode, join the splitted node that is in front
817 			// of the new content with the first new node. Or in other words:
818 			// Revert the first split node.
819 			SwTxtNode* pTxtNode = pSttNdIdx->GetNode().GetTxtNode();
820 			SwNodeIndex aNxtIdx( *pSttNdIdx );
821 			if( pTxtNode && pTxtNode->CanJoinNext( &aNxtIdx ) &&
822 				pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex() )
823 			{
824 				// If the PaM points to the first new node, move the PaM to the
825 				// end of the previous node.
826 				if( pPaM && pPaM->GetPoint()->nNode == aNxtIdx )
827 				{
828 					pPaM->GetPoint()->nNode = *pSttNdIdx;
829 					pPaM->GetPoint()->nContent.Assign( pTxtNode,
830 											pTxtNode->GetTxt().Len() );
831 				}
832 
833 #ifdef DBG_UTIL
834 				// !!! This should be impossible !!!!
835 				ASSERT( pSttNdIdx->GetIndex()+1 !=
836 										pPaM->GetBound( sal_True ).nNode.GetIndex(),
837 						"PaM.Bound1 point to new node " );
838 				ASSERT( pSttNdIdx->GetIndex()+1 !=
839 										pPaM->GetBound( sal_False ).nNode.GetIndex(),
840 						"PaM.Bound2 points to new node" );
841 
842 				if( pSttNdIdx->GetIndex()+1 ==
843 										pPaM->GetBound( sal_True ).nNode.GetIndex() )
844 				{
845 					sal_uInt16 nCntPos =
846 							pPaM->GetBound( sal_True ).nContent.GetIndex();
847 					pPaM->GetBound( sal_True ).nContent.Assign( pTxtNode,
848 							pTxtNode->GetTxt().Len() + nCntPos );
849 				}
850 				if( pSttNdIdx->GetIndex()+1 ==
851 								pPaM->GetBound( sal_False ).nNode.GetIndex() )
852 				{
853 					sal_uInt16 nCntPos =
854 							pPaM->GetBound( sal_False ).nContent.GetIndex();
855 					pPaM->GetBound( sal_False ).nContent.Assign( pTxtNode,
856 							pTxtNode->GetTxt().Len() + nCntPos );
857 				}
858 #endif
859 				// If the first new node isn't empty, convert  the node's text
860 				// attributes into hints. Otherwise, set the new node's
861 				// paragraph style at the previous (empty) node.
862 				SwTxtNode* pDelNd = aNxtIdx.GetNode().GetTxtNode();
863 				if( pTxtNode->GetTxt().Len() )
864 					pDelNd->FmtToTxtAttr( pTxtNode );
865 				else
866 					pTxtNode->ChgFmtColl( pDelNd->GetTxtColl() );
867 				pTxtNode->JoinNext();
868 			}
869 		}
870 
871 		SwPosition* pPos = pPaM->GetPoint();
872 		DBG_ASSERT( !pPos->nContent.GetIndex(), "last paragraph isn't empty" );
873 		if( !pPos->nContent.GetIndex() )
874 		{
875 			SwTxtNode* pCurrNd;
876 			sal_uLong nNodeIdx = pPos->nNode.GetIndex();
877 			pDoc = pPaM->GetDoc();
878 
879 			DBG_ASSERT( pPos->nNode.GetNode().IsCntntNode(),
880 						"insert position is not a content node" );
881 			if( !IsInsertMode() )
882 			{
883 				// If we're not in insert mode, the last node is deleted.
884 				const SwNode *pPrev = pDoc->GetNodes()[nNodeIdx -1];
885 				if( pPrev->IsCntntNode() ||
886 				 	( pPrev->IsEndNode() &&
887 					  pPrev->StartOfSectionNode()->IsSectionNode() ) )
888 				{
889 					SwCntntNode* pCNd = pPaM->GetCntntNode();
890 					if( pCNd && pCNd->StartOfSectionIndex()+2 <
891 						pCNd->EndOfSectionIndex() )
892 					{
893 						pPaM->GetBound(sal_True).nContent.Assign( 0, 0 );
894 						pPaM->GetBound(sal_False).nContent.Assign( 0, 0 );
895 						pDoc->GetNodes().Delete( pPaM->GetPoint()->nNode );
896 					}
897 				}
898 			}
899 			else if( 0 != (pCurrNd = pDoc->GetNodes()[nNodeIdx]->GetTxtNode()) )
900 			{
901 				// Id we're in insert mode, the empty node is joined with
902 				// the next and the previous one.
903 				if( pCurrNd->CanJoinNext( &pPos->nNode ))
904 				{
905 					SwTxtNode* pNextNd = pPos->nNode.GetNode().GetTxtNode();
906 					pPos->nContent.Assign( pNextNd, 0 );
907 					pPaM->SetMark(); pPaM->DeleteMark();
908 					pNextNd->JoinPrev();
909 
910 					// Remove line break that has been inserted by the import,
911 					// but only if one has been inserted!
912 					if( pNextNd->CanJoinPrev(/* &pPos->nNode*/ ) &&
913 					 	*pSttNdIdx != pPos->nNode )
914 					{
915 //						SwTxtNode* pPrevNd = pPos->nNode.GetNode().GetTxtNode();
916 //						pPos->nContent.Assign( pPrevNd, 0 );
917 //						pPaM->SetMark(); pPaM->DeleteMark();
918 //						pPrevNd->JoinNext();
919 						pNextNd->JoinPrev();
920 					}
921 				}
922 				else if( !pCurrNd->GetTxt().Len() )
923 				{
924 					pPos->nContent.Assign( 0, 0 );
925 					pPaM->SetMark(); pPaM->DeleteMark();
926 					pDoc->GetNodes().Delete( pPos->nNode, 1 );
927 					pPaM->Move( fnMoveBackward );
928 				}
929 			}
930 		}
931 	}
932 
933     /* #108146# Was called too early. Moved from
934         SwXMLBodyContext_Impl::EndElement */
935 
936     GetTextImport()->RedlineAdjustStartNodeCursor( sal_False );
937 
938 	if( (getImportFlags() & IMPORT_CONTENT) != 0 ||
939 		((getImportFlags() & IMPORT_MASTERSTYLES) != 0 && IsStylesOnlyMode()) )
940 	{
941 		// pDoc might be 0. In this case UpdateTxtCollCondition is looking
942 		// for it itself.
943 		UpdateTxtCollConditions( pDoc );
944 	}
945 
946 	GetTextImport()->ResetCursor();
947 
948 	delete pSttNdIdx;
949 	pSttNdIdx = 0;
950 
951 	if( (getImportFlags() == IMPORT_ALL ) )
952 	{
953 		// Notify math objects. If we are in the package filter this will
954 		// be done by the filter object itself
955 		if( IsInsertMode() )
956 			pDoc->PrtOLENotify( sal_False );
957 		else if ( pDoc->IsOLEPrtNotifyPending() )
958 			pDoc->PrtOLENotify( sal_True );
959 	}
960 
961 	// SJ: #i49801# -> now permitting repaints
962 	if ( pDoc )
963 	{
964 		SwDrawModel* pDrawModel = pDoc->GetDrawModel();
965 		if ( pDrawModel )
966 			pDrawModel->setLock( sal_False );
967 	}
968 
969     // #i90243#
970     if ( bInititedXForms )
971     {
972         Reference< xforms::XFormsSupplier > xFormsSupp( GetModel(), UNO_QUERY );
973         Reference< XNameAccess > xXForms;
974         if ( xFormsSupp.is() )
975             xXForms = xFormsSupp->getXForms().get();
976 
977         if ( xXForms.is() )
978         {
979             try
980             {
981                 Sequence< beans::PropertyValue > aXFormsSettings;
982 
983                 ::rtl::OUString sXFormsSettingsName( GetXMLToken( XML_XFORM_MODEL_SETTINGS ) );
984                 if ( xLateInitSettings.is() && xLateInitSettings->hasByName( sXFormsSettingsName ) )
985                 {
986                     OSL_VERIFY( xLateInitSettings->getByName( sXFormsSettingsName ) >>= aXFormsSettings );
987                     applyXFormsSettings( xXForms, aXFormsSettings );
988                 }
989             }
990             catch( const Exception& )
991             {
992                 DBG_UNHANDLED_EXCEPTION();
993             }
994         }
995     }
996 
997     // delegate to parent: takes care of error handling
998     SvXMLImport::endDocument();
999 }
1000 
1001 
1002 // Locally derive XMLTextShapeImportHelper, so we can take care of the
1003 // form import This is Writer, but not text specific, so it should go
1004 // here!
1005 class SvTextShapeImportHelper : public XMLTextShapeImportHelper
1006 {
1007 	// hold own reference form import helper, because the SvxImport
1008 	// stored in the superclass, from whom we originally got the
1009 	// reference, is already destroyed when we want to use it in the
1010 	// destructor
1011 	UniReference< ::xmloff::OFormLayerXMLImport > rFormImport;
1012 
1013     // hold reference to the one page (if it exists) for calling startPage()
1014     // and endPage. If !xPage.is(), then this document doesn't have a
1015     // XDrawPage.
1016     Reference<drawing::XDrawPage> xPage;
1017 
1018 public:
1019 
1020 	SvTextShapeImportHelper(SvXMLImport& rImp);
1021 	virtual ~SvTextShapeImportHelper();
1022 };
1023 
SvTextShapeImportHelper(SvXMLImport & rImp)1024 SvTextShapeImportHelper::SvTextShapeImportHelper(SvXMLImport& rImp) :
1025 	XMLTextShapeImportHelper(rImp)
1026 {
1027     Reference<drawing::XDrawPageSupplier> xSupplier(rImp.GetModel(),UNO_QUERY);
1028     if (xSupplier.is())
1029 	{
1030         if (rImp.GetFormImport().is())
1031         {
1032 			rImp.GetFormImport()->startPage(xSupplier->getDrawPage());
1033 			rFormImport = rImp.GetFormImport();
1034 		}
1035 
1036         xPage  = xSupplier->getDrawPage();
1037         Reference<XShapes> xShapes( xPage, UNO_QUERY );
1038         XMLShapeImportHelper::startPage( xShapes );
1039 	}
1040 }
1041 
~SvTextShapeImportHelper()1042 SvTextShapeImportHelper::~SvTextShapeImportHelper()
1043 {
1044 	rFormImport->endPage();
1045 
1046     if (xPage.is())
1047     {
1048         Reference<XShapes> xShapes( xPage, UNO_QUERY );
1049         XMLShapeImportHelper::endPage(xShapes);
1050     }
1051 }
1052 
1053 
CreateShapeImport()1054 XMLShapeImportHelper* SwXMLImport::CreateShapeImport()
1055 {
1056 	return new SvTextShapeImportHelper( *this );
1057 }
1058 
CreateFontDeclsContext(const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)1059 SvXMLImportContext *SwXMLImport::CreateFontDeclsContext(
1060 		const OUString& rLocalName,
1061 		const Reference< xml::sax::XAttributeList > & xAttrList )
1062 {
1063 	XMLFontStylesContext *pFSContext =
1064 			new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
1065 									  rLocalName, xAttrList,
1066 									  gsl_getSystemTextEncoding() );
1067 	SetFontDecls( pFSContext );
1068 	return pFSContext;
1069 }
SetViewSettings(const Sequence<PropertyValue> & aViewProps)1070 void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
1071 {
1072 	if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || IsOrganizerMode() || !GetModel().is() )
1073 		return;
1074 
1075     // this method will modify the document directly -> lock SolarMutex
1076 	vos::OGuard aGuard(Application::GetSolarMutex());
1077 
1078 	Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1079 	Reference < XText > xText = xTextDoc->getText();
1080 	Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1081 	ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
1082 	if( !xTextTunnel.is() )
1083 		return;
1084 
1085 	SwXText *pText = reinterpret_cast< SwXText *>(
1086 			sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1087 	ASSERT( pText, "SwXText missing" );
1088 	if( !pText )
1089 		return;
1090 
1091 	SwDoc *pDoc = pText->GetDoc();
1092 	Rectangle aRect;
1093 	if( pDoc->GetDocShell() )
1094         aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
1095         //TODO/LATER: why that cast?!
1096         //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea();
1097 
1098     sal_Int32 nCount = aViewProps.getLength();
1099     const PropertyValue *pValue = aViewProps.getConstArray();
1100 
1101     sal_Int64 nTmp = 0;
1102     sal_Bool bShowRedlineChanges = sal_False, bBrowseMode = sal_False;
1103     sal_Bool bChangeShowRedline = sal_False, bChangeBrowseMode = sal_False;
1104 
1105     //TODO/LATER: why that cast?!
1106     sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
1107     //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MAP_TWIP;
1108 
1109     for (sal_Int32 i = 0; i < nCount ; i++)
1110     {
1111         if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaTop" ) ) )
1112         {
1113             pValue->Value >>= nTmp;
1114             aRect.setY( static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp) );
1115         }
1116         else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaLeft" ) ) )
1117         {
1118             pValue->Value >>= nTmp;
1119             aRect.setX( static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp) );
1120         }
1121         else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaWidth" ) ) )
1122         {
1123             pValue->Value >>= nTmp;
1124 			Size aSize( aRect.GetSize() );
1125             aSize.Width() = static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp);
1126             aRect.SetSize( aSize );
1127         }
1128         else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ViewAreaHeight" ) ) )
1129         {
1130             pValue->Value >>= nTmp;
1131 			Size aSize( aRect.GetSize() );
1132             aSize.Height() = static_cast< long >(bTwip ? MM100_TO_TWIP ( nTmp ) : nTmp);
1133             aRect.SetSize( aSize );
1134         }
1135         else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowRedlineChanges" ) ) )
1136         {
1137             bShowRedlineChanges = *(sal_Bool *)(pValue->Value.getValue());
1138 			bChangeShowRedline = sal_True;
1139         }
1140 // #105372#: Headers and footers are not displayed in BrowseView anymore
1141 //        else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowHeaderWhileBrowsing" ) ) )
1142 //        else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "ShowFooterWhileBrowsing" ) ) )
1143         else if (pValue->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "InBrowseMode" ) ) )
1144         {
1145             bBrowseMode = *(sal_Bool *)(pValue->Value.getValue());
1146 			bChangeBrowseMode = sal_True;
1147         }
1148 		pValue++;
1149     }
1150 	if( pDoc->GetDocShell() )
1151 		pDoc->GetDocShell()->SetVisArea ( aRect );
1152 
1153     if (bChangeBrowseMode)
1154     	pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bBrowseMode );
1155 
1156 	if (bChangeShowRedline)
1157 		GetTextImport()->SetShowChanges( bShowRedlineChanges );
1158 }
1159 
SetConfigurationSettings(const Sequence<PropertyValue> & aConfigProps)1160 void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aConfigProps)
1161 {
1162     // this method will modify the document directly -> lock SolarMutex
1163     vos::OGuard aGuard(Application::GetSolarMutex());
1164 
1165     Reference< lang::XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
1166     if( !xFac.is() )
1167         return;
1168 
1169     Reference< XPropertySet > xProps( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), UNO_QUERY );
1170     if( !xProps.is() )
1171         return;
1172 
1173     Reference< XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
1174     if( !xInfo.is() )
1175         return;
1176 
1177     hash_set< String, StringHashRef, StringEqRef > aSet;
1178     aSet.insert(String("ForbiddenCharacters", RTL_TEXTENCODING_ASCII_US));
1179     aSet.insert(String("IsKernAsianPunctuation", RTL_TEXTENCODING_ASCII_US));
1180     aSet.insert(String("CharacterCompressionType", RTL_TEXTENCODING_ASCII_US));
1181     aSet.insert(String("LinkUpdateMode", RTL_TEXTENCODING_ASCII_US));
1182     aSet.insert(String("FieldAutoUpdate", RTL_TEXTENCODING_ASCII_US));
1183     aSet.insert(String("ChartAutoUpdate", RTL_TEXTENCODING_ASCII_US));
1184     aSet.insert(String("AddParaTableSpacing", RTL_TEXTENCODING_ASCII_US));
1185     aSet.insert(String("AddParaTableSpacingAtStart", RTL_TEXTENCODING_ASCII_US));
1186     aSet.insert(String("PrintAnnotationMode", RTL_TEXTENCODING_ASCII_US));
1187     aSet.insert(String("PrintBlackFonts", RTL_TEXTENCODING_ASCII_US));
1188     aSet.insert(String("PrintControls", RTL_TEXTENCODING_ASCII_US));
1189     aSet.insert(String("PrintDrawings", RTL_TEXTENCODING_ASCII_US));
1190     aSet.insert(String("PrintGraphics", RTL_TEXTENCODING_ASCII_US));
1191     aSet.insert(String("PrintLeftPages", RTL_TEXTENCODING_ASCII_US));
1192     aSet.insert(String("PrintPageBackground", RTL_TEXTENCODING_ASCII_US));
1193     aSet.insert(String("PrintProspect", RTL_TEXTENCODING_ASCII_US));
1194     aSet.insert(String("PrintReversed", RTL_TEXTENCODING_ASCII_US));
1195     aSet.insert(String("PrintRightPages", RTL_TEXTENCODING_ASCII_US));
1196     aSet.insert(String("PrintFaxName", RTL_TEXTENCODING_ASCII_US));
1197     aSet.insert(String("PrintPaperFromSetup", RTL_TEXTENCODING_ASCII_US));
1198     aSet.insert(String("PrintTables", RTL_TEXTENCODING_ASCII_US));
1199     aSet.insert(String("PrintSingleJobs", RTL_TEXTENCODING_ASCII_US));
1200     aSet.insert(String("UpdateFromTemplate", RTL_TEXTENCODING_ASCII_US));
1201     aSet.insert(String("PrinterIndependentLayout", RTL_TEXTENCODING_ASCII_US));
1202     aSet.insert(String("PrintEmptyPages", RTL_TEXTENCODING_ASCII_US));
1203 
1204     sal_Int32 nCount = aConfigProps.getLength();
1205     const PropertyValue* pValues = aConfigProps.getConstArray();
1206 
1207     SvtSaveOptions aSaveOpt;
1208     sal_Bool bIsUserSetting = aSaveOpt.IsLoadUserSettings();
1209     sal_Bool bSet = bIsUserSetting;
1210 
1211     // for some properties we don't want to use the application
1212     // default if they're missing. So we watch for them in the loop
1213     // below, and set them if not found
1214     bool bPrinterIndependentLayout = false;
1215     bool bUseOldNumbering = false; // #111955#
1216     bool bOutlineLevelYieldsOutlineRule = false;
1217     bool bAddExternalLeading = false;
1218     bool bAddParaSpacingToTableCells = false;
1219     bool bUseFormerLineSpacing = false;
1220     bool bUseFormerObjectPositioning = false;
1221     bool bUseFormerTextWrapping = false;
1222     bool bConsiderWrapOnObjPos = false;
1223     bool bIgnoreFirstLineIndentInNumbering = false;
1224     bool bDoNotJustifyLinesWithManualBreak = false;
1225     bool bDoNotResetParaAttrsForNumFont    = false;
1226     bool bLoadReadonly = false;
1227     bool bDoNotCaptureDrawObjsOnPage( false );
1228     bool bClipAsCharacterAnchoredWriterFlyFrames( false );
1229     bool bUnixForceZeroExtLeading = false;
1230     bool bUseOldPrinterMetrics = false;
1231 
1232     static const OUString sRedlineProtectionKey( RTL_CONSTASCII_USTRINGPARAM( "RedlineProtectionKey" ) );
1233 
1234     // Set current database properties in certain order
1235     // Thus, keep these properties during loop and set them afterwards in valid order
1236     static const OUString sCurrentDatabaseDataSource( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseDataSource" ) );
1237     uno::Any aCurrentDatabaseDataSource;
1238     static const OUString sCurrentDatabaseCommand( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseCommand" ) );
1239     uno::Any aCurrentDatabaseCommand;
1240     static const OUString sCurrentDatabaseCommandType( RTL_CONSTASCII_USTRINGPARAM( "CurrentDatabaseCommandType" ) );
1241     uno::Any aCurrentDatabaseCommandType;
1242 
1243     while( nCount-- )
1244     {
1245         if( !bIsUserSetting )
1246         {
1247             // test over the hash value if the entry is in the table.
1248             String aStr(pValues->Name);
1249 
1250             bSet = aSet.find(aStr) == aSet.end();
1251         }
1252 
1253         if( bSet )
1254         {
1255             try
1256             {
1257                 if( xInfo->hasPropertyByName( pValues->Name ) )
1258                 {
1259                     if( pValues->Name.equals( sRedlineProtectionKey ) )
1260                     {
1261                         Sequence<sal_Int8> aKey;
1262                         pValues->Value >>= aKey;
1263                         GetTextImport()->SetChangesProtectionKey( aKey );
1264                     }
1265                     else if ( !aCurrentDatabaseDataSource.hasValue()
1266                               && pValues->Name.equals( sCurrentDatabaseDataSource ) )
1267                     {
1268                         aCurrentDatabaseDataSource = pValues->Value;
1269                     }
1270                     else if ( !aCurrentDatabaseCommand.hasValue()
1271                               && pValues->Name.equals( sCurrentDatabaseCommand ) )
1272                     {
1273                         aCurrentDatabaseCommand = pValues->Value;
1274                     }
1275                     else if ( !aCurrentDatabaseCommandType.hasValue()
1276                               && pValues->Name.equals( sCurrentDatabaseCommandType ) )
1277                     {
1278                         aCurrentDatabaseCommandType = pValues->Value;
1279                     }
1280                     else
1281                     {
1282                         xProps->setPropertyValue( pValues->Name, pValues->Value );
1283                     }
1284                 }
1285 
1286                 // did we find any of the non-default cases?
1287                 if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PrinterIndependentLayout")) )
1288                     bPrinterIndependentLayout = true;
1289                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("AddExternalLeading")) )
1290                     bAddExternalLeading = true;
1291                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("AddParaSpacingToTableCells")) )
1292                     bAddParaSpacingToTableCells = true;
1293                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseFormerLineSpacing")) )
1294                     bUseFormerLineSpacing = true;
1295                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseFormerObjectPositioning")) )
1296                     bUseFormerObjectPositioning = true;
1297                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseFormerTextWrapping")) )
1298                     bUseFormerTextWrapping = true;
1299                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseOldNumbering")) )
1300                     bUseOldNumbering = true;
1301                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("OutlineLevelYieldsNumbering")) )
1302                     bOutlineLevelYieldsOutlineRule = true;
1303                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ConsiderTextWrapOnObjPos")) )
1304                     bConsiderWrapOnObjPos = true;
1305                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("IgnoreFirstLineIndentInNumbering")) )
1306                     bIgnoreFirstLineIndentInNumbering = true;
1307                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("DoNotJustifyLinesWithManualBreak")) )
1308                     bDoNotJustifyLinesWithManualBreak = true;
1309                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("DoNotResetParaAttrsForNumFont")) )
1310                     bDoNotResetParaAttrsForNumFont = true;
1311                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("LoadReadonly")) )
1312                     bLoadReadonly = true;
1313                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("DoNotCaptureDrawObjsOnPage")) )
1314                     bDoNotCaptureDrawObjsOnPage = true;
1315                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ClipAsCharacterAnchoredWriterFlyFrames")) )
1316                     bClipAsCharacterAnchoredWriterFlyFrames = true;
1317                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UnxForceZeroExtLeading")) )
1318                     bUnixForceZeroExtLeading = true;
1319                 else if( pValues->Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("UseOldPrinterMetrics")) )
1320                     bUseOldPrinterMetrics = true;
1321             }
1322             catch( Exception& )
1323             {
1324                 DBG_ERROR( "SwXMLImport::SetConfigurationSettings: Exception!" );
1325             }
1326         }
1327         pValues++;
1328     }
1329 
1330     // apply current database properties
1331     {
1332         if ( aCurrentDatabaseDataSource.hasValue() )
1333         {
1334             xProps->setPropertyValue( sCurrentDatabaseDataSource, aCurrentDatabaseDataSource );
1335         }
1336         if ( aCurrentDatabaseCommand.hasValue() )
1337         {
1338             xProps->setPropertyValue( sCurrentDatabaseCommand, aCurrentDatabaseCommand );
1339         }
1340         if ( aCurrentDatabaseCommandType.hasValue() )
1341         {
1342             xProps->setPropertyValue( sCurrentDatabaseCommandType, aCurrentDatabaseCommandType );
1343         }
1344     }
1345 
1346     // finally, treat the non-default cases
1347 
1348     // introduce boolean, that indicates a document, written by version prior SO8.
1349     const bool bDocumentPriorSO8 = !bConsiderWrapOnObjPos;
1350 
1351     if( ! bPrinterIndependentLayout )
1352     {
1353         Any aAny;
1354         sal_Int16 nTmp = document::PrinterIndependentLayout::DISABLED;
1355         aAny <<= nTmp;
1356         xProps->setPropertyValue(
1357             OUString( RTL_CONSTASCII_USTRINGPARAM("PrinterIndependentLayout") ),
1358             aAny );
1359     }
1360 
1361     if( ! bAddExternalLeading )
1362     {
1363         xProps->setPropertyValue(
1364             OUString( RTL_CONSTASCII_USTRINGPARAM("AddExternalLeading")), makeAny( false ) );
1365     }
1366 
1367     if( ! bUseFormerLineSpacing )
1368     {
1369         xProps->setPropertyValue(
1370             OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerLineSpacing")), makeAny( true ) );
1371     }
1372 
1373     if( !bUseFormerObjectPositioning )
1374     {
1375         xProps->setPropertyValue(
1376             OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerObjectPositioning")), makeAny( true ) );
1377     }
1378 
1379     if( !bUseOldNumbering )
1380     {
1381         Any aAny;
1382         sal_Bool bOldNum = true;
1383         aAny.setValue(&bOldNum, ::getBooleanCppuType());
1384         xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("UseOldNumbering")), aAny );
1385     }
1386 
1387     if( !bOutlineLevelYieldsOutlineRule )
1388     {
1389         Any aAny;
1390         sal_Bool bTmp = true;
1391         aAny.setValue(&bTmp, ::getBooleanCppuType());
1392         xProps->setPropertyValue
1393             (OUString( RTL_CONSTASCII_USTRINGPARAM
1394                        ("OutlineLevelYieldsNumbering")),
1395                        aAny );
1396     }
1397 
1398     if( !bAddParaSpacingToTableCells )
1399     {
1400         xProps->setPropertyValue(
1401             OUString( RTL_CONSTASCII_USTRINGPARAM("AddParaSpacingToTableCells")), makeAny( false ) );
1402     }
1403 
1404     if( !bUseFormerTextWrapping )
1405     {
1406         xProps->setPropertyValue(
1407             OUString( RTL_CONSTASCII_USTRINGPARAM("UseFormerTextWrapping")), makeAny( true ) );
1408     }
1409 
1410     if( !bConsiderWrapOnObjPos )
1411     {
1412         xProps->setPropertyValue(
1413             OUString( RTL_CONSTASCII_USTRINGPARAM("ConsiderTextWrapOnObjPos")), makeAny( false ) );
1414     }
1415 
1416     // FME 2005-05-27 #i47448#
1417     // For SO7pp4, part of the 'new numbering' stuff has been backported from
1418     // SO8. Unfortunately, only part of it and by using the same compatibility option
1419     // like in SO8. Therefore documents generated with SO7pp4, containing
1420     // numbered paragraphs with first line indent differ between SO7pp4 and
1421     // SO8. In order to fix this for SO8pp1, I introduce a new compatibility
1422     // flag 'bIgnoreFirstLineIndentInNumbering'. This flag has to be set for all
1423     // documents < SO8, but not for SO8. So if the property is not present, the
1424     // flag will be set to 'true'. SO8 documents surely have the
1425     // 'ConsiderWrapOnObjPos' property set (no matter if 'true' or 'false'),
1426     // therefore the correct condition to set this flag is this:
1427     if( !bIgnoreFirstLineIndentInNumbering && bDocumentPriorSO8 )
1428     {
1429         xProps->setPropertyValue(
1430             OUString( RTL_CONSTASCII_USTRINGPARAM("IgnoreFirstLineIndentInNumbering")), makeAny( true ) );
1431     }
1432 
1433     // This flag has to be set for all documents < SO8
1434     if ( !bDoNotJustifyLinesWithManualBreak && bDocumentPriorSO8 )
1435     {
1436         xProps->setPropertyValue(
1437             OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotJustifyLinesWithManualBreak")), makeAny( true ) );
1438     }
1439     // <--
1440 
1441     // This flag has to be set for all documents < SO8
1442     if ( !bDoNotResetParaAttrsForNumFont && bDocumentPriorSO8 )
1443     {
1444         xProps->setPropertyValue(
1445             OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotResetParaAttrsForNumFont")), makeAny( true ) );
1446     }
1447 
1448     if ( !bLoadReadonly )
1449     {
1450         xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("LoadReadonly") ), makeAny( false ) );
1451     }
1452 
1453     // This flag has to be set for all documents < SO8
1454     if ( !bDoNotCaptureDrawObjsOnPage && bDocumentPriorSO8 )
1455     {
1456         xProps->setPropertyValue(
1457             OUString( RTL_CONSTASCII_USTRINGPARAM("DoNotCaptureDrawObjsOnPage") ), makeAny( true ) );
1458     }
1459 
1460     // This flag has to be set for all documents < SO8
1461     if ( !bClipAsCharacterAnchoredWriterFlyFrames && bDocumentPriorSO8 )
1462     {
1463         xProps->setPropertyValue(
1464             OUString( RTL_CONSTASCII_USTRINGPARAM("ClipAsCharacterAnchoredWriterFlyFrames") ), makeAny( true ) );
1465     }
1466 
1467     if ( !bUnixForceZeroExtLeading )
1468     {
1469         xProps->setPropertyValue(
1470             OUString( RTL_CONSTASCII_USTRINGPARAM("UnxForceZeroExtLeading") ), makeAny( true ) );
1471     }
1472 
1473     if ( !bUseOldPrinterMetrics )
1474     {
1475         xProps->setPropertyValue(
1476             OUString( RTL_CONSTASCII_USTRINGPARAM("UseOldPrinterMetrics") ), makeAny( true ) );
1477     }
1478     // <--
1479 
1480     Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1481     Reference < XText > xText = xTextDoc->getText();
1482     Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1483     ASSERT( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
1484     if( xTextTunnel.is() )
1485     {
1486         SwXText *pText = reinterpret_cast< SwXText *>(
1487             sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1488         ASSERT( pText, "SwXText missing" );
1489         if( pText )
1490         {
1491             SwDoc *pDoc = pText->GetDoc();
1492             if( pDoc )
1493             {
1494                 SfxPrinter *pPrinter = pDoc->getPrinter( false );
1495                 if( pPrinter )
1496                 {
1497                     // If the printer is known, then the OLE objects will
1498                     // already have correct sizes, and we don't have to call
1499                     // PrtOLENotify again. Otherwise we have to call it.
1500                     // The flag might be set from setting the printer, so it
1501                     // it is required to clear it.
1502                     pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
1503 
1504                     // FME 2007-05-14 #147385# old printer metrics compatibility
1505                     if (  pDoc->get(IDocumentSettingAccess::USE_OLD_PRINTER_METRICS ) &&
1506                          !pDoc->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
1507                     {
1508                         pPrinter->Compat_OldPrinterMetrics( true );
1509                         pDoc->GetDocShell()->UpdateFontList();
1510                     }
1511                 }
1512             }
1513         }
1514     }
1515 }
1516 
1517 
SetDocumentSpecificSettings(const::rtl::OUString & _rSettingsGroupName,const Sequence<PropertyValue> & _rSettings)1518 void SwXMLImport::SetDocumentSpecificSettings(
1519     const ::rtl::OUString& _rSettingsGroupName,
1520     const Sequence< PropertyValue>& _rSettings )
1521 {
1522     // the only doc-specific settings group we know so far are the XForms settings
1523     if ( !IsXMLToken( _rSettingsGroupName, XML_XFORM_MODEL_SETTINGS ) )
1524         return;
1525 
1526     // preserve the settings for a later iteration - we are currently reading the settings.xml,
1527     // the content.xml will be read later, by another instance of SwXMLImport
1528     OSL_ENSURE( xLateInitSettings.is(), "SwXMLImport::SetDocumentSpecificSettings: no storage for those settings!" );
1529     if ( !xLateInitSettings.is() )
1530         return;
1531 
1532     try
1533     {
1534         if ( xLateInitSettings->hasByName( _rSettingsGroupName ) )
1535         {
1536             xLateInitSettings->replaceByName( _rSettingsGroupName, makeAny( _rSettings ) );
1537             OSL_ENSURE( false, "SwXMLImport::SetDocumentSpecificSettings: already have settings for this model!" );
1538         }
1539         else
1540             xLateInitSettings->insertByName( _rSettingsGroupName, makeAny( _rSettings ) );
1541     }
1542     catch( const Exception& )
1543     {
1544     	DBG_UNHANDLED_EXCEPTION();
1545     }
1546 }
1547 
initialize(const Sequence<Any> & aArguments)1548 void SwXMLImport::initialize(
1549 	const Sequence<Any>& aArguments )
1550 	throw( uno::Exception, uno::RuntimeException)
1551 {
1552 	// delegate to super class
1553 	SvXMLImport::initialize(aArguments);
1554 
1555 	// we are only looking for a PropertyValue "PreserveRedlineMode"
1556 	sal_Int32 nLength = aArguments.getLength();
1557 	for(sal_Int32 i = 0; i < nLength; i++)
1558 	{
1559         beans::PropertyValue aValue;
1560         if ( aArguments[i] >>= aValue )
1561 		{
1562 			if (aValue.Name.equalsAsciiL(
1563 				RTL_CONSTASCII_STRINGPARAM("PreserveRedlineMode")))
1564 			{
1565                 OSL_VERIFY( aValue.Value >>= bPreserveRedlineMode );
1566 			}
1567             continue;
1568 		}
1569 
1570         beans::NamedValue aNamedValue;
1571         if ( aArguments[i] >>= aNamedValue )
1572         {
1573 			if (aNamedValue.Name.equalsAsciiL(
1574 				RTL_CONSTASCII_STRINGPARAM("LateInitSettings")))
1575             {
1576                 OSL_VERIFY( aNamedValue.Value >>= xLateInitSettings );
1577             }
1578         }
1579 	}
1580 }
1581 
1582 
1583 //
1584 // UNO component registration helper functions
1585 //
1586 
SwXMLImport_getImplementationName()1587 OUString SAL_CALL SwXMLImport_getImplementationName() throw()
1588 {
1589 	return OUString( RTL_CONSTASCII_USTRINGPARAM(
1590 		"com.sun.star.comp.Writer.XMLOasisImporter" ) );
1591 }
1592 
SwXMLImport_getSupportedServiceNames()1593 uno::Sequence< OUString > SAL_CALL SwXMLImport_getSupportedServiceNames()
1594 	throw()
1595 {
1596 	const OUString aServiceName( SwXMLImport_getImplementationName() );
1597 	const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1598 	return aSeq;
1599 }
1600 
SwXMLImport_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1601 uno::Reference< uno::XInterface > SAL_CALL SwXMLImport_createInstance(
1602 		const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1603 	throw( uno::Exception )
1604 {
1605 	// #110680#
1606 	// return (cppu::OWeakObject*)new SwXMLImport(IMPORT_ALL);
1607 	return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_ALL );
1608 }
1609 
SwXMLImportStyles_getImplementationName()1610 OUString SAL_CALL SwXMLImportStyles_getImplementationName() throw()
1611 {
1612 	return OUString( RTL_CONSTASCII_USTRINGPARAM(
1613 		"com.sun.star.comp.Writer.XMLOasisStylesImporter" ) );
1614 }
1615 
SwXMLImportStyles_getSupportedServiceNames()1616 uno::Sequence< OUString > SAL_CALL SwXMLImportStyles_getSupportedServiceNames()
1617 	throw()
1618 {
1619 	const OUString aServiceName( SwXMLImportStyles_getImplementationName() );
1620 	const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1621 	return aSeq;
1622 }
1623 
SwXMLImportStyles_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1624 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportStyles_createInstance(
1625 		const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1626 	throw( uno::Exception )
1627 {
1628 	// #110680#
1629 	//return (cppu::OWeakObject*)new SwXMLImport(
1630 	//	IMPORT_STYLES | IMPORT_MASTERSTYLES | IMPORT_AUTOSTYLES |
1631 	//	IMPORT_FONTDECLS );
1632 	return (cppu::OWeakObject*)new SwXMLImport(
1633 		rSMgr,
1634 		IMPORT_STYLES | IMPORT_MASTERSTYLES | IMPORT_AUTOSTYLES |
1635 		IMPORT_FONTDECLS );
1636 }
1637 
SwXMLImportContent_getImplementationName()1638 OUString SAL_CALL SwXMLImportContent_getImplementationName() throw()
1639 {
1640 	return OUString( RTL_CONSTASCII_USTRINGPARAM(
1641 		"com.sun.star.comp.Writer.XMLOasisContentImporter" ) );
1642 }
1643 
SwXMLImportContent_getSupportedServiceNames()1644 uno::Sequence< OUString > SAL_CALL SwXMLImportContent_getSupportedServiceNames()
1645 	throw()
1646 {
1647 	const OUString aServiceName( SwXMLImportContent_getImplementationName() );
1648 	const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1649 	return aSeq;
1650 }
1651 
SwXMLImportContent_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1652 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportContent_createInstance(
1653 		const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1654 	throw( uno::Exception )
1655 {
1656 	// #110680#
1657 	//return (cppu::OWeakObject*)new SwXMLImport(
1658 	//	IMPORT_AUTOSTYLES |	IMPORT_CONTENT | IMPORT_SCRIPTS |
1659 	//	IMPORT_FONTDECLS );
1660 	return (cppu::OWeakObject*)new SwXMLImport(
1661 		rSMgr,
1662 		IMPORT_AUTOSTYLES |	IMPORT_CONTENT | IMPORT_SCRIPTS |
1663 		IMPORT_FONTDECLS );
1664 }
1665 
SwXMLImportMeta_getImplementationName()1666 OUString SAL_CALL SwXMLImportMeta_getImplementationName() throw()
1667 {
1668 	return OUString( RTL_CONSTASCII_USTRINGPARAM(
1669 		"com.sun.star.comp.Writer.XMLOasisMetaImporter" ) );
1670 }
1671 
SwXMLImportMeta_getSupportedServiceNames()1672 uno::Sequence< OUString > SAL_CALL SwXMLImportMeta_getSupportedServiceNames()
1673 	throw()
1674 {
1675 	const OUString aServiceName( SwXMLImportMeta_getImplementationName() );
1676 	const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1677 	return aSeq;
1678 }
1679 
SwXMLImportMeta_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1680 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportMeta_createInstance(
1681 		const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1682 	throw( uno::Exception )
1683 {
1684 	// #110680#
1685 	// return (cppu::OWeakObject*)new SwXMLImport( IMPORT_META );
1686 	return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_META );
1687 }
1688 
SwXMLImportSettings_getImplementationName()1689 OUString SAL_CALL SwXMLImportSettings_getImplementationName() throw()
1690 {
1691 	return OUString( RTL_CONSTASCII_USTRINGPARAM(
1692 		"com.sun.star.comp.Writer.XMLOasisSettingsImporter" ) );
1693 }
1694 
SwXMLImportSettings_getSupportedServiceNames()1695 uno::Sequence< OUString > SAL_CALL SwXMLImportSettings_getSupportedServiceNames()
1696 	throw()
1697 {
1698 	const OUString aServiceName( SwXMLImportSettings_getImplementationName() );
1699 	const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1700 	return aSeq;
1701 }
1702 
SwXMLImportSettings_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)1703 uno::Reference< uno::XInterface > SAL_CALL SwXMLImportSettings_createInstance(
1704 		const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1705 	throw( uno::Exception )
1706 {
1707 	// #110680#
1708 	// return (cppu::OWeakObject*)new SwXMLImport( IMPORT_SETTINGS );
1709 	return (cppu::OWeakObject*)new SwXMLImport( rSMgr, IMPORT_SETTINGS );
1710 }
1711 
1712 
1713 // XServiceInfo
1714 // override empty method from parent class
getImplementationName()1715 OUString SAL_CALL SwXMLImport::getImplementationName()
1716     throw(RuntimeException)
1717 {
1718     switch( getImportFlags() )
1719     {
1720         case IMPORT_ALL:
1721             return SwXMLImport_getImplementationName();
1722         case (IMPORT_STYLES|IMPORT_MASTERSTYLES|IMPORT_AUTOSTYLES|IMPORT_FONTDECLS):
1723             return SwXMLImportStyles_getImplementationName();
1724         case (IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS):
1725             return SwXMLImportContent_getImplementationName();
1726         case IMPORT_META:
1727             return SwXMLImportMeta_getImplementationName();
1728         case IMPORT_SETTINGS:
1729             return SwXMLImportSettings_getImplementationName();
1730         default:
1731             // generic name for 'unknown' cases
1732             return OUString( RTL_CONSTASCII_USTRINGPARAM(
1733                 "com.sun.star.comp.Writer.SwXMLImport" ) );
1734     }
1735 }
1736 
GetDocFromXMLImport(SvXMLImport & rImport)1737 SwDoc* SwImport::GetDocFromXMLImport( SvXMLImport& rImport )
1738 {
1739 	uno::Reference<lang::XUnoTunnel> xModelTunnel( rImport.GetModel(), uno::UNO_QUERY );
1740     SwXTextDocument *pTxtDoc = reinterpret_cast< SwXTextDocument *>(
1741             sal::static_int_cast< sal_IntPtr >(  xModelTunnel->getSomething(SwXTextDocument::getUnoTunnelId() )));
1742 	ASSERT( pTxtDoc, "Where is my model?" )
1743 	ASSERT( pTxtDoc->GetDocShell(), "Where is my shell?" )
1744 	SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
1745 	ASSERT( pDoc, "Where is my document?" )
1746 	return pDoc;
1747 }
1748 
1749 
initXForms()1750 void SwXMLImport::initXForms()
1751 {
1752     // obtain SwDoc
1753 	Reference<XUnoTunnel> xDocTunnel( GetModel(), UNO_QUERY );
1754     if( ! xDocTunnel.is() )
1755         return;
1756     SwXTextDocument* pXTextDocument = reinterpret_cast<SwXTextDocument*>(
1757         xDocTunnel->getSomething( SwXTextDocument::getUnoTunnelId() ) );
1758     if( pXTextDocument == NULL )
1759         return;
1760 
1761 	SwDoc *pDoc = pXTextDocument->GetDocShell()->GetDoc();
1762 
1763     // init XForms (if not already done)
1764     // (no default model, since we'll load the models)
1765     if( ! pDoc->isXForms() )
1766         pDoc->initXForms( false );
1767 
1768     bInititedXForms = sal_True;
1769 }
1770