LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/core - xmlimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 688 858 80.2 %
Date: 2013-07-09 Functions: 78 107 72.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10