LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/core - xmlimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 593 827 71.7 %
Date: 2012-12-17 Functions: 65 104 62.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10