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

Generated by: LCOV version 1.10