xref: /aoo42x/main/xmloff/source/core/xmlimp.cxx (revision 63bba73c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <com/sun/star/beans/XPropertySetInfo.hpp>
27 #include <tools/debug.hxx>
28 #include <tools/urlobj.hxx>
29 #include <osl/mutex.hxx>
30 #include <rtl/uuid.h>
31 #include <rtl/memory.h>
32 #include <svl/svarray.hxx>
33 #include "unointerfacetouniqueidentifiermapper.hxx"
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include "xmloff/xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/XMLFontStylesContext.hxx>
39 #include <xmloff/xmlictxt.hxx>
40 #include <xmloff/xmlimp.hxx>
41 #include <xmloff/xmlnumfi.hxx>
42 #include "XMLEventImportHelper.hxx"
43 #include "XMLStarBasicContextFactory.hxx"
44 #include "XMLScriptContextFactory.hxx"
45 #include "StyleMap.hxx"
46 #include <xmloff/ProgressBarHelper.hxx>
47 #include <xmloff/xmltoken.hxx>
48 #include "xmloff/xmlerror.hxx"
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
51 #include <com/sun/star/io/XOutputStream.hpp>
52 #include <com/sun/star/document/XBinaryStreamResolver.hpp>
53 #include <com/sun/star/document/XStorageBasedDocument.hpp>
54 #include <com/sun/star/xml/sax/XLocator.hpp>
55 #include <com/sun/star/packages/zip/ZipIOException.hpp>
56 #include <comphelper/namecontainer.hxx>
57 #include <rtl/logfile.hxx>
58 #include <tools/string.hxx> // used in StartElement for logging
59 #include <cppuhelper/implbase1.hxx>
60 #include <comphelper/extract.hxx>
61 #include <comphelper/processfactory.hxx>
62 #include <comphelper/documentconstants.hxx>
63 #include <comphelper/storagehelper.hxx>
64 #include <unotools/fontcvt.hxx>
65 
66 #include <com/sun/star/rdf/XMetadatable.hpp>
67 #include <com/sun/star/rdf/XRepositorySupplier.hpp>
68 #include "RDFaImportHelper.hxx"
69 
70 #define LOGFILE_AUTHOR "unknown"
71 
72 using ::com::sun::star::beans::XPropertySetInfo;
73 
74 using ::rtl::OUString;
75 using ::rtl::OUStringBuffer;
76 
77 using namespace ::osl;
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::frame;
80 using namespace ::com::sun::star::uno;
81 using namespace ::com::sun::star::util;
82 using namespace ::com::sun::star::io;
83 using namespace ::com::sun::star::container;
84 using namespace ::com::sun::star::document;
85 using namespace ::xmloff::token;
86 
87 sal_Char __READONLY_DATA sXML_np__office[] = "_office";
88 sal_Char __READONLY_DATA sXML_np__office_ext[] = "_office_ooo";
89 sal_Char __READONLY_DATA sXML_np__ooo[] = "_ooo";
90 sal_Char __READONLY_DATA sXML_np__ooow[] = "_ooow";
91 sal_Char __READONLY_DATA sXML_np__oooc[] = "_oooc";
92 sal_Char __READONLY_DATA sXML_np__of[] = "_of";
93 sal_Char __READONLY_DATA sXML_np__style[] = "_style";
94 sal_Char __READONLY_DATA sXML_np__text[] = "_text";
95 sal_Char __READONLY_DATA sXML_np__table[] = "_table";
96 sal_Char __READONLY_DATA sXML_np__table_ext[] = "_table_ooo";
97 sal_Char __READONLY_DATA sXML_np__draw[] = "_draw";
98 sal_Char __READONLY_DATA sXML_np__draw_ext[] = "_draw_ooo";
99 sal_Char __READONLY_DATA sXML_np__dr3d[] = "_dr3d";
100 sal_Char __READONLY_DATA sXML_np__fo[] = "_fo";
101 sal_Char __READONLY_DATA sXML_np__xlink[] = "_xlink";
102 sal_Char __READONLY_DATA sXML_np__dc[] = "_dc";
103 sal_Char __READONLY_DATA sXML_np__dom[] = "_dom";
104 sal_Char __READONLY_DATA sXML_np__meta[] = "_meta";
105 sal_Char __READONLY_DATA sXML_np__number[] = "_number";
106 sal_Char __READONLY_DATA sXML_np__svg[] = "_svg";
107 sal_Char __READONLY_DATA sXML_np__chart[] = "_chart";
108 sal_Char __READONLY_DATA sXML_np__math[] = "_math";
109 sal_Char __READONLY_DATA sXML_np__form[] = "_form";
110 sal_Char __READONLY_DATA sXML_np__script[] = "_script";
111 sal_Char __READONLY_DATA sXML_np__config[] = "_config";
112 sal_Char __READONLY_DATA sXML_np__db[] = "_db";
113 sal_Char __READONLY_DATA sXML_np__xforms[] = "_xforms";
114 sal_Char __READONLY_DATA sXML_np__xsd[] = "_xsd";
115 sal_Char __READONLY_DATA sXML_np__xsi[] = "_xsi";
116 sal_Char __READONLY_DATA sXML_np__field[] = "_field";
117 sal_Char __READONLY_DATA sXML_np__xhtml[] = "_xhtml";
118 
119 sal_Char __READONLY_DATA sXML_np__fo_old[] = "__fo";
120 sal_Char __READONLY_DATA sXML_np__xlink_old[] = "__xlink";
121 sal_Char __READONLY_DATA sXML_np__office_old[] = "__office";
122 sal_Char __READONLY_DATA sXML_np__style_old[] = "__style";
123 sal_Char __READONLY_DATA sXML_np__text_old[] = "__text";
124 sal_Char __READONLY_DATA sXML_np__table_old[] = "__table";
125 sal_Char __READONLY_DATA sXML_np__meta_old[] = "__meta";
126 
127 
128 
129 class SvXMLImportEventListener : public cppu::WeakImplHelper1<
130 							com::sun::star::lang::XEventListener >
131 {
132 private:
133 	SvXMLImport*	pImport;
134 
135 public:
136 							SvXMLImportEventListener(SvXMLImport* pImport);
137 	virtual					~SvXMLImportEventListener();
138 
139 							// XEventListener
140 	virtual void SAL_CALL disposing(const lang::EventObject& rEventObject) throw(::com::sun::star::uno::RuntimeException);
141 };
142 
143 SvXMLImportEventListener::SvXMLImportEventListener(SvXMLImport* pTempImport)
144 	: pImport(pTempImport)
145 {
146 }
147 
148 SvXMLImportEventListener::~SvXMLImportEventListener()
149 {
150 }
151 
152 // XEventListener
153 void SAL_CALL SvXMLImportEventListener::disposing( const lang::EventObject& )
154 	throw(uno::RuntimeException)
155 {
156 	if (pImport)
157 	{
158 		pImport->DisposingModel();
159 		pImport = NULL;
160 	}
161 }
162 
163 //==============================================================================
164 // --> ORW
165 namespace
166 {
167     class DocumentInfo
168     {
169         private:
170             sal_uInt16 mnGeneratorVersion;
171 
172         public:
173             DocumentInfo( const SvXMLImport& rImport )
174                 : mnGeneratorVersion( SvXMLImport::ProductVersionUnknown )
175             {
176                 sal_Int32 nUPD, nBuild;
177                 if ( rImport.getBuildIds( nUPD, nBuild ) )
178                 {
179                     if ( nUPD >= 640 && nUPD <= 645 )
180                     {
181                         mnGeneratorVersion = SvXMLImport::OOo_1x;
182                     }
183                     else if ( nUPD == 680 )
184                     {
185                         mnGeneratorVersion = SvXMLImport::OOo_2x;
186                     }
187                     else if ( nUPD == 300 && nBuild <= 9379 )
188                     {
189                         mnGeneratorVersion = SvXMLImport::OOo_30x;
190                     }
191                     else if ( nUPD == 310 )
192                     {
193                         mnGeneratorVersion = SvXMLImport::OOo_31x;
194                     }
195                     else if ( nUPD == 320 )
196                     {
197                         mnGeneratorVersion = SvXMLImport::OOo_32x;
198                     }
199                     else if ( nUPD == 330 )
200                     {
201                         mnGeneratorVersion = SvXMLImport::OOo_33x;
202                     }
203                     else if ( nUPD == 340 )
204                     {
205                         mnGeneratorVersion = SvXMLImport::OOo_34x;
206                     }
207                 }
208             }
209 
210             ~DocumentInfo()
211             {}
212 
213             const sal_uInt16 getGeneratorVersion() const
214             {
215                 return mnGeneratorVersion;
216             }
217     };
218 }
219 // <--
220 
221 class SvXMLImport_Impl
222 {
223 public:
224 	FontToSubsFontConverter hBatsFontConv;
225 	FontToSubsFontConverter hMathFontConv;
226 
227 	bool mbOwnGraphicResolver;
228 	bool mbOwnEmbeddedResolver;
229 	INetURLObject aBaseURL;
230     INetURLObject aDocBase;
231 
232     /// name of stream in package, e.g., "content.xml"
233     ::rtl::OUString mStreamName;
234 
235     ::rtl::OUString aODFVersion;
236 
237     // --> OD 2004-08-10 #i28749# - boolean, indicating that position attributes
238     // of shapes are given in horizontal left-to-right layout. This is the case
239     // for the OpenOffice.org file format.
240     sal_Bool mbShapePositionInHoriL2R;
241     // <--
242     // --> OD 2007-12-19 #152540#
243     sal_Bool mbTextDocInOOoFileFormat;
244     // <--
245 
246     const uno::Reference< uno::XComponentContext > mxComponentContext;
247 
248     std::auto_ptr< xmloff::RDFaImportHelper > mpRDFaHelper;
249 
250     // --> ORW
251     std::auto_ptr< DocumentInfo > mpDocumentInfo;
252     // <--
253 
254     SvXMLImport_Impl()
255         : hBatsFontConv( 0 )
256         , hMathFontConv( 0 )
257         , mbOwnGraphicResolver( false )
258         , mbOwnEmbeddedResolver( false )
259         , mStreamName()
260         , mbShapePositionInHoriL2R( sal_False )
261         , mbTextDocInOOoFileFormat( sal_False )
262         , mxComponentContext( ::comphelper::getProcessComponentContext() )
263         , mpRDFaHelper() // lazy
264         // --> ORW
265         , mpDocumentInfo() // lazy
266         // <--
267     {
268         OSL_ENSURE(mxComponentContext.is(), "SvXMLImport: no ComponentContext");
269         if (!mxComponentContext.is()) throw uno::RuntimeException();
270     }
271 
272 	~SvXMLImport_Impl()
273 	{
274 		if( hBatsFontConv )
275 			DestroyFontToSubsFontConverter( hBatsFontConv );
276 		if( hMathFontConv )
277 			DestroyFontToSubsFontConverter( hMathFontConv );
278 	}
279 
280     // --> ORW
281     const sal_uInt16 getGeneratorVersion( const SvXMLImport& rImport )
282     {
283         if ( !mpDocumentInfo.get() )
284         {
285             mpDocumentInfo.reset( new DocumentInfo( rImport ) );
286         }
287 
288         return mpDocumentInfo->getGeneratorVersion();
289     }
290     // <--
291 
292 	::comphelper::UnoInterfaceToUniqueIdentifierMapper	maInterfaceToIdentifierMapper;
293 };
294 
295 typedef SvXMLImportContext *SvXMLImportContextPtr;
296 SV_DECL_PTRARR( SvXMLImportContexts_Impl, SvXMLImportContextPtr, 20, 5 )
297 SV_IMPL_PTRARR( SvXMLImportContexts_Impl, SvXMLImportContextPtr )
298 
299 SvXMLImportContext *SvXMLImport::CreateContext( sal_uInt16 nPrefix,
300 										 const OUString& rLocalName,
301 										 const uno::Reference< xml::sax::XAttributeList >& )
302 {
303 	return new SvXMLImportContext( *this, nPrefix, rLocalName );
304 }
305 
306 void SvXMLImport::_InitCtor()
307 {
308 	if( mnImportFlags != 0 )
309 	{
310 		// implicit "xml" namespace prefix
311 		mpNamespaceMap->Add( GetXMLToken(XML_XML), GetXMLToken(XML_N_XML),
312                             XML_NAMESPACE_XML );
313 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ),
314 							GetXMLToken(XML_N_OFFICE),
315 							XML_NAMESPACE_OFFICE );
316 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office_ext ) ),
317 							GetXMLToken(XML_N_OFFICE_EXT),
318 							XML_NAMESPACE_OFFICE_EXT );
319 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooo ) ), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
320 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__style) ),
321 							GetXMLToken(XML_N_STYLE),
322 							XML_NAMESPACE_STYLE );
323 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__text) ),
324 							GetXMLToken(XML_N_TEXT),
325 							XML_NAMESPACE_TEXT );
326 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__table ) ),
327 							GetXMLToken(XML_N_TABLE),
328 							XML_NAMESPACE_TABLE );
329 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__table_ext ) ),
330 							GetXMLToken(XML_N_TABLE_EXT),
331 							XML_NAMESPACE_TABLE_EXT );
332 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw ) ),
333 							GetXMLToken(XML_N_DRAW),
334 							XML_NAMESPACE_DRAW );
335 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw_ext ) ),
336 							GetXMLToken(XML_N_DRAW_EXT),
337 							XML_NAMESPACE_DRAW_EXT );
338 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM (sXML_np__dr3d ) ),
339 							GetXMLToken(XML_N_DR3D),
340 							XML_NAMESPACE_DR3D );
341 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__fo) ),
342 							GetXMLToken(XML_N_FO_COMPAT),
343 							XML_NAMESPACE_FO );
344 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xlink) ),
345 							GetXMLToken(XML_N_XLINK),
346 							XML_NAMESPACE_XLINK );
347 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__dc) ),
348 							GetXMLToken(XML_N_DC),
349 							XML_NAMESPACE_DC );
350 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__dom ) ),
351 							GetXMLToken(XML_N_DOM),
352 							XML_NAMESPACE_DOM );
353 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__meta) ),
354 							GetXMLToken(XML_N_META),
355 							XML_NAMESPACE_META );
356 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__number) ),
357 							GetXMLToken(XML_N_NUMBER),
358 							XML_NAMESPACE_NUMBER );
359 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__svg) ),
360 							GetXMLToken(XML_N_SVG_COMPAT),
361 							XML_NAMESPACE_SVG );
362 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__chart) ),
363 							GetXMLToken(XML_N_CHART),
364 							XML_NAMESPACE_CHART );
365 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__math) ),
366 							GetXMLToken(XML_N_MATH),
367 							XML_NAMESPACE_MATH );
368         mpNamespaceMap->Add(OUString(RTL_CONSTASCII_USTRINGPARAM( sXML_np__form )),
369                             GetXMLToken(XML_N_FORM),
370 							XML_NAMESPACE_FORM );
371 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__script) ),
372 							GetXMLToken(XML_N_SCRIPT),
373 							XML_NAMESPACE_SCRIPT );
374 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__config) ),
375 							GetXMLToken(XML_N_CONFIG),
376 							XML_NAMESPACE_CONFIG );
377         mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xforms) ),
378                             GetXMLToken(XML_N_XFORMS_1_0),
379                             XML_NAMESPACE_XFORMS );
380         mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xsd) ),
381                             GetXMLToken(XML_N_XSD),
382                             XML_NAMESPACE_XSD );
383         mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xsi) ),
384                             GetXMLToken(XML_N_XSI),
385                             XML_NAMESPACE_XFORMS );
386 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooow ) ), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
387 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__oooc ) ), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
388         mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__field ) ), GetXMLToken(XML_N_FIELD), XML_NAMESPACE_FIELD );
389 		mpNamespaceMap->Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__of ) ),
390                             GetXMLToken(XML_N_OF), XML_NAMESPACE_OF );
391         mpNamespaceMap->Add(
392             OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xhtml ) ),
393             GetXMLToken(XML_N_XHTML), XML_NAMESPACE_XHTML );
394 	}
395 
396 	msPackageProtocol = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
397 
398 	if (mxNumberFormatsSupplier.is())
399 		mpNumImport = new SvXMLNumFmtHelper(mxNumberFormatsSupplier, getServiceFactory());
400 
401 	if (mxModel.is() && !mxEventListener.is())
402 	{
403 		mxEventListener.set(new SvXMLImportEventListener(this));
404 		mxModel->addEventListener(mxEventListener);
405 	}
406 
407     ::comphelper::UnoInterfaceToUniqueIdentifierMapper	maInterfaceToIdentifierMapper;
408 
409 }
410 
411 // #110680#
412 SvXMLImport::SvXMLImport(
413 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
414 	sal_uInt16 nImportFlags ) throw ()
415 :	mpImpl( new SvXMLImport_Impl() ),
416 	mpNamespaceMap( new SvXMLNamespaceMap ),
417 
418 	// #110680#
419 	// pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM ) ),
420 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM, xServiceFactory ) ),
421 
422 	mpContexts( new SvXMLImportContexts_Impl ),
423 	mpNumImport( NULL ),
424 	mpProgressBarHelper( NULL ),
425 	mpEventImportHelper( NULL ),
426 	mpXMLErrors( NULL ),
427 	mpStyleMap(0),
428 	mnImportFlags( nImportFlags ),
429 	mnErrorFlags(0),
430 	// #110680#
431 	mxServiceFactory(xServiceFactory),
432     mbIsFormsSupported( sal_True ),
433 	mbIsTableShapeSupported( false ),
434     mbIsGraphicLoadOnDemandSupported( true )
435 {
436 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
437 	_InitCtor();
438 }
439 
440 // #110680#
441 SvXMLImport::SvXMLImport(
442 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
443 	const Reference< XModel > & rModel ) throw ()
444 :	mxModel( rModel ),
445 	mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
446 	mpImpl( new SvXMLImport_Impl() ),
447 	mpNamespaceMap( new SvXMLNamespaceMap ),
448 	// #110680#
449 	// pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM ) ),
450 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM, xServiceFactory ) ),
451 	mpContexts( new SvXMLImportContexts_Impl ),
452 	mpNumImport( NULL ),
453 	mpProgressBarHelper( NULL ),
454 	mpEventImportHelper( NULL ),
455 	mpXMLErrors( NULL ),
456 	mpStyleMap(0),
457 	mnImportFlags( IMPORT_ALL ),
458 	mnErrorFlags(0),
459 	// #110680#
460 	mxServiceFactory(xServiceFactory),
461 	mbIsFormsSupported( sal_True ),
462 	mbIsTableShapeSupported( false ),
463     mbIsGraphicLoadOnDemandSupported( true )
464 {
465 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
466 	_InitCtor();
467 }
468 
469 // #110680#
470 SvXMLImport::SvXMLImport(
471 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
472 	const Reference< XModel > & rModel,
473 	const ::com::sun::star::uno::Reference< ::com::sun::star::document::XGraphicObjectResolver > & rGraphicObjects ) throw ()
474 :	mxModel( rModel ),
475 	mxNumberFormatsSupplier (rModel, uno::UNO_QUERY),
476 	mxGraphicResolver( rGraphicObjects ),
477 	mpImpl( new SvXMLImport_Impl() ),
478 	mpNamespaceMap( new SvXMLNamespaceMap ),
479 	// #110680#
480 	// pUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM ) ),
481 	mpUnitConv( new SvXMLUnitConverter( MAP_100TH_MM, MAP_100TH_MM, xServiceFactory ) ),
482 	mpContexts( new SvXMLImportContexts_Impl ),
483 	mpNumImport( NULL ),
484 	mpProgressBarHelper( NULL ),
485 	mpEventImportHelper( NULL ),
486 	mpXMLErrors( NULL ),
487 	mpStyleMap(0),
488 	mnImportFlags( IMPORT_ALL ),
489 	mnErrorFlags(0),
490 	// #110680#
491 	mxServiceFactory(xServiceFactory),
492     mbIsFormsSupported( sal_True ),
493     mbIsGraphicLoadOnDemandSupported( true )
494 {
495 	DBG_ASSERT( mxServiceFactory.is(), "got no service manager" );
496 	_InitCtor();
497 }
498 
499 SvXMLImport::~SvXMLImport() throw ()
500 {
501     delete mpXMLErrors;
502 	delete mpNamespaceMap;
503 	delete mpUnitConv;
504 	delete mpEventImportHelper;
505 	if( mpContexts )
506 	{
507 		while( mpContexts->Count() )
508 		{
509 			sal_uInt16 n = mpContexts->Count() - 1;
510 			SvXMLImportContext *pContext = (*mpContexts)[n];
511 			mpContexts->Remove( n, 1 );
512 			if( pContext )
513 				pContext->ReleaseRef();
514 		}
515 		delete mpContexts;
516 	}
517 
518 	//	delete pImageMapImportHelper;
519 
520 	//	#i9518# the import component might not be deleted until after the document has been closed,
521 	//	so the stuff that accesses the document has been moved to endDocument.
522 
523 	//	pNumImport is allocated in the ctor, so it must also be deleted here in case the component
524 	//	is created and deleted without actually importing.
525 	delete mpNumImport;
526 	delete mpProgressBarHelper;
527 
528 	xmloff::token::ResetTokens();
529 
530 	if( mpImpl )
531 		delete mpImpl;
532 
533 	if (mxEventListener.is() && mxModel.is())
534 		mxModel->removeEventListener(mxEventListener);
535 }
536 
537 // XUnoTunnel & co
538 const uno::Sequence< sal_Int8 > & SvXMLImport::getUnoTunnelId() throw()
539 {
540 	static uno::Sequence< sal_Int8 > * pSeq = 0;
541 	if( !pSeq )
542 	{
543 		Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
544 		if( !pSeq )
545 		{
546 			static uno::Sequence< sal_Int8 > aSeq( 16 );
547 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
548 			pSeq = &aSeq;
549 		}
550 	}
551 	return *pSeq;
552 }
553 
554 SvXMLImport* SvXMLImport::getImplementation( uno::Reference< uno::XInterface > xInt ) throw()
555 {
556 	uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
557 	if( xUT.is() )
558 	{
559 		return
560 			reinterpret_cast<SvXMLImport*>(
561 				sal::static_int_cast<sal_IntPtr>(
562 					xUT->getSomething( SvXMLImport::getUnoTunnelId())));
563 	}
564 	else
565 		return NULL;
566 }
567 
568 // XUnoTunnel
569 sal_Int64 SAL_CALL SvXMLImport::getSomething( const uno::Sequence< sal_Int8 >& rId )
570 	throw( uno::RuntimeException )
571 {
572 	if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
573 														 rId.getConstArray(), 16 ) )
574 	{
575 		return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
576 	}
577 	return 0;
578 }
579 
580 void SAL_CALL SvXMLImport::startDocument( void )
581 	throw( xml::sax::SAXException, uno::RuntimeException )
582 {
583     RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "{ SvXMLImport::startDocument" );
584 
585 	if( !mxGraphicResolver.is() || !mxEmbeddedResolver.is() )
586 	{
587 		Reference< lang::XMultiServiceFactory > xFactory( mxModel,	UNO_QUERY );
588 		if( xFactory.is() )
589 		{
590 			try
591 			{
592 				if( !mxGraphicResolver.is() )
593 				{
594 					mxGraphicResolver = Reference< XGraphicObjectResolver >::query(
595 						xFactory->createInstance(
596 							OUString(RTL_CONSTASCII_USTRINGPARAM(
597 								// #99870# Import... instead of Export...
598 								"com.sun.star.document.ImportGraphicObjectResolver"))));
599 					mpImpl->mbOwnGraphicResolver = mxGraphicResolver.is();
600 				}
601 
602 				if( !mxEmbeddedResolver.is() )
603 				{
604 					mxEmbeddedResolver = Reference< XEmbeddedObjectResolver >::query(
605 						xFactory->createInstance(
606 							OUString(RTL_CONSTASCII_USTRINGPARAM(
607 								// #99870# Import... instead of Export...
608 								"com.sun.star.document.ImportEmbeddedObjectResolver"))));
609 					mpImpl->mbOwnEmbeddedResolver = mxEmbeddedResolver.is();
610 				}
611 			}
612 			catch( com::sun::star::uno::Exception& )
613 			{
614 			}
615 		}
616 	}
617 }
618 
619 void SAL_CALL SvXMLImport::endDocument( void )
620 	throw( xml::sax::SAXException, uno::RuntimeException)
621 {
622     RTL_LOGFILE_TRACE_AUTHOR( "xmloff", LOGFILE_AUTHOR, "} SvXMLImport::startDocument" );
623 
624 	//	#i9518# All the stuff that accesses the document has to be done here, not in the dtor,
625 	//	because the SvXMLImport dtor might not be called until after the document has been closed.
626 
627     if (mpImpl->mpRDFaHelper.get())
628     {
629         const uno::Reference<rdf::XRepositorySupplier> xRS(mxModel,
630             uno::UNO_QUERY);
631         if (xRS.is())
632         {
633             mpImpl->mpRDFaHelper->InsertRDFa( xRS );
634         }
635     }
636 
637 	if (mpNumImport)
638 	{
639 		delete mpNumImport;
640 		mpNumImport = NULL;
641 	}
642 	if (mxImportInfo.is())
643 	{
644 		uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
645 		if (xPropertySetInfo.is())
646 		{
647 			if (mpProgressBarHelper)
648 			{
649 				OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
650 				OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
651                 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
652 				if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
653 					xPropertySetInfo->hasPropertyByName(sProgressCurrent))
654 				{
655 					sal_Int32 nProgressMax(mpProgressBarHelper->GetReference());
656 					sal_Int32 nProgressCurrent(mpProgressBarHelper->GetValue());
657 					uno::Any aAny;
658 					aAny <<= nProgressMax;
659 					mxImportInfo->setPropertyValue(sProgressMax, aAny);
660 					aAny <<= nProgressCurrent;
661 					mxImportInfo->setPropertyValue(sProgressCurrent, aAny);
662 				}
663                 if (xPropertySetInfo->hasPropertyByName(sRepeat))
664                     mxImportInfo->setPropertyValue(sRepeat, cppu::bool2any(mpProgressBarHelper->GetRepeat()));
665                 // pProgressBarHelper is deleted in dtor
666 			}
667 			OUString sNumberStyles(RTL_CONSTASCII_USTRINGPARAM(XML_NUMBERSTYLES));
668 			if (mxNumberStyles.is() && xPropertySetInfo->hasPropertyByName(sNumberStyles))
669 			{
670 				uno::Any aAny;
671 				aAny <<= mxNumberStyles;
672 				mxImportInfo->setPropertyValue(sNumberStyles, aAny);
673 			}
674 		}
675 	}
676 
677 	if( mxFontDecls.Is() )
678 		((SvXMLStylesContext *)&mxFontDecls)->Clear();
679 	if( mxStyles.Is() )
680 		((SvXMLStylesContext *)&mxStyles)->Clear();
681 	if( mxAutoStyles.Is() )
682 		((SvXMLStylesContext *)&mxAutoStyles)->Clear();
683 	if( mxMasterStyles.Is() )
684 		((SvXMLStylesContext *)&mxMasterStyles)->Clear();
685 
686     // possible form-layer related knittings which can only be done when
687     // the whole document exists
688     if ( mxFormImport.is() )
689         mxFormImport->documentDone();
690 
691 	//	The shape import helper does the z-order sorting in the dtor,
692 	//	so it must be deleted here, too.
693 	mxShapeImport = NULL;
694 
695 	if( mpImpl->mbOwnGraphicResolver )
696 	{
697 		Reference< lang::XComponent > xComp( mxGraphicResolver, UNO_QUERY );
698 		xComp->dispose();
699 	}
700 
701 	if( mpImpl->mbOwnEmbeddedResolver )
702 	{
703 		Reference< lang::XComponent > xComp( mxEmbeddedResolver, UNO_QUERY );
704 		xComp->dispose();
705 	}
706 	if( mpStyleMap )
707 	{
708 		mpStyleMap->release();
709 		mpStyleMap = 0;
710 	}
711 
712     if ( mpXMLErrors != NULL )
713     {
714         mpXMLErrors->ThrowErrorAsSAXException( XMLERROR_FLAG_SEVERE );
715     }
716 }
717 
718 void SAL_CALL SvXMLImport::startElement( const OUString& rName,
719 										 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
720 	throw(xml::sax::SAXException, uno::RuntimeException)
721 {
722 	SvXMLNamespaceMap *pRewindMap = 0;
723 
724 	// Process namespace attributes. This must happen before creating the
725 	// context, because namespace decaration apply to the element name itself.
726 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
727 	for( sal_Int16 i=0; i < nAttrCount; i++ )
728 	{
729 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
730         if ( rAttrName.equalsAscii("office:version") )
731         {
732             mpImpl->aODFVersion = xAttrList->getValueByIndex( i );
733 
734             // the ODF version in content.xml and manifest.xml must be the same starting from ODF1.2
735             if ( mpImpl->mStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) )
736               && !IsODFVersionConsistent( mpImpl->aODFVersion ) )
737             {
738                 throw xml::sax::SAXException(
739                         ::rtl::OUString(
740                             RTL_CONSTASCII_USTRINGPARAM( "Inconsistent ODF versions in content.xml and manifest.xml!" ) ),
741                         uno::Reference< uno::XInterface >(),
742                         uno::makeAny(
743                             packages::zip::ZipIOException(
744                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
745                                     "Inconsistent ODF versions in content.xml and manifest.xml!" ) ),
746 							    Reference< XInterface >() ) ) );
747             }
748         }
749         else if( ( rAttrName.getLength() >= 5 ) &&
750             ( rAttrName.compareTo( GetXMLToken(XML_XMLNS), 5 ) == 0 ) &&
751 			( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
752 		{
753 			if( !pRewindMap )
754 			{
755 				pRewindMap = mpNamespaceMap;
756 				mpNamespaceMap = new SvXMLNamespaceMap( *mpNamespaceMap );
757 			}
758 			const OUString& rAttrValue = xAttrList->getValueByIndex( i );
759 
760             OUString aPrefix( ( rAttrName.getLength() == 5 )
761                                  ? OUString()
762                                  : rAttrName.copy( 6 ) );
763 			// Add namespace, but only if it is known.
764 			sal_uInt16 nKey = mpNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
765 			// If namespace is unknwon, try to match a name with similar
766 			// TC Id an version
767             if( XML_NAMESPACE_UNKNOWN == nKey  )
768 			{
769 				OUString aTestName( rAttrValue );
770 				if( SvXMLNamespaceMap::NormalizeURI( aTestName ) )
771 					nKey = mpNamespaceMap->AddIfKnown( aPrefix, aTestName );
772 			}
773 			// If that namespace is not known, too, add it as unknown
774             if( XML_NAMESPACE_UNKNOWN == nKey  )
775 				mpNamespaceMap->Add( aPrefix, rAttrValue );
776 
777 		}
778 	}
779 
780 	// Get element's namespace and local name.
781 	OUString aLocalName;
782 	sal_uInt16 nPrefix =
783 		mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
784 
785 	// If there are contexts already, call a CreateChildContext at the topmost
786 	// context. Otherwise, create a default context.
787 	SvXMLImportContext *pContext;
788 	sal_uInt16 nCount = mpContexts->Count();
789 	if( nCount > 0 )
790 	{
791 		pContext = (*mpContexts)[nCount - 1]->CreateChildContext( nPrefix,
792 																 aLocalName,
793 																 xAttrList );
794         DBG_ASSERT( pContext && pContext->GetPrefix() == nPrefix,
795 				"SvXMLImport::startElement: created context has wrong prefix" );
796 	}
797 	else
798 	{
799 #ifdef TIMELOG
800         // If we do profiling, we want a trace message for the first element
801         // in order to identify the stream.
802         ByteString aString( (String)rName, RTL_TEXTENCODING_ASCII_US );
803         RTL_LOGFILE_TRACE_AUTHOR1( "xmloff", LOGFILE_AUTHOR,
804                                    "SvXMLImport::StartElement( \"%s\", ... )",
805                                    aString.GetBuffer() );
806 #endif
807 
808 		pContext = CreateContext( nPrefix, aLocalName, xAttrList );
809 		if( (nPrefix & XML_NAMESPACE_UNKNOWN_FLAG) != 0 &&
810 			IS_TYPE( SvXMLImportContext, pContext ) )
811 		{
812 			OUString aMsg( RTL_CONSTASCII_USTRINGPARAM( "Root element unknown" ) );
813     		Reference<xml::sax::XLocator> xDummyLocator;
814 			Sequence < OUString > aParams(1);
815 			aParams.getArray()[0] = rName;
816 
817 			SetError( XMLERROR_FLAG_SEVERE|XMLERROR_UNKNWON_ROOT,
818 					  aParams, aMsg, xDummyLocator );
819 		}
820 	}
821 
822 	DBG_ASSERT( pContext, "SvXMLImport::startElement: missing context" );
823 	if( !pContext )
824 		pContext = new SvXMLImportContext( *this, nPrefix, aLocalName );
825 
826 	pContext->AddRef();
827 
828 	// Remeber old namespace map.
829 	if( pRewindMap )
830 		pContext->SetRewindMap( pRewindMap );
831 
832 	// Call a startElement at the new context.
833 	pContext->StartElement( xAttrList );
834 
835 	// Push context on stack.
836 	mpContexts->Insert( pContext, nCount );
837 }
838 
839 void SAL_CALL SvXMLImport::endElement( const OUString&
840 #ifdef DBG_UTIL
841 rName
842 #endif
843 )
844 	throw(xml::sax::SAXException, uno::RuntimeException)
845 {
846 	sal_uInt16 nCount = mpContexts->Count();
847 	DBG_ASSERT( nCount, "SvXMLImport::endElement: no context left" );
848 	if( nCount > 0 )
849 	{
850 		// Get topmost context and remove it from the stack.
851 		SvXMLImportContext *pContext = (*mpContexts)[nCount-1];
852 		mpContexts->Remove( nCount-1, 1 );
853 
854 #ifdef DBG_UTIL
855 		// Non product only: check if endElement call matches startELement call.
856 		OUString aLocalName;
857 		sal_uInt16 nPrefix =
858 			mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
859 		DBG_ASSERT( pContext->GetPrefix() == nPrefix,
860 				"SvXMLImport::endElement: popped context has wrong prefix" );
861 		DBG_ASSERT( pContext->GetLocalName() == aLocalName,
862 				"SvXMLImport::endElement: popped context has wrong lname" );
863 #endif
864 
865 		// Call a EndElement at the current context.
866 		pContext->EndElement();
867 
868 		// Get a namespace map to rewind.
869 		SvXMLNamespaceMap *pRewindMap = pContext->GetRewindMap();
870 
871 		// Delete the current context.
872 		pContext->ReleaseRef();
873 		pContext = 0;
874 
875 		// Rewind a namespace map.
876 		if( pRewindMap )
877 		{
878 			delete mpNamespaceMap;
879 			mpNamespaceMap = pRewindMap;
880 		}
881 	}
882 }
883 
884 void SAL_CALL SvXMLImport::characters( const OUString& rChars )
885 	throw(xml::sax::SAXException, uno::RuntimeException)
886 {
887 	sal_uInt16 nCount = mpContexts->Count();
888 	if( nCount > 0 )
889 	{
890 		(*mpContexts)[nCount - 1]->Characters( rChars );
891 	}
892 }
893 
894 void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
895 	throw(xml::sax::SAXException, uno::RuntimeException)
896 {
897 }
898 
899 void SAL_CALL SvXMLImport::processingInstruction( const OUString&,
900 									   const OUString& )
901 	throw(xml::sax::SAXException, uno::RuntimeException)
902 {
903 }
904 
905 void SAL_CALL SvXMLImport::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& rLocator )
906 	throw(xml::sax::SAXException, uno::RuntimeException)
907 {
908 	mxLocator = rLocator;
909 }
910 
911 // XExtendedDocumentHandler
912 void SAL_CALL SvXMLImport::startCDATA( void ) throw(xml::sax::SAXException, uno::RuntimeException)
913 {
914 }
915 
916 void SAL_CALL SvXMLImport::endCDATA( void ) throw(uno::RuntimeException)
917 {
918 }
919 
920 void SAL_CALL SvXMLImport::comment( const OUString& )
921 	throw(xml::sax::SAXException, uno::RuntimeException)
922 {
923 }
924 
925 void SAL_CALL SvXMLImport::allowLineBreak( void )
926 	throw(xml::sax::SAXException, uno::RuntimeException)
927 {
928 }
929 
930 void SAL_CALL SvXMLImport::unknown( const OUString& )
931 	throw(xml::sax::SAXException, uno::RuntimeException)
932 {
933 }
934 
935 void SvXMLImport::SetStatistics(const uno::Sequence< beans::NamedValue> &)
936 {
937     GetProgressBarHelper()->SetRepeat(sal_False);
938     GetProgressBarHelper()->SetReference(0);
939 }
940 
941 ///////////////////////////////////////////////////////////////////////
942 
943 // XImporter
944 void SAL_CALL SvXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
945 	throw(lang::IllegalArgumentException, uno::RuntimeException)
946 {
947 	mxModel = uno::Reference< frame::XModel >::query( xDoc );
948 	if( !mxModel.is() )
949 		throw lang::IllegalArgumentException();
950 	if (mxModel.is() && !mxEventListener.is())
951 	{
952 		mxEventListener.set(new SvXMLImportEventListener(this));
953 		mxModel->addEventListener(mxEventListener);
954 	}
955 
956 	DBG_ASSERT( !mpNumImport, "number format import already exists." );
957 	if( mpNumImport )
958 	{
959 		delete mpNumImport;
960 		mpNumImport = 0;
961 	}
962 }
963 
964 // XFilter
965 sal_Bool SAL_CALL SvXMLImport::filter( const uno::Sequence< beans::PropertyValue >& )
966     throw (uno::RuntimeException)
967 {
968     return sal_False;
969 }
970 
971 void SAL_CALL SvXMLImport::cancel(  )
972     throw (uno::RuntimeException)
973 {
974 }
975 
976 // XInitialize
977 void SAL_CALL SvXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
978 	throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
979 {
980 	const sal_Int32 nAnyCount = aArguments.getLength();
981 	const uno::Any* pAny = aArguments.getConstArray();
982 
983 	for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
984     {
985         Reference<XInterface> xValue;
986         *pAny >>= xValue;
987 
988         uno::Reference<task::XStatusIndicator> xTmpStatusIndicator(
989             xValue, UNO_QUERY );
990 		if( xTmpStatusIndicator.is() )
991 			mxStatusIndicator = xTmpStatusIndicator;
992 
993         uno::Reference<document::XGraphicObjectResolver> xTmpGraphicResolver(
994             xValue, UNO_QUERY );
995 		if( xTmpGraphicResolver.is() )
996 			mxGraphicResolver = xTmpGraphicResolver;
997 
998         uno::Reference<document::XEmbeddedObjectResolver> xTmpObjectResolver(
999             xValue, UNO_QUERY );
1000         if( xTmpObjectResolver.is() )
1001             mxEmbeddedResolver = xTmpObjectResolver;
1002 
1003         uno::Reference<beans::XPropertySet> xTmpPropSet( xValue, UNO_QUERY );
1004         if( xTmpPropSet.is() )
1005         {
1006             mxImportInfo = xTmpPropSet;
1007             uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
1008             if (xPropertySetInfo.is())
1009 			{
1010                 OUString sPropName(RTL_CONSTASCII_USTRINGPARAM(XML_NUMBERSTYLES));
1011                 if (xPropertySetInfo->hasPropertyByName(sPropName))
1012 				{
1013                     uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1014                     aAny >>= mxNumberStyles;
1015 				}
1016 
1017 				sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("PrivateData" ) );
1018                 if (xPropertySetInfo->hasPropertyByName(sPropName))
1019 				{
1020 					Reference < XInterface > xIfc;
1021                     uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1022                     aAny >>= xIfc;
1023 
1024 					StyleMap *pSMap = StyleMap::getImplementation( xIfc );
1025 					if( pSMap )
1026 					{
1027 						mpStyleMap = pSMap;
1028 						mpStyleMap->acquire();
1029 					}
1030 				}
1031 				OUString sBaseURI;
1032 				sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("BaseURI" ) );
1033                 if (xPropertySetInfo->hasPropertyByName(sPropName))
1034 				{
1035                     uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1036                     aAny >>= sBaseURI;
1037 					mpImpl->aBaseURL.SetURL( sBaseURI );
1038                     mpImpl->aDocBase.SetURL( sBaseURI );
1039 				}
1040 				OUString sRelPath;
1041 				sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamRelPath" ) );
1042 				if( xPropertySetInfo->hasPropertyByName(sPropName) )
1043 				{
1044 					uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1045 					aAny >>= sRelPath;
1046 				}
1047 				OUString sName;
1048 				sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("StreamName" ) );
1049 				if( xPropertySetInfo->hasPropertyByName(sPropName) )
1050 				{
1051 					uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1052 					aAny >>= sName;
1053 				}
1054 				if( sBaseURI.getLength() && sName.getLength() )
1055 				{
1056 					if( sRelPath.getLength() )
1057 						mpImpl->aBaseURL.insertName( sRelPath );
1058 					mpImpl->aBaseURL.insertName( sName );
1059 				}
1060                 mpImpl->mStreamName = sName; // Note: may be empty (XSLT)
1061                 // --> OD 2004-08-10 #i28749# - retrieve property <ShapePositionInHoriL2R>
1062                 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("ShapePositionInHoriL2R" ) );
1063                 if( xPropertySetInfo->hasPropertyByName(sPropName) )
1064                 {
1065                     uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1066                     aAny >>= (mpImpl->mbShapePositionInHoriL2R);
1067                 }
1068                 // <--
1069                 // --> OD 2007-12-19 #152540#
1070                 sPropName = OUString( RTL_CONSTASCII_USTRINGPARAM("TextDocInOOoFileFormat" ) );
1071                 if( xPropertySetInfo->hasPropertyByName(sPropName) )
1072                 {
1073                     uno::Any aAny = mxImportInfo->getPropertyValue(sPropName);
1074                     aAny >>= (mpImpl->mbTextDocInOOoFileFormat);
1075                 }
1076                 // <--
1077             }
1078 		}
1079 	}
1080 }
1081 
1082 // XServiceInfo
1083 OUString SAL_CALL SvXMLImport::getImplementationName()
1084 	throw(uno::RuntimeException)
1085 {
1086 	OUString aStr;
1087 	return aStr;
1088 }
1089 
1090 sal_Bool SAL_CALL SvXMLImport::supportsService( const OUString& rServiceName )
1091 	throw(::com::sun::star::uno::RuntimeException)
1092 {
1093     return
1094         rServiceName.equalsAsciiL(
1095             "com.sun.star.document.ImportFilter",
1096             sizeof("com.sun.star.document.ImportFilter")-1 ) ||
1097         rServiceName.equalsAsciiL(
1098             "com.sun.star.xml.XMLImportFilter",
1099             sizeof("com.sun.star.xml.XMLImportFilter")-1);
1100 }
1101 
1102 uno::Sequence< OUString > SAL_CALL SvXMLImport::getSupportedServiceNames(  )
1103 	throw(uno::RuntimeException)
1104 {
1105     uno::Sequence<OUString> aSeq(2);
1106     aSeq[0] = OUString(
1107         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ImportFilter"));
1108     aSeq[1] = OUString(
1109         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.XMLImportFilter"));
1110     return aSeq;
1111 }
1112 
1113 ///////////////////////////////////////////////////////////////////////
1114 
1115 XMLTextImportHelper* SvXMLImport::CreateTextImport()
1116 {
1117 	return new XMLTextImportHelper( mxModel, *this );
1118 }
1119 
1120 XMLShapeImportHelper* SvXMLImport::CreateShapeImport()
1121 {
1122 	return new XMLShapeImportHelper( *this, mxModel );
1123 }
1124 
1125 #ifndef SVX_LIGHT
1126 SchXMLImportHelper* SvXMLImport::CreateChartImport()
1127 {
1128 	return new SchXMLImportHelper();
1129 }
1130 #endif
1131 
1132 #ifndef SVX_LIGHT
1133 ::xmloff::OFormLayerXMLImport* SvXMLImport::CreateFormImport()
1134 {
1135 	return new ::xmloff::OFormLayerXMLImport(*this);
1136 }
1137 #endif // #ifndef SVX_LIGHT
1138 
1139 
1140 ///////////////////////////////////////////////////////////////////////////////
1141 //
1142 // Get or create fill/line/lineend-style-helper
1143 //
1144 
1145 const Reference< container::XNameContainer > & SvXMLImport::GetGradientHelper()
1146 {
1147 	if( !mxGradientHelper.is() )
1148 	{
1149 		if( mxModel.is() )
1150 		{
1151 			Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1152 			if( xServiceFact.is() )
1153 			{
1154 				try
1155 				{
1156 					mxGradientHelper =  Reference< container::XNameContainer >( xServiceFact->createInstance(
1157 						OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.GradientTable" ) ) ), UNO_QUERY);
1158 				}
1159 				catch( lang::ServiceNotRegisteredException& )
1160 				{}
1161 			}
1162 		}
1163 	}
1164 
1165 	return mxGradientHelper;
1166 }
1167 
1168 const Reference< container::XNameContainer > & SvXMLImport::GetHatchHelper()
1169 {
1170 	if( !mxHatchHelper.is() )
1171 	{
1172 		if( mxModel.is() )
1173 		{
1174 			Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1175 			if( xServiceFact.is() )
1176 			{
1177 				try
1178 				{
1179 					mxHatchHelper =  Reference< container::XNameContainer >( xServiceFact->createInstance(
1180 						OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.HatchTable" ) ) ), UNO_QUERY);
1181 				}
1182 				catch( lang::ServiceNotRegisteredException& )
1183 				{}
1184 			}
1185 		}
1186 	}
1187 
1188 	return mxHatchHelper;
1189 }
1190 
1191 const Reference< container::XNameContainer > & SvXMLImport::GetBitmapHelper()
1192 {
1193 	if( !mxBitmapHelper.is() )
1194 	{
1195 		if( mxModel.is() )
1196 		{
1197 			Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1198 			if( xServiceFact.is() )
1199 			{
1200 				try
1201 				{
1202 					mxBitmapHelper =  Reference< container::XNameContainer >( xServiceFact->createInstance(
1203 						OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.BitmapTable" ) ) ), UNO_QUERY);
1204 				}
1205 				catch( lang::ServiceNotRegisteredException& )
1206 				{}
1207 			}
1208 		}
1209 	}
1210 
1211 	return mxBitmapHelper;
1212 }
1213 
1214 const Reference< container::XNameContainer > & SvXMLImport::GetTransGradientHelper()
1215 {
1216 	if( !mxTransGradientHelper.is() )
1217 	{
1218 		if( mxModel.is() )
1219 		{
1220 			Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1221 			if( xServiceFact.is() )
1222 			{
1223 				try
1224 				{
1225 					mxTransGradientHelper =  Reference< container::XNameContainer >( xServiceFact->createInstance(
1226 						OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.TransparencyGradientTable" ) ) ), UNO_QUERY);
1227 				}
1228 				catch( lang::ServiceNotRegisteredException& )
1229 				{}
1230 			}
1231 		}
1232 	}
1233 
1234 	return mxTransGradientHelper;
1235 }
1236 
1237 const Reference< container::XNameContainer > & SvXMLImport::GetMarkerHelper()
1238 {
1239 	if( !mxMarkerHelper.is() )
1240 	{
1241 		if( mxModel.is() )
1242 		{
1243 			Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1244 			if( xServiceFact.is() )
1245 			{
1246 				try
1247 				{
1248 					mxMarkerHelper =  Reference< container::XNameContainer >( xServiceFact->createInstance(
1249 						OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.MarkerTable" ) ) ), UNO_QUERY);
1250 				}
1251 				catch( lang::ServiceNotRegisteredException& )
1252 				{}
1253 			}
1254 		}
1255 	}
1256 
1257 	return mxMarkerHelper;
1258 }
1259 
1260 const Reference< container::XNameContainer > & SvXMLImport::GetDashHelper()
1261 {
1262 	if( !mxDashHelper.is() )
1263 	{
1264 		if( mxModel.is() )
1265 		{
1266 			Reference< lang::XMultiServiceFactory > xServiceFact( mxModel, UNO_QUERY);
1267 			if( xServiceFact.is() )
1268 			{
1269 				try
1270 				{
1271 					mxDashHelper =  Reference< container::XNameContainer >( xServiceFact->createInstance(
1272 						OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DashTable" ) ) ), UNO_QUERY);
1273 				}
1274 				catch( lang::ServiceNotRegisteredException& )
1275 				{}
1276 			}
1277 		}
1278 	}
1279 
1280 	return mxDashHelper;
1281 }
1282 
1283 sal_Bool SvXMLImport::IsPackageURL( const ::rtl::OUString& rURL ) const
1284 {
1285 
1286 	// if, and only if, only parts are imported, then we're in a package
1287 	const sal_uInt32 nTest = IMPORT_META|IMPORT_STYLES|IMPORT_CONTENT|IMPORT_SETTINGS;
1288 	if( (mnImportFlags & nTest) == nTest )
1289 		return sal_False;
1290 
1291 	// Some quick tests: Some may rely on the package structure!
1292 	sal_Int32 nLen = rURL.getLength();
1293 	if( (nLen > 0 && '/' == rURL[0]) )
1294 		// RFC2396 net_path or abs_path
1295 		return sal_False;
1296 	else if( nLen > 1 && '.' == rURL[0] )
1297 	{
1298 		if( '.' == rURL[1] )
1299 			// ../: We are never going up one level, so we know
1300 			// it's not an external URI
1301 			return sal_False;
1302 		else if( '/' == rURL[1] )
1303 			// we are remaining on a level, so it's an package URI
1304 			return sal_True;
1305 	}
1306 
1307 	// Now check for a RFC2396 schema
1308 	sal_Int32 nPos = 1;
1309 	while( nPos < nLen )
1310 	{
1311 		switch( rURL[nPos] )
1312 		{
1313 		case '/':
1314 			// a relative path segement
1315 			return sal_True;
1316 		case ':':
1317 			// a schema
1318 			return sal_False;
1319 		default:
1320 			break;
1321 			// we don't care about any other characters
1322 		}
1323 		++nPos;
1324 	}
1325 
1326 	return sal_True;
1327 }
1328 
1329 ::rtl::OUString SvXMLImport::ResolveGraphicObjectURL( const ::rtl::OUString& rURL,
1330 									                  sal_Bool bLoadOnDemand )
1331 {
1332 	::rtl::OUString sRet;
1333 
1334 	if( IsPackageURL( rURL ) )
1335 	{
1336 		if( !bLoadOnDemand && mxGraphicResolver.is() )
1337 		{
1338 			::rtl::OUString		aTmp( msPackageProtocol );
1339 			aTmp += rURL;
1340 			sRet = mxGraphicResolver->resolveGraphicObjectURL( aTmp );
1341 		}
1342 
1343 		if( !sRet.getLength() )
1344 		{
1345 			sRet = msPackageProtocol;
1346 			sRet += rURL;
1347 		}
1348 	}
1349 
1350 	if( !sRet.getLength() )
1351 		sRet = GetAbsoluteReference( rURL );
1352 
1353 	return sRet;
1354 }
1355 
1356 Reference< XOutputStream > SvXMLImport::GetStreamForGraphicObjectURLFromBase64()
1357 {
1358 	Reference< XOutputStream > xOStm;
1359 	Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1360 
1361 	if( xStmResolver.is() )
1362         xOStm = xStmResolver->createOutputStream();
1363 
1364 	return xOStm;
1365 }
1366 
1367 ::rtl::OUString SvXMLImport::ResolveGraphicObjectURLFromBase64(
1368 								 const Reference < XOutputStream >& rOut )
1369 {
1370 	OUString sURL;
1371 	Reference< document::XBinaryStreamResolver > xStmResolver( mxGraphicResolver, UNO_QUERY );
1372 	if( xStmResolver.is() )
1373 		sURL = xStmResolver->resolveOutputStream( rOut );
1374 
1375 	return sURL;
1376 }
1377 
1378 ::rtl::OUString SvXMLImport::ResolveEmbeddedObjectURL(
1379 									const ::rtl::OUString& rURL,
1380 									const ::rtl::OUString& rClassId )
1381 {
1382 	::rtl::OUString sRet;
1383 
1384 	if( IsPackageURL( rURL ) )
1385 	{
1386 		if ( mxEmbeddedResolver.is() )
1387 		{
1388 			OUString sURL( rURL );
1389 			if( rClassId.getLength() )
1390 			{
1391 				sURL += OUString( sal_Unicode('!') );
1392 				sURL += rClassId;
1393 			}
1394 			sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( sURL );
1395 		}
1396 	}
1397 	else
1398 		sRet = GetAbsoluteReference( rURL );
1399 
1400 	return sRet;
1401 }
1402 
1403 Reference < XOutputStream >
1404 		SvXMLImport::GetStreamForEmbeddedObjectURLFromBase64()
1405 {
1406 	Reference < XOutputStream > xOLEStream;
1407 
1408 	if( mxEmbeddedResolver.is() )
1409 	{
1410 		Reference< XNameAccess > xNA( mxEmbeddedResolver, UNO_QUERY );
1411 		if( xNA.is() )
1412 		{
1413 			OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "Obj12345678" ) );
1414 			Any aAny = xNA->getByName( aURL );
1415 			aAny >>= xOLEStream;
1416 		}
1417 	}
1418 
1419 	return xOLEStream;
1420 }
1421 
1422 ::rtl::OUString SvXMLImport::ResolveEmbeddedObjectURLFromBase64()
1423 {
1424 	::rtl::OUString sRet;
1425 
1426 	if( mxEmbeddedResolver.is() )
1427 	{
1428 		OUString aURL( RTL_CONSTASCII_USTRINGPARAM( "Obj12345678" ) );
1429 		sRet = mxEmbeddedResolver->resolveEmbeddedObjectURL( aURL );
1430 	}
1431 
1432 	return sRet;
1433 }
1434 
1435 void SvXMLImport::AddStyleDisplayName( sal_uInt16 nFamily,
1436 									   const OUString& rName,
1437 									   const OUString& rDisplayName )
1438 {
1439 	if( !mpStyleMap )
1440 	{
1441 		mpStyleMap = new StyleMap;
1442 		mpStyleMap->acquire();
1443 		if( mxImportInfo.is() )
1444 		{
1445 			OUString sPrivateData(
1446 					RTL_CONSTASCII_USTRINGPARAM("PrivateData" ) );
1447             Reference< beans::XPropertySetInfo > xPropertySetInfo =
1448 				mxImportInfo->getPropertySetInfo();
1449             if( xPropertySetInfo.is() &&
1450 				xPropertySetInfo->hasPropertyByName(sPrivateData) )
1451 			{
1452 				Reference < XInterface > xIfc(
1453 						static_cast< XUnoTunnel *>( mpStyleMap ) );
1454 				Any aAny;
1455 				aAny <<= xIfc;
1456 				mxImportInfo->setPropertyValue( sPrivateData, aAny );
1457 			}
1458 		}
1459 	}
1460 
1461 	StyleMap::key_type aKey( nFamily, rName );
1462 	StyleMap::value_type aValue( aKey, rDisplayName );
1463 	::std::pair<StyleMap::iterator,bool> aRes( mpStyleMap->insert( aValue ) );
1464 	OSL_ENSURE( aRes.second, "duplicate style name" );
1465 
1466 }
1467 
1468 OUString SvXMLImport::GetStyleDisplayName( sal_uInt16 nFamily,
1469 										   const OUString& rName ) const
1470 {
1471 	OUString sName( rName );
1472 	if( mpStyleMap && rName.getLength() )
1473 	{
1474 		StyleMap::key_type aKey( nFamily, rName );
1475 		StyleMap::const_iterator aIter = mpStyleMap->find( aKey );
1476 		if( aIter != mpStyleMap->end() )
1477 			sName = (*aIter).second;
1478 	}
1479 	return sName;
1480 }
1481 
1482 void SvXMLImport::SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1483 {
1484 }
1485 
1486 void SvXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>&)
1487 {
1488 }
1489 
1490 void SvXMLImport::SetDocumentSpecificSettings(const ::rtl::OUString& _rSettingsGroupName, const uno::Sequence<beans::PropertyValue>& _rSettings)
1491 {
1492     (void)_rSettingsGroupName;
1493     (void)_rSettings;
1494 }
1495 
1496 ProgressBarHelper*	SvXMLImport::GetProgressBarHelper()
1497 {
1498 	if (!mpProgressBarHelper)
1499 	{
1500 		mpProgressBarHelper = new ProgressBarHelper(mxStatusIndicator, sal_False);
1501 
1502 		if (mxImportInfo.is())
1503 		{
1504 			uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = mxImportInfo->getPropertySetInfo();
1505 			if (xPropertySetInfo.is())
1506 			{
1507 				OUString sProgressRange(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSRANGE));
1508 				OUString sProgressMax(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSMAX));
1509 				OUString sProgressCurrent(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSCURRENT));
1510                 OUString sRepeat(RTL_CONSTASCII_USTRINGPARAM(XML_PROGRESSREPEAT));
1511 				if (xPropertySetInfo->hasPropertyByName(sProgressMax) &&
1512 					xPropertySetInfo->hasPropertyByName(sProgressCurrent) &&
1513 					xPropertySetInfo->hasPropertyByName(sProgressRange))
1514 				{
1515 					uno::Any aAny;
1516 					sal_Int32 nProgressMax(0);
1517 					sal_Int32 nProgressCurrent(0);
1518 					sal_Int32 nProgressRange(0);
1519 					aAny = mxImportInfo->getPropertyValue(sProgressRange);
1520 					if (aAny >>= nProgressRange)
1521 						mpProgressBarHelper->SetRange(nProgressRange);
1522 					aAny = mxImportInfo->getPropertyValue(sProgressMax);
1523 					if (aAny >>= nProgressMax)
1524 						mpProgressBarHelper->SetReference(nProgressMax);
1525 					aAny = mxImportInfo->getPropertyValue(sProgressCurrent);
1526 					if (aAny >>= nProgressCurrent)
1527 						mpProgressBarHelper->SetValue(nProgressCurrent);
1528 				}
1529                 if (xPropertySetInfo->hasPropertyByName(sRepeat))
1530                 {
1531                     uno::Any aAny = mxImportInfo->getPropertyValue(sRepeat);
1532                     if (aAny.getValueType() == getBooleanCppuType())
1533                         mpProgressBarHelper->SetRepeat(::cppu::any2bool(aAny));
1534                     else {
1535                         DBG_ERRORFILE("why is it no boolean?");
1536                     }
1537                 }
1538 			}
1539 		}
1540 	}
1541 	return mpProgressBarHelper;
1542 }
1543 
1544 void SvXMLImport::AddNumberStyle(sal_Int32 nKey, const OUString& rName)
1545 {
1546 	if (!mxNumberStyles.is())
1547 		mxNumberStyles = uno::Reference< container::XNameContainer >( comphelper::NameContainer_createInstance( ::getCppuType((const sal_Int32*)0)) );
1548 	if (mxNumberStyles.is())
1549 	{
1550 		uno::Any aAny;
1551 		aAny <<= nKey;
1552 		try
1553 		{
1554 			mxNumberStyles->insertByName(rName, aAny);
1555 		}
1556 		catch ( uno::Exception& )
1557 		{
1558 			DBG_ERROR("Numberformat could not be inserted");
1559 		}
1560 	}
1561 	else {
1562 		DBG_ERROR("not possible to create NameContainer");
1563     }
1564 }
1565 
1566 XMLEventImportHelper& SvXMLImport::GetEventImport()
1567 {
1568 #ifndef SVX_LIGHT
1569 	if (!mpEventImportHelper)
1570 	{
1571 		// construct event helper and register StarBasic handler and standard
1572 		// event tables
1573 		mpEventImportHelper = new XMLEventImportHelper();
1574 		OUString sStarBasic(GetXMLToken(XML_STARBASIC));
1575 		mpEventImportHelper->RegisterFactory(sStarBasic,
1576 											new XMLStarBasicContextFactory());
1577 		OUString sScript(GetXMLToken(XML_SCRIPT));
1578 		mpEventImportHelper->RegisterFactory(sScript,
1579 											new XMLScriptContextFactory());
1580 		mpEventImportHelper->AddTranslationTable(aStandardEventTable);
1581 
1582         // register StarBasic event handler with capitalized spelling
1583 		OUString sStarBasicCap(RTL_CONSTASCII_USTRINGPARAM("StarBasic"));
1584 		mpEventImportHelper->RegisterFactory(sStarBasicCap,
1585 											new XMLStarBasicContextFactory());
1586 	}
1587 #endif
1588 
1589 	return *mpEventImportHelper;
1590 }
1591 
1592 void SvXMLImport::SetFontDecls( XMLFontStylesContext *pFontDecls )
1593 {
1594 	mxFontDecls = pFontDecls;
1595 	GetTextImport()->SetFontDecls( pFontDecls );
1596 }
1597 
1598 void SvXMLImport::SetStyles( SvXMLStylesContext *pStyles )
1599 {
1600 	mxStyles = pStyles;
1601 }
1602 
1603 void SvXMLImport::SetAutoStyles( SvXMLStylesContext *pAutoStyles )
1604 {
1605 	if (pAutoStyles && mxNumberStyles.is() && (mnImportFlags & IMPORT_CONTENT) )
1606 	{
1607 		uno::Reference<xml::sax::XAttributeList> xAttrList;
1608 		uno::Sequence< ::rtl::OUString > aNames = mxNumberStyles->getElementNames();
1609 		sal_uInt32 nCount(aNames.getLength());
1610 		if (nCount)
1611 		{
1612 			const OUString* pNames = aNames.getConstArray();
1613 			if ( pNames )
1614 			{
1615 				SvXMLStyleContext* pContext;
1616 				uno::Any aAny;
1617 				sal_Int32 nKey(0);
1618 				for (sal_uInt32 i = 0; i < nCount; i++, pNames++)
1619 				{
1620 					aAny = mxNumberStyles->getByName(*pNames);
1621 					if (aAny >>= nKey)
1622 					{
1623 						pContext = new SvXMLNumFormatContext( *this, XML_NAMESPACE_NUMBER,
1624 									*pNames, xAttrList, nKey, *pAutoStyles );
1625 						pAutoStyles->AddStyle(*pContext);
1626 					}
1627 				}
1628 			}
1629 		}
1630 	}
1631 	mxAutoStyles = pAutoStyles;
1632 	GetTextImport()->SetAutoStyles( pAutoStyles );
1633 	GetShapeImport()->SetAutoStylesContext( pAutoStyles );
1634 #ifndef SVX_LIGHT
1635 	GetChartImport()->SetAutoStylesContext( pAutoStyles );
1636 	GetFormImport()->setAutoStyleContext( pAutoStyles );
1637 #endif
1638 }
1639 
1640 void SvXMLImport::SetMasterStyles( SvXMLStylesContext *pMasterStyles )
1641 {
1642 	mxMasterStyles = pMasterStyles;
1643 }
1644 
1645 XMLFontStylesContext *SvXMLImport::GetFontDecls()
1646 {
1647 	return (XMLFontStylesContext *)&mxFontDecls;
1648 }
1649 
1650 SvXMLStylesContext *SvXMLImport::GetStyles()
1651 {
1652 	return (SvXMLStylesContext *)&mxStyles;
1653 }
1654 
1655 SvXMLStylesContext *SvXMLImport::GetAutoStyles()
1656 {
1657 	return (SvXMLStylesContext *)&mxAutoStyles;
1658 }
1659 
1660 SvXMLStylesContext *SvXMLImport::GetMasterStyles()
1661 {
1662 	return (SvXMLStylesContext *)&mxMasterStyles;
1663 }
1664 
1665 const XMLFontStylesContext *SvXMLImport::GetFontDecls() const
1666 {
1667 	return (const XMLFontStylesContext *)&mxFontDecls;
1668 }
1669 
1670 const SvXMLStylesContext *SvXMLImport::GetStyles() const
1671 {
1672 	return (const SvXMLStylesContext *)&mxStyles;
1673 }
1674 
1675 const SvXMLStylesContext *SvXMLImport::GetAutoStyles() const
1676 {
1677 	return (const SvXMLStylesContext *)&mxAutoStyles;
1678 }
1679 
1680 const SvXMLStylesContext *SvXMLImport::GetMasterStyles() const
1681 {
1682 	return (const SvXMLStylesContext *)&mxMasterStyles;
1683 }
1684 
1685 OUString SvXMLImport::GetAbsoluteReference(const OUString& rValue) const
1686 {
1687 	if( rValue.getLength() == 0 || rValue[0] == '#' )
1688 		return rValue;
1689 
1690 	INetURLObject aAbsURL;
1691 	if( mpImpl->aBaseURL.GetNewAbsURL( rValue, &aAbsURL ) )
1692 		return aAbsURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
1693 	else
1694 		return rValue;
1695 }
1696 
1697 sal_Bool SvXMLImport::IsODFVersionConsistent( const ::rtl::OUString& aODFVersion )
1698 {
1699     // the check returns sal_False only if the storage version could be retrieved
1700     sal_Bool bResult = sal_True;
1701 
1702     if ( aODFVersion.getLength() && aODFVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
1703     {
1704         // check the consistency only for the ODF1.2 and later ( according to content.xml )
1705         // manifest.xml might have no version, it should be checked here and the correct version should be set
1706         try
1707         {
1708             uno::Reference< document::XStorageBasedDocument > xDoc( mxModel, uno::UNO_QUERY_THROW );
1709             uno::Reference< embed::XStorage > xStor = xDoc->getDocumentStorage();
1710             uno::Reference< beans::XPropertySet > xStorProps( xStor, uno::UNO_QUERY_THROW );
1711 
1712             // the check should be done only for OASIS format
1713             ::rtl::OUString aMediaType;
1714             xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= aMediaType;
1715             if ( ::comphelper::OStorageHelper::GetXStorageFormat( xStor ) >= SOFFICE_FILEFORMAT_8 )
1716             {
1717                 sal_Bool bRepairPackage = sal_False;
1718                 try
1719                 {
1720                     xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RepairPackage" ) ) )
1721                         >>= bRepairPackage;
1722                 } catch ( uno::Exception& )
1723                 {}
1724 
1725                 // check only if not in Repair mode
1726                 if ( !bRepairPackage )
1727                 {
1728                     ::rtl::OUString aStorVersion;
1729                     xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) )
1730                         >>= aStorVersion;
1731 
1732                     // if the storage version is set in manifest.xml, it must be the same as in content.xml
1733                     // if not, set it explicitly to be used further ( it will work even for readonly storage )
1734                     // This workaround is not nice, but I see no other way to handle it, since there are
1735                     // ODF1.2 documents without version in manifest.xml
1736                     if ( aStorVersion.getLength() )
1737                         bResult = aODFVersion.equals( aStorVersion );
1738                     else
1739                         xStorProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ),
1740                                                       uno::makeAny( aODFVersion ) );
1741 
1742                     if ( bResult )
1743                     {
1744                         sal_Bool bInconsistent = sal_False;
1745                         xStorProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsInconsistent" ) ) )
1746                             >>= bInconsistent;
1747                         bResult = !bInconsistent;
1748                     }
1749                 }
1750             }
1751         }
1752         catch( uno::Exception& )
1753         {}
1754     }
1755 
1756     return bResult;
1757 }
1758 
1759 void SvXMLImport::_CreateNumberFormatsSupplier()
1760 {
1761     DBG_ASSERT( !mxNumberFormatsSupplier.is(),
1762                 "number formats supplier already exists!" );
1763     if(mxModel.is())
1764     	mxNumberFormatsSupplier =
1765         	uno::Reference< util::XNumberFormatsSupplier> (mxModel, uno::UNO_QUERY);
1766 }
1767 
1768 
1769 void SvXMLImport::_CreateDataStylesImport()
1770 {
1771     DBG_ASSERT( mpNumImport == NULL, "data styles import already exists!" );
1772     uno::Reference<util::XNumberFormatsSupplier> xNum =
1773         GetNumberFormatsSupplier();
1774     if ( xNum.is() )
1775         mpNumImport = new SvXMLNumFmtHelper(xNum, getServiceFactory());
1776 }
1777 
1778 
1779 sal_Unicode SvXMLImport::ConvStarBatsCharToStarSymbol( sal_Unicode c )
1780 {
1781 	sal_Unicode cNew = c;
1782 	if( !mpImpl->hBatsFontConv )
1783 	{
1784 		OUString sStarBats( RTL_CONSTASCII_USTRINGPARAM( "StarBats" ) );
1785 		mpImpl->hBatsFontConv = CreateFontToSubsFontConverter( sStarBats,
1786 				 FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1787 		OSL_ENSURE( mpImpl->hBatsFontConv, "Got no symbol font converter" );
1788 	}
1789 	if( mpImpl->hBatsFontConv )
1790 	{
1791 		cNew = ConvertFontToSubsFontChar( mpImpl->hBatsFontConv, c );
1792 	}
1793 
1794 	return cNew;
1795 }
1796 
1797 sal_Unicode SvXMLImport::ConvStarMathCharToStarSymbol( sal_Unicode c )
1798 {
1799 	sal_Unicode cNew = c;
1800 	if( !mpImpl->hMathFontConv )
1801 	{
1802 		OUString sStarMath( RTL_CONSTASCII_USTRINGPARAM( "StarMath" ) );
1803 		mpImpl->hMathFontConv = CreateFontToSubsFontConverter( sStarMath,
1804 				 FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS );
1805 		OSL_ENSURE( mpImpl->hMathFontConv, "Got no symbol font converter" );
1806 	}
1807 	if( mpImpl->hMathFontConv )
1808 	{
1809 		cNew = ConvertFontToSubsFontChar( mpImpl->hMathFontConv, c );
1810 	}
1811 
1812 	return cNew;
1813 }
1814 
1815 
1816 
1817 void SvXMLImport::SetError(
1818     sal_Int32 nId,
1819     const Sequence<OUString>& rMsgParams,
1820     const OUString& rExceptionMessage,
1821     const Reference<xml::sax::XLocator>& rLocator )
1822 {
1823     // maintain error flags
1824     if ( ( nId & XMLERROR_FLAG_ERROR ) != 0 )
1825         mnErrorFlags |= ERROR_ERROR_OCCURED;
1826     if ( ( nId & XMLERROR_FLAG_WARNING ) != 0 )
1827         mnErrorFlags |= ERROR_WARNING_OCCURED;
1828     if ( ( nId & XMLERROR_FLAG_SEVERE ) != 0 )
1829         mnErrorFlags |= ERROR_DO_NOTHING;
1830 
1831     // create error list on demand
1832     if ( mpXMLErrors == NULL )
1833         mpXMLErrors = new XMLErrors();
1834 
1835     // save error information
1836     // use document locator (if none supplied)
1837     mpXMLErrors->AddRecord( nId, rMsgParams, rExceptionMessage,
1838                            rLocator.is() ? rLocator : mxLocator );
1839 }
1840 
1841 void SvXMLImport::SetError(
1842     sal_Int32 nId,
1843     const Sequence<OUString>& rMsgParams)
1844 {
1845     OUString sEmpty;
1846     SetError( nId, rMsgParams, sEmpty, NULL );
1847 }
1848 
1849 void SvXMLImport::SetError(
1850     sal_Int32 nId)
1851 {
1852     Sequence<OUString> aSeq(0);
1853     SetError( nId, aSeq );
1854 }
1855 
1856 void SvXMLImport::SetError(
1857     sal_Int32 nId,
1858     const OUString& rMsg1)
1859 {
1860     Sequence<OUString> aSeq(1);
1861     OUString* pSeq = aSeq.getArray();
1862     pSeq[0] = rMsg1;
1863     SetError( nId, aSeq );
1864 }
1865 
1866 void SvXMLImport::SetError(
1867     sal_Int32 nId,
1868     const OUString& rMsg1,
1869     const OUString& rMsg2)
1870 {
1871     Sequence<OUString> aSeq(2);
1872     OUString* pSeq = aSeq.getArray();
1873     pSeq[0] = rMsg1;
1874     pSeq[1] = rMsg2;
1875     SetError( nId, aSeq );
1876 }
1877 
1878 void SvXMLImport::SetError(
1879     sal_Int32 nId,
1880     const OUString& rMsg1,
1881     const OUString& rMsg2,
1882     const OUString& rMsg3)
1883 {
1884     Sequence<OUString> aSeq(3);
1885     OUString* pSeq = aSeq.getArray();
1886     pSeq[0] = rMsg1;
1887     pSeq[1] = rMsg2;
1888     pSeq[2] = rMsg3;
1889     SetError( nId, aSeq );
1890 }
1891 
1892 void SvXMLImport::SetError(
1893     sal_Int32 nId,
1894     const OUString& rMsg1,
1895     const OUString& rMsg2,
1896     const OUString& rMsg3,
1897     const OUString& rMsg4)
1898 {
1899     Sequence<OUString> aSeq(4);
1900     OUString* pSeq = aSeq.getArray();
1901     pSeq[0] = rMsg1;
1902     pSeq[1] = rMsg2;
1903     pSeq[2] = rMsg3;
1904     pSeq[3] = rMsg4;
1905     SetError( nId, aSeq );
1906 }
1907 
1908 XMLErrors* SvXMLImport::GetErrors()
1909 {
1910 	return mpXMLErrors;
1911 }
1912 
1913 void SvXMLImport::DisposingModel()
1914 {
1915 	if( mxFontDecls.Is() )
1916 		((SvXMLStylesContext *)&mxFontDecls)->Clear();
1917 	if( mxStyles.Is() )
1918 		((SvXMLStylesContext *)&mxStyles)->Clear();
1919 	if( mxAutoStyles.Is() )
1920 		((SvXMLStylesContext *)&mxAutoStyles)->Clear();
1921 	if( mxMasterStyles.Is() )
1922 		((SvXMLStylesContext *)&mxMasterStyles)->Clear();
1923 
1924 	mxModel.set(0);
1925 	mxEventListener.set(NULL);
1926 }
1927 
1928 ::comphelper::UnoInterfaceToUniqueIdentifierMapper& SvXMLImport::getInterfaceToIdentifierMapper()
1929 {
1930 	return mpImpl->maInterfaceToIdentifierMapper;
1931 }
1932 
1933 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > SvXMLImport::getServiceFactory()
1934 {
1935 	// #110680#
1936 	return mxServiceFactory;
1937 }
1938 
1939 uno::Reference< uno::XComponentContext >
1940 SvXMLImport::GetComponentContext() const
1941 {
1942     return mpImpl->mxComponentContext;
1943 }
1944 
1945 String SvXMLImport::GetBaseURL() const
1946 {
1947     return mpImpl->aBaseURL.GetMainURL( INetURLObject::NO_DECODE );
1948 }
1949 
1950 String SvXMLImport::GetDocumentBase() const
1951 {
1952     return mpImpl->aDocBase.GetMainURL( INetURLObject::NO_DECODE );
1953 }
1954 
1955 ::rtl::OUString SvXMLImport::GetStreamName() const
1956 {
1957     return mpImpl->mStreamName;
1958 }
1959 
1960 // --> OD 2004-08-10 #i28749#
1961 sal_Bool SvXMLImport::IsShapePositionInHoriL2R() const
1962 {
1963     return mpImpl->mbShapePositionInHoriL2R;
1964 }
1965 // <--
1966 
1967 // --> OD 2007-12-19 #152540#
1968 sal_Bool SvXMLImport::IsTextDocInOOoFileFormat() const
1969 {
1970     return mpImpl->mbTextDocInOOoFileFormat;
1971 }
1972 
1973 // <--
1974 
1975 void SvXMLImport::initXForms()
1976 {
1977     // dummy method; to be implemented by derived classes supporting XForms
1978 }
1979 
1980 bool SvXMLImport::getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const
1981 {
1982 	bool bRet = false;
1983 	if( mxImportInfo.is() ) try
1984 	{
1985 		const OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("BuildId"));
1986 		Reference< XPropertySetInfo > xSetInfo( mxImportInfo->getPropertySetInfo() );
1987 		if( xSetInfo.is() && xSetInfo->hasPropertyByName( aPropName ) )
1988 		{
1989 			OUString aBuildId;
1990 			mxImportInfo->getPropertyValue( aPropName ) >>= aBuildId;
1991 			if( aBuildId.getLength() )
1992 			{
1993 				sal_Int32 nIndex = aBuildId.indexOf('$');
1994 				if( nIndex != -1 )
1995 				{
1996 					rUPD = aBuildId.copy( 0, nIndex ).toInt32();
1997 					rBuild = aBuildId.copy( nIndex+1 ).toInt32();
1998 					bRet = true;
1999 				}
2000 			}
2001 		}
2002 	}
2003 	catch( Exception& )
2004 	{
2005 	}
2006 	return bRet;
2007 }
2008 
2009 sal_uInt16 SvXMLImport::getGeneratorVersion() const
2010 {
2011     // --> ORW
2012     return mpImpl->getGeneratorVersion( *this );
2013     // <--
2014 }
2015 
2016 bool SvXMLImport::isGraphicLoadOnDemandSupported() const
2017 {
2018     return mbIsGraphicLoadOnDemandSupported;
2019 }
2020 
2021 ::rtl::OUString SvXMLImport::GetODFVersion() const
2022 {
2023     return mpImpl->aODFVersion;
2024 }
2025 
2026 // xml:id for RDF metadata
2027 void SvXMLImport::SetXmlId(uno::Reference<uno::XInterface> const & i_xIfc,
2028     ::rtl::OUString const & i_rXmlId)
2029 {
2030     if (i_rXmlId.getLength() > 0) {
2031         try {
2032             const uno::Reference<rdf::XMetadatable> xMeta(i_xIfc,
2033                 uno::UNO_QUERY);
2034 //FIXME: not yet
2035 //            OSL_ENSURE(xMeta.is(), "xml:id: not XMetadatable");
2036             if (xMeta.is()) {
2037                 const beans::StringPair mdref( GetStreamName(), i_rXmlId );
2038                 try {
2039                     xMeta->setMetadataReference(mdref);
2040                 } catch (lang::IllegalArgumentException &) {
2041                     // probably duplicate; ignore
2042                     OSL_TRACE("SvXMLImport::SetXmlId: cannot set xml:id");
2043                 }
2044             }
2045         } catch (uno::Exception &) {
2046             OSL_ENSURE(false, "SvXMLImport::SetXmlId: exception?");
2047         }
2048     }
2049 }
2050 
2051 SAL_DLLPRIVATE ::xmloff::RDFaImportHelper &
2052 SvXMLImport::GetRDFaImportHelper()
2053 {
2054     if (!mpImpl->mpRDFaHelper.get())
2055     {
2056         mpImpl->mpRDFaHelper.reset( new ::xmloff::RDFaImportHelper(*this) );
2057     }
2058     return *mpImpl->mpRDFaHelper;
2059 }
2060 
2061 void
2062 SvXMLImport::AddRDFa(uno::Reference<rdf::XMetadatable> i_xObject,
2063     ::rtl::OUString const & i_rAbout,
2064     ::rtl::OUString const & i_rProperty,
2065     ::rtl::OUString const & i_rContent,
2066     ::rtl::OUString const & i_rDatatype)
2067 {
2068     // N.B.: we only get called if i_xObject had xhtml:about attribute
2069     // (an empty attribute value is valid)
2070     ::xmloff::RDFaImportHelper & rRDFaHelper( GetRDFaImportHelper() );
2071     rRDFaHelper.ParseAndAddRDFa(i_xObject,
2072         i_rAbout, i_rProperty, i_rContent, i_rDatatype);
2073 }
2074 
2075