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