LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/xml - xmlxtimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 170 199 85.4 %
Date: 2013-07-09 Functions: 18 18 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/urlobj.hxx>
      21             : #include <com/sun/star/document/XGraphicObjectResolver.hpp>
      22             : #include <com/sun/star/embed/ElementModes.hpp>
      23             : #include <com/sun/star/io/XActiveDataControl.hpp>
      24             : #include <com/sun/star/io/XActiveDataSource.hpp>
      25             : #include <com/sun/star/xml/sax/Parser.hpp>
      26             : #include <com/sun/star/container/XNameContainer.hpp>
      27             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      28             : #include <com/sun/star/uno/Sequence.hxx>
      29             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      30             : #include <com/sun/star/drawing/LineDash.hpp>
      31             : #include <com/sun/star/awt/Gradient.hpp>
      32             : #include <com/sun/star/drawing/Hatch.hpp>
      33             : #include <com/sun/star/io/XOutputStream.hpp>
      34             : #include <com/sun/star/io/XSeekable.hpp>
      35             : #include <comphelper/processfactory.hxx>
      36             : #include <comphelper/storagehelper.hxx>
      37             : #include <unotools/streamwrap.hxx>
      38             : #include <rtl/ustrbuf.hxx>
      39             : #include <sax/tools/converter.hxx>
      40             : #include <sfx2/docfile.hxx>
      41             : #include "xmloff/xmlnmspe.hxx"
      42             : #include "xmloff/nmspmap.hxx"
      43             : 
      44             : #include "xmloff/xmltoken.hxx"
      45             : #include "xmloff/xmlmetae.hxx"
      46             : #include "xmloff/DashStyle.hxx"
      47             : #include "xmloff/GradientStyle.hxx"
      48             : #include "xmloff/HatchStyle.hxx"
      49             : #include "xmloff/ImageStyle.hxx"
      50             : #include "xmloff/MarkerStyle.hxx"
      51             : #include <xmloff/xmlictxt.hxx>
      52             : #include "svx/xmlgrhlp.hxx"
      53             : #include "xmloff/attrlist.hxx"
      54             : 
      55             : #include "xmlxtimp.hxx"
      56             : 
      57             : #include <cstdio>
      58             : 
      59             : using namespace com::sun::star;
      60             : using namespace com::sun::star::container;
      61             : using namespace com::sun::star::document;
      62             : using namespace com::sun::star::uno;
      63             : using namespace com::sun::star::awt;
      64             : using namespace com::sun::star::lang;
      65             : using namespace com::sun::star::xml::sax;
      66             : using namespace ::rtl;
      67             : using namespace ::xmloff::token;
      68             : using namespace cppu;
      69             : 
      70             : sal_Char const sXML_np__office[] = "__office";
      71             : sal_Char const sXML_np__office_ooo[] = "___office";
      72             : sal_Char const sXML_np__draw[] = "__draw";
      73             : sal_Char const sXML_np__draw_ooo[] = "___draw";
      74             : sal_Char const sXML_np__ooo[] = "__ooo";
      75             : sal_Char const sXML_np__xlink[] = "__xlink";
      76             : 
      77             : ///////////////////////////////////////////////////////////////////////
      78             : 
      79             : enum SvxXMLTableImportContextEnum { stice_unknown, stice_color, stice_marker, stice_dash, stice_hatch, stice_gradient, stice_bitmap };
      80             : 
      81             : ///////////////////////////////////////////////////////////////////////
      82             : 
      83             : class SvxXMLTableImportContext : public SvXMLImportContext
      84             : {
      85             : public:
      86             :     SvxXMLTableImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >& xAttrList, SvxXMLTableImportContextEnum eContext, const uno::Reference< XNameContainer >& xTable,
      87             :         bool bOOoFormat );
      88             :     virtual ~SvxXMLTableImportContext();
      89             : 
      90             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList );
      91             : 
      92             :     SvxXMLXTableImport& getImport() const { return *(SvxXMLXTableImport*)&GetImport(); }
      93             : 
      94             : protected:
      95             :     void importColor( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName );
      96             :     void importMarker( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName );
      97             :     void importDash( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName );
      98             :     void importHatch( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName );
      99             :     void importGradient( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName );
     100             :     void importBitmap( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName );
     101             : 
     102             : private:
     103             :     uno::Reference< XNameContainer > mxTable;
     104             :     SvxXMLTableImportContextEnum meContext;
     105             :     bool mbOOoFormat;
     106             : };
     107             : 
     108             : ///////////////////////////////////////////////////////////////////////
     109             : 
     110         143 : SvxXMLTableImportContext::SvxXMLTableImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference< XAttributeList >&, SvxXMLTableImportContextEnum eContext, const uno::Reference< XNameContainer >& xTable, bool bOOoFormat )
     111             : : SvXMLImportContext( rImport, nPrfx, rLName ), mxTable( xTable ), meContext( eContext ),
     112         143 :     mbOOoFormat( bOOoFormat )
     113             : {
     114         143 : }
     115             : 
     116         286 : SvxXMLTableImportContext::~SvxXMLTableImportContext()
     117             : {
     118         286 : }
     119             : 
     120       11601 : SvXMLImportContext *SvxXMLTableImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& rAttrList )
     121             : {
     122       11601 :     if( XML_NAMESPACE_DRAW == nPrefix )
     123             :     {
     124       11601 :         uno::Reference< XAttributeList > xAttrList( rAttrList );
     125       23118 :         if( mbOOoFormat &&
     126       33125 :              (stice_dash == meContext || stice_hatch == meContext ||
     127       10784 :              stice_bitmap == meContext) )
     128             :         {
     129         733 :             SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList );
     130         733 :             xAttrList = pAttrList;
     131         733 :             sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     132        4839 :             for( sal_Int16 i=0; i < nAttrCount; i++ )
     133             :             {
     134        4106 :                 const OUString& rAttrName = xAttrList->getNameByIndex( i );
     135        8212 :                 OUString aLocalName;
     136             :                 sal_uInt16 nPrefix_ =
     137        4106 :                     GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     138        4106 :                                                                 &aLocalName );
     139        4106 :                 if( XML_NAMESPACE_XLINK == nPrefix_ &&
     140        4106 :                     stice_bitmap == meContext &&
     141           0 :                     IsXMLToken( aLocalName, XML_HREF ) )
     142             :                 {
     143           0 :                     const OUString rValue = xAttrList->getValueByIndex( i );
     144           0 :                     if( !rValue.isEmpty() && '#' == rValue[0] )
     145           0 :                         pAttrList->SetValueByIndex( i, rValue.copy( 1 ) );
     146             :                 }
     147        9701 :                 else if( XML_NAMESPACE_DRAW == nPrefix_ &&
     148        8012 :                           ( ( stice_dash == meContext &&
     149        7308 :                               (IsXMLToken( aLocalName, XML_DOTS1_LENGTH ) ||
     150        6552 :                                IsXMLToken( aLocalName, XML_DOTS2_LENGTH ) ||
     151        5807 :                                IsXMLToken( aLocalName, XML_DISTANCE )) ) ||
     152        2857 :                             ( stice_hatch == meContext &&
     153         200 :                               IsXMLToken( aLocalName, XML_HATCH_DISTANCE ) ) ) )
     154             :                 {
     155        1489 :                     const OUString rValue = xAttrList->getValueByIndex( i );
     156        1489 :                     sal_Int32 nPos = rValue.getLength();
     157        2978 :                     while( nPos && rValue[nPos-1] <= ' ' )
     158           0 :                         --nPos;
     159        2978 :                     if( nPos > 2 &&
     160        3900 :                         ('c'==rValue[nPos-2] || 'C'==rValue[nPos-2]) &&
     161         922 :                         ('h'==rValue[nPos-1] || 'H'==rValue[nPos-1]) )
     162             :                     {
     163         922 :                         pAttrList->SetValueByIndex( i, rValue.copy( 0, nPos-2 ) );
     164        1489 :                     }
     165             :                 }
     166        4106 :             }
     167             :         }
     168             :         try
     169             :         {
     170       11601 :             Any aAny;
     171       23202 :             OUString aName;
     172             : 
     173       11601 :             switch( meContext )
     174             :             {
     175             :             case stice_color:
     176       10560 :                 importColor( nPrefix, rLocalName, xAttrList, aAny, aName );
     177       10560 :                 break;
     178             :             case stice_marker:
     179          80 :                 importMarker( nPrefix, rLocalName, xAttrList, aAny, aName  );
     180          80 :                 break;
     181             :             case stice_dash:
     182         693 :                 importDash( nPrefix, rLocalName, xAttrList, aAny, aName  );
     183         693 :                 break;
     184             :             case stice_hatch:
     185          40 :                 importHatch( nPrefix, rLocalName, xAttrList, aAny, aName  );
     186          40 :                 break;
     187             :             case stice_gradient:
     188         144 :                 importGradient( nPrefix, rLocalName, xAttrList, aAny, aName  );
     189         144 :                 break;
     190             :             case stice_bitmap:
     191          84 :                 importBitmap( nPrefix, rLocalName, xAttrList, aAny, aName  );
     192          84 :                 break;
     193             :             case stice_unknown:
     194           0 :                 break;
     195             :             }
     196             : 
     197       11601 :             if( !aName.isEmpty() && aAny.hasValue() )
     198             :             {
     199       11601 :                 if( mxTable->hasByName( aName ) )
     200             :                 {
     201           0 :                     mxTable->replaceByName( aName, aAny );
     202             :                 }
     203             :                 else
     204             :                 {
     205       11601 :                     mxTable->insertByName( aName, aAny );
     206             :                 }
     207       11601 :             }
     208             :         }
     209           0 :         catch (const uno::Exception&)
     210             :         {
     211       11601 :         }
     212             :     }
     213             : 
     214       11601 :     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     215             : }
     216             : 
     217       10560 : void SvxXMLTableImportContext::importColor( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName )
     218             : {
     219             :     (void)nPrfx;
     220             :     (void)rLocalName;
     221             : 
     222       10560 :     const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     223       31680 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     224             :     {
     225       21120 :         const OUString& rFullAttrName = xAttrList->getNameByIndex( i );
     226       42240 :         OUString aLocalName;
     227       21120 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aLocalName );
     228             : 
     229             : 
     230       21120 :         if( XML_NAMESPACE_DRAW == nPrefix )
     231             :         {
     232       21120 :             if( aLocalName == GetXMLToken(XML_NAME) )
     233             :             {
     234       10560 :                 rName = xAttrList->getValueByIndex( i );
     235             :             }
     236       10560 :             else if( aLocalName == GetXMLToken(XML_COLOR) )
     237             :             {
     238       10560 :                 sal_Int32 nColor(0);
     239             :                 ::sax::Converter::convertColor(nColor,
     240       10560 :                         xAttrList->getValueByIndex( i ));
     241       10560 :                 rAny <<= nColor;
     242             :             }
     243             :         }
     244       21120 :     }
     245       10560 : }
     246             : 
     247          80 : void SvxXMLTableImportContext::importMarker( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName )
     248             : {
     249             :     (void)nPrfx;
     250             :     (void)rLocalName;
     251             : 
     252             :     try
     253             :     {
     254          80 :         XMLMarkerStyleImport aMarkerStyle( GetImport() );
     255          80 :         aMarkerStyle.importXML( xAttrList, rAny, rName );
     256             :     }
     257           0 :     catch (const Exception&)
     258             :     {
     259             :         OSL_FAIL("SvxXMLTableImportContext::importMarker(), exception caught!");
     260             :     }
     261          80 : }
     262             : 
     263         693 : void SvxXMLTableImportContext::importDash( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName )
     264             : {
     265             :     (void)nPrfx;
     266             :     (void)rLocalName;
     267             : 
     268             :     try
     269             :     {
     270         693 :         XMLDashStyleImport aDashStyle( GetImport() );
     271         693 :         aDashStyle.importXML( xAttrList, rAny, rName );
     272             :     }
     273           0 :     catch (const Exception&)
     274             :     {
     275             :         OSL_FAIL("SvxXMLTableImportContext::importDash(), exception caught!");
     276             :     }
     277         693 : }
     278             : 
     279          40 : void SvxXMLTableImportContext::importHatch( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName )
     280             : {
     281             :     (void)nPrfx;
     282             :     (void)rLocalName;
     283             : 
     284             :     try
     285             :     {
     286          40 :         XMLHatchStyleImport aHatchStyle( GetImport() );
     287          40 :         aHatchStyle.importXML( xAttrList, rAny, rName );
     288             :     }
     289           0 :     catch (const Exception&)
     290             :     {
     291             :         OSL_FAIL("SvxXMLTableImportContext::importHatch(), exception caught!");
     292             :     }
     293          40 : }
     294             : 
     295         144 : void SvxXMLTableImportContext::importGradient( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName )
     296             : {
     297             :     (void)nPrfx;
     298             :     (void)rLocalName;
     299             : 
     300             :     try
     301             :     {
     302         144 :         XMLGradientStyleImport aGradientStyle( GetImport() );
     303         144 :         aGradientStyle.importXML( xAttrList, rAny, rName );
     304             :     }
     305           0 :     catch (const Exception&)
     306             :     {
     307             :         OSL_FAIL("SvxXMLTableImportContext::importGradient(), exception caught!");
     308             :     }
     309         144 : }
     310             : 
     311          84 : void SvxXMLTableImportContext::importBitmap( sal_uInt16 nPrfx, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList, Any& rAny, OUString& rName )
     312             : {
     313             :     (void)nPrfx;
     314             :     (void)rLocalName;
     315             : 
     316             :     try
     317             :     {
     318          84 :         XMLImageStyle aImageStyle;
     319          84 :         aImageStyle.importXML( xAttrList, rAny, rName, GetImport() );
     320             :     }
     321           0 :     catch (const Exception&)
     322             :     {
     323             :         OSL_FAIL("SvxXMLTableImportContext::importBitmap(), exception caught!");
     324             :     }
     325          84 : }
     326             : 
     327             : ///////////////////////////////////////////////////////////////////////
     328             : 
     329             : // #110680#
     330         175 : SvxXMLXTableImport::SvxXMLXTableImport(
     331             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
     332             :     const uno::Reference< XNameContainer > & rTable,
     333             :     uno::Reference< XGraphicObjectResolver >& xGrfResolver )
     334             : :   SvXMLImport(xContext, 0),
     335         175 :     mrTable( rTable )
     336             : {
     337         175 :     SetGraphicResolver( xGrfResolver );
     338             : 
     339         175 :     GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__ooo ) ), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
     340         175 :     GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office ) ), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
     341         175 :     GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw ) ), GetXMLToken(XML_N_DRAW), XML_NAMESPACE_DRAW );
     342         175 :     GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__xlink ) ), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
     343             : 
     344             :     // OOo namespaces for reading OOo 1.1 files
     345         350 :     GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__office_ooo ) ),
     346         175 :                         GetXMLToken(XML_N_OFFICE_OOO),
     347         350 :                         XML_NAMESPACE_OFFICE );
     348         350 :     GetNamespaceMap().Add( OUString( RTL_CONSTASCII_USTRINGPARAM ( sXML_np__draw_ooo ) ),
     349         175 :                         GetXMLToken(XML_N_DRAW_OOO),
     350         350 :                         XML_NAMESPACE_DRAW );
     351         175 : }
     352             : 
     353         350 : SvxXMLXTableImport::~SvxXMLXTableImport() throw ()
     354             : {
     355         350 : }
     356             : 
     357           4 : static void openStorageStream( xml::sax::InputSource *pParserInput,
     358             :                                SvXMLGraphicHelper   **ppGraphicHelper,
     359             :                                uno::Reference < embed::XStorage > xStorage )
     360             : {
     361           4 :     uno::Reference < io::XStream > xIStm;
     362           8 :     const String aContentStmName( RTL_CONSTASCII_USTRINGPARAM( "Content.xml" ) );
     363           4 :     xIStm.set( xStorage->openStreamElement( aContentStmName, embed::ElementModes::READ ), uno::UNO_QUERY_THROW );
     364           4 :     if( !xIStm.is() )
     365             :     {
     366             :         OSL_FAIL( "could not open Content stream" );
     367           4 :         return;
     368             :     }
     369           4 :     pParserInput->aInputStream = xIStm->getInputStream();
     370           8 :     *ppGraphicHelper = SvXMLGraphicHelper::Create( xStorage, GRAPHICHELPER_MODE_READ );
     371             : }
     372             : 
     373         175 : bool SvxXMLXTableImport::load( const OUString &rPath,
     374             :                                const uno::Reference < embed::XStorage > &xStorage,
     375             :                                const uno::Reference< XNameContainer >& xTable,
     376             :                                bool *bOptLoadedFromStorage ) throw()
     377             : {
     378         175 :     bool bRet = true;
     379         175 :     SvXMLGraphicHelper* pGraphicHelper = 0;
     380             : 
     381         175 :     INetURLObject aURLObj( rPath );
     382         175 :     bool bUseStorage = aURLObj.GetProtocol() == INET_PROT_NOT_VALID; // a relative path
     383             : 
     384             :     try
     385             :     {
     386         175 :         uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
     387             : 
     388         350 :         uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
     389             : 
     390         350 :         xml::sax::InputSource aParserInput;
     391         350 :         comphelper::LifecycleProxy aNasty;
     392             : 
     393         175 :         if( !bUseStorage || !xStorage.is() )
     394             :         {
     395         175 :             SfxMedium aMedium( rPath, STREAM_READ | STREAM_NOCREATE );
     396         175 :             aParserInput.sSystemId = aMedium.GetName();
     397             : 
     398         175 :             if( aMedium.IsStorage() )
     399             :             {
     400           4 :                 uno::Reference < embed::XStorage > xMediumStorage( aMedium.GetStorage( sal_False ), uno::UNO_QUERY_THROW );
     401           4 :                 openStorageStream( &aParserInput, &pGraphicHelper, xMediumStorage );
     402             :             }
     403             :             else
     404         171 :                 aParserInput.aInputStream = aMedium.GetInputStream();
     405             :         }
     406             :         else // relative URL into a storage
     407             :         {
     408           0 :             uno::Reference< embed::XStorage > xSubStorage;
     409             :             try
     410             :             {
     411           0 :                 xSubStorage = comphelper::OStorageHelper::GetStorageAtPath(
     412           0 :                         xStorage, rPath, embed::ElementModes::READ, aNasty );
     413             :             }
     414           0 :             catch (const uno::Exception&)
     415             :             {
     416             :             }
     417           0 :             if( xSubStorage.is() )
     418           0 :                 openStorageStream( &aParserInput, &pGraphicHelper, xSubStorage );
     419             :             else
     420             :             {
     421           0 :                 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream;
     422           0 :                 xStream = comphelper::OStorageHelper::GetStreamAtPath(
     423           0 :                         xStorage, rPath, embed::ElementModes::READ, aNasty );
     424           0 :                 if( !xStream.is() )
     425           0 :                     return false;
     426           0 :                 aParserInput.aInputStream = xStream->getInputStream();
     427             :             }
     428           0 :             if( bOptLoadedFromStorage )
     429           0 :                 *bOptLoadedFromStorage = true;
     430             :         }
     431             : 
     432         350 :         uno::Reference< XGraphicObjectResolver > xGrfResolver;
     433         175 :         if (pGraphicHelper)
     434           4 :             xGrfResolver = pGraphicHelper;
     435             : 
     436             :         try
     437             :         {
     438         175 :             uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW );
     439         139 :             xSeek->seek( 0 );
     440             :         }
     441          36 :         catch (const uno::Exception&)
     442             :         {
     443             :         }
     444             : 
     445         318 :         uno::Reference< XDocumentHandler > xHandler( new SvxXMLXTableImport( xContext, xTable, xGrfResolver ) );
     446         175 :         xParser->setDocumentHandler( xHandler );
     447         175 :         xParser->parseStream( aParserInput );
     448             : 
     449         143 :         if( pGraphicHelper )
     450         179 :             SvXMLGraphicHelper::Destroy( pGraphicHelper );
     451             :     }
     452          64 :     catch (const uno::Exception&)
     453             :     {
     454             : //      thrown each time you load a document with property tables that are not
     455             : //      on the current machine. FIXME: would be better to check a file exists
     456             : //      before importing ...
     457             : //        fprintf (stderr, "parsing etc. exception '%s'\n",
     458             : //                 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
     459          32 :         bRet = false;
     460             :     }
     461             : 
     462         175 :     return bRet;
     463             : }
     464             : 
     465         143 : SvXMLImportContext *SvxXMLXTableImport::CreateContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< XAttributeList >& xAttrList )
     466             : {
     467         143 :     if( XML_NAMESPACE_OOO == nPrefix ||
     468             :         XML_NAMESPACE_OFFICE == nPrefix )
     469             :     {
     470         143 :         bool bOOoFormat = (XML_NAMESPACE_OFFICE == nPrefix);
     471         143 :         Type aType = mrTable->getElementType();
     472             : 
     473         143 :         if ( rLocalName == "color-table" )
     474             :         {
     475          64 :             if( aType == ::getCppuType((const sal_Int32*)0) )
     476          64 :                 return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_color, mrTable, bOOoFormat );
     477             :         }
     478          79 :         else if ( rLocalName == "marker-table" )
     479             :         {
     480           4 :             if( aType == ::getCppuType((const drawing::PolyPolygonBezierCoords*)0) )
     481           4 :                 return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_marker, mrTable, bOOoFormat );
     482             :         }
     483          75 :         else if ( rLocalName == "dash-table" )
     484             :         {
     485          63 :             if( aType == ::getCppuType((const drawing::LineDash*)0) )
     486          63 :                 return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_dash, mrTable, bOOoFormat );
     487             :         }
     488          12 :         else if ( rLocalName == "hatch-table" )
     489             :         {
     490           4 :             if( aType == ::getCppuType((const drawing::Hatch*)0) )
     491           4 :                 return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_hatch, mrTable, bOOoFormat );
     492             :         }
     493           8 :         else if ( rLocalName == "gradient-table" )
     494             :         {
     495           4 :             if( aType == ::getCppuType((const awt::Gradient*)0))
     496           4 :                 return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_gradient, mrTable, bOOoFormat );
     497             :         }
     498           4 :         else if ( rLocalName == "bitmap-table" )
     499             :         {
     500           4 :             if( aType == ::getCppuType((const OUString*)0))
     501           4 :                 return new SvxXMLTableImportContext( *this, nPrefix, rLocalName, xAttrList, stice_bitmap, mrTable, bOOoFormat );
     502           0 :         }
     503             :     }
     504             : 
     505           0 :     return new SvXMLImportContext( *this, nPrefix, rLocalName );
     506         258 : }
     507             : 
     508             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10