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