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