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