LCOV - code coverage report
Current view: top level - svx/source/xml - xmlxtimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 167 193 86.5 %
Date: 2012-08-25 Functions: 16 16 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 236 488 48.4 %

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

Generated by: LCOV version 1.10