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