LCOV - code coverage report
Current view: top level - xmloff/source/core - XMLEmbeddedObjectImportContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 119 0.0 %
Date: 2012-08-25 Functions: 0 25 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 241 0.0 %

           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 <com/sun/star/document/XImporter.hpp>
      30                 :            : #include <com/sun/star/util/XModifiable.hpp>
      31                 :            : #include <com/sun/star/util/XModifiable2.hpp>
      32                 :            : #include <com/sun/star/frame/XStorable.hpp>
      33                 :            : #include <tools/globname.hxx>
      34                 :            : #include <sot/clsids.hxx>
      35                 :            : #include <xmloff/nmspmap.hxx>
      36                 :            : #include <xmloff/xmlimp.hxx>
      37                 :            : #include "xmloff/xmlnmspe.hxx"
      38                 :            : #include <xmloff/xmltoken.hxx>
      39                 :            : #include "xmloff/xmlerror.hxx"
      40                 :            : #include <xmloff/attrlist.hxx>
      41                 :            : #include "xmloff/XMLFilterServiceNames.h"
      42                 :            : #include "XMLEmbeddedObjectImportContext.hxx"
      43                 :            : 
      44                 :            : using ::rtl::OUString;
      45                 :            : using ::rtl::OUStringBuffer;
      46                 :            : 
      47                 :            : using namespace ::com::sun::star::uno;
      48                 :            : using namespace ::com::sun::star::util;
      49                 :            : using namespace ::com::sun::star::beans;
      50                 :            : using namespace ::com::sun::star::lang;
      51                 :            : using namespace ::com::sun::star::frame;
      52                 :            : using namespace ::com::sun::star::document;
      53                 :            : using namespace ::com::sun::star::xml::sax;
      54                 :            : using namespace ::xmloff::token;
      55                 :            : 
      56                 :            : struct XMLServiceMapEntry_Impl
      57                 :            : {
      58                 :            :     enum XMLTokenEnum eClass;
      59                 :            :     const sal_Char *sFilterService;
      60                 :            :     sal_Int32      nFilterServiceLen;
      61                 :            : };
      62                 :            : 
      63                 :            : #define SERVICE_MAP_ENTRY( cls, app ) \
      64                 :            :     { XML_##cls, \
      65                 :            :       XML_IMPORT_FILTER_##app, sizeof(XML_IMPORT_FILTER_##app)-1}
      66                 :            : 
      67                 :            : const XMLServiceMapEntry_Impl aServiceMap[] =
      68                 :            : {
      69                 :            :     SERVICE_MAP_ENTRY( TEXT, WRITER ),
      70                 :            :     SERVICE_MAP_ENTRY( ONLINE_TEXT, WRITER ),
      71                 :            :     SERVICE_MAP_ENTRY( SPREADSHEET, CALC ),
      72                 :            :     SERVICE_MAP_ENTRY( DRAWING, DRAW ),
      73                 :            :     SERVICE_MAP_ENTRY( GRAPHICS, DRAW ),
      74                 :            :     SERVICE_MAP_ENTRY( PRESENTATION, IMPRESS ),
      75                 :            :     SERVICE_MAP_ENTRY( CHART, CHART ),
      76                 :            :     { XML_TOKEN_INVALID, 0, 0 }
      77                 :            : };
      78                 :            : 
      79                 :            : class XMLEmbeddedObjectImportContext_Impl : public SvXMLImportContext
      80                 :            : {
      81                 :            :     ::com::sun::star::uno::Reference<
      82                 :            :         ::com::sun::star::xml::sax::XDocumentHandler > xHandler;
      83                 :            : 
      84                 :            : public:
      85                 :            :     TYPEINFO();
      86                 :            : 
      87                 :            :     XMLEmbeddedObjectImportContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
      88                 :            :                                     const ::rtl::OUString& rLName,
      89                 :            :     const ::com::sun::star::uno::Reference<
      90                 :            :         ::com::sun::star::xml::sax::XDocumentHandler >& rHandler );
      91                 :            : 
      92                 :            :     virtual ~XMLEmbeddedObjectImportContext_Impl();
      93                 :            : 
      94                 :            :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
      95                 :            :                                    const ::rtl::OUString& rLocalName,
      96                 :            :                                    const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
      97                 :            : 
      98                 :            :     virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
      99                 :            : 
     100                 :            :     virtual void EndElement();
     101                 :            : 
     102                 :            :     virtual void Characters( const ::rtl::OUString& rChars );
     103                 :            : };
     104                 :            : 
     105 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLEmbeddedObjectImportContext_Impl, SvXMLImportContext );
     106                 :            : 
     107                 :          0 : XMLEmbeddedObjectImportContext_Impl::XMLEmbeddedObjectImportContext_Impl(
     108                 :            :         SvXMLImport& rImport, sal_uInt16 nPrfx,
     109                 :            :         const OUString& rLName,
     110                 :            :         const Reference< XDocumentHandler >& rHandler ) :
     111                 :            :     SvXMLImportContext( rImport, nPrfx, rLName ),
     112                 :          0 :     xHandler( rHandler )
     113                 :            : {
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : XMLEmbeddedObjectImportContext_Impl::~XMLEmbeddedObjectImportContext_Impl()
     117                 :            : {
     118         [ #  # ]:          0 : }
     119                 :            : 
     120                 :          0 : SvXMLImportContext *XMLEmbeddedObjectImportContext_Impl::CreateChildContext(
     121                 :            :         sal_uInt16 nPrefix,
     122                 :            :         const OUString& rLocalName,
     123                 :            :         const Reference< XAttributeList >& )
     124                 :            : {
     125                 :          0 :     return new XMLEmbeddedObjectImportContext_Impl( GetImport(),
     126                 :            :                                                     nPrefix, rLocalName,
     127         [ #  # ]:          0 :                                                     xHandler );
     128                 :            : }
     129                 :            : 
     130                 :          0 : void XMLEmbeddedObjectImportContext_Impl::StartElement(
     131                 :            :         const Reference< XAttributeList >& xAttrList )
     132                 :            : {
     133                 :          0 :     xHandler->startElement( GetImport().GetNamespaceMap().GetQNameByKey(
     134                 :          0 :                                 GetPrefix(), GetLocalName() ),
     135         [ #  # ]:          0 :                             xAttrList );
     136                 :          0 : }
     137                 :            : 
     138                 :          0 : void XMLEmbeddedObjectImportContext_Impl::EndElement()
     139                 :            : {
     140                 :          0 :     xHandler->endElement( GetImport().GetNamespaceMap().GetQNameByKey(
     141         [ #  # ]:          0 :                                 GetPrefix(), GetLocalName() ) );
     142                 :          0 : }
     143                 :            : 
     144                 :          0 : void XMLEmbeddedObjectImportContext_Impl::Characters( const OUString& rChars )
     145                 :            : {
     146                 :          0 :     xHandler->characters( rChars );
     147                 :          0 : }
     148                 :            : 
     149                 :            : //-----------------------------------------------------------------------------
     150                 :            : 
     151 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLEmbeddedObjectImportContext, SvXMLImportContext );
     152                 :            : 
     153                 :          0 : sal_Bool XMLEmbeddedObjectImportContext::SetComponent(
     154                 :            :         Reference< XComponent >& rComp )
     155                 :            : {
     156 [ #  # ][ #  # ]:          0 :     if( !rComp.is() || sFilterService.isEmpty() )
                 [ #  # ]
     157                 :          0 :         return sal_False;
     158                 :            : 
     159                 :            : 
     160         [ #  # ]:          0 :     Sequence<Any> aArgs( 0 );
     161                 :            : 
     162         [ #  # ]:          0 :     Reference< XMultiServiceFactory > xServiceFactory = GetImport().getServiceFactory();
     163                 :            : 
     164                 :            :     xHandler = Reference < XDocumentHandler >(
     165         [ #  # ]:          0 :         xServiceFactory->createInstanceWithArguments( sFilterService, aArgs),
     166 [ #  # ][ #  # ]:          0 :                                                UNO_QUERY);
                 [ #  # ]
     167                 :            : 
     168         [ #  # ]:          0 :     if( !xHandler.is() )
     169                 :          0 :         return sal_False;
     170                 :            : 
     171                 :            :     try
     172                 :            :     {
     173         [ #  # ]:          0 :         Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY_THROW );
     174 [ #  # ][ #  # ]:          0 :         xModifiable2->disableSetModified();
                 [ #  # ]
     175                 :            :     }
     176         [ #  # ]:          0 :     catch( Exception& )
     177                 :            :     {
     178                 :            :     }
     179                 :            : 
     180         [ #  # ]:          0 :     Reference < XImporter > xImporter( xHandler, UNO_QUERY );
     181 [ #  # ][ #  # ]:          0 :     xImporter->setTargetDocument( rComp );
     182                 :            : 
     183         [ #  # ]:          0 :     xComp = rComp;  // keep ref to component only if there is a handler
     184                 :            : 
     185         [ #  # ]:          0 :     return sal_True;
     186                 :            : }
     187                 :            : 
     188                 :          0 : XMLEmbeddedObjectImportContext::XMLEmbeddedObjectImportContext(
     189                 :            :         SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
     190                 :            :         const Reference< XAttributeList >& xAttrList ) :
     191                 :          0 :     SvXMLImportContext( rImport, nPrfx, rLName )
     192                 :            : {
     193         [ #  # ]:          0 :     SvGlobalName aName;
     194                 :            : 
     195 [ #  # ][ #  # ]:          0 :     if( nPrfx == XML_NAMESPACE_MATH &&
                 [ #  # ]
     196         [ #  # ]:          0 :         IsXMLToken( rLName, XML_MATH ) )
     197                 :            :     {
     198         [ #  # ]:          0 :         sFilterService = OUString( RTL_CONSTASCII_USTRINGPARAM(XML_IMPORT_FILTER_MATH) );
     199 [ #  # ][ #  # ]:          0 :         aName = SvGlobalName(SO3_SM_CLASSID);
                 [ #  # ]
     200                 :            :     }
     201 [ #  # ][ #  # ]:          0 :     else if( nPrfx == XML_NAMESPACE_OFFICE &&
                 [ #  # ]
     202         [ #  # ]:          0 :         IsXMLToken( rLName, XML_DOCUMENT ) )
     203                 :            :     {
     204                 :          0 :         OUString sMime;
     205                 :            : 
     206 [ #  # ][ #  # ]:          0 :         sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
                 [ #  # ]
     207         [ #  # ]:          0 :         for( sal_Int16 i=0; i < nAttrCount; i++ )
     208                 :            :         {
     209 [ #  # ][ #  # ]:          0 :             const OUString& rAttrName = xAttrList->getNameByIndex( i );
     210                 :          0 :             OUString aLocalName;
     211         [ #  # ]:          0 :             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
     212 [ #  # ][ #  # ]:          0 :             if( nPrefix == XML_NAMESPACE_OFFICE &&
                 [ #  # ]
     213         [ #  # ]:          0 :                 IsXMLToken( aLocalName, XML_MIMETYPE ) )
     214                 :            :             {
     215 [ #  # ][ #  # ]:          0 :                 sMime = xAttrList->getValueByIndex( i );
     216                 :            :                 break;
     217                 :            :             }
     218 [ #  # ][ #  # ]:          0 :         }
     219                 :            : 
     220                 :          0 :         OUString sClass;
     221                 :            :         static const char * aTmp[] =
     222                 :            :         {
     223                 :            :             "application/vnd.oasis.openoffice.",
     224                 :            :             "application/x-vnd.oasis.openoffice.",
     225                 :            :             "application/vnd.oasis.opendocument.",
     226                 :            :             "application/x-vnd.oasis.opendocument.",
     227                 :            :             NULL
     228                 :            :         };
     229         [ #  # ]:          0 :         for (int k=0; aTmp[k]; k++)
     230                 :            :         {
     231                 :          0 :             ::rtl::OUString sTmpString = ::rtl::OUString::createFromAscii(aTmp[k]);
     232         [ #  # ]:          0 :             if( sMime.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
     233                 :            :             {
     234                 :          0 :                 sClass = sMime.copy( sTmpString.getLength() );
     235                 :            :                 break;
     236                 :            :             }
     237         [ #  # ]:          0 :         }
     238                 :            : 
     239         [ #  # ]:          0 :         if( !sClass.isEmpty() )
     240                 :            :         {
     241                 :          0 :             const XMLServiceMapEntry_Impl *pEntry = aServiceMap;
     242         [ #  # ]:          0 :             while( pEntry->eClass != XML_TOKEN_INVALID )
     243                 :            :             {
     244 [ #  # ][ #  # ]:          0 :                 if( IsXMLToken( sClass, pEntry->eClass ) )
     245                 :            :                 {
     246                 :            :                     sFilterService = OUString( pEntry->sFilterService,
     247                 :            :                                                pEntry->nFilterServiceLen,
     248         [ #  # ]:          0 :                                                RTL_TEXTENCODING_ASCII_US );
     249                 :            : 
     250   [ #  #  #  #  :          0 :                     switch( pEntry->eClass )
                #  #  # ]
     251                 :            :                     {
     252 [ #  # ][ #  # ]:          0 :                     case XML_TEXT:          aName = SvGlobalName(SO3_SW_CLASSID); break;
                 [ #  # ]
     253 [ #  # ][ #  # ]:          0 :                     case XML_ONLINE_TEXT:   aName = SvGlobalName(SO3_SWWEB_CLASSID); break;
                 [ #  # ]
     254 [ #  # ][ #  # ]:          0 :                     case XML_SPREADSHEET:   aName = SvGlobalName(SO3_SC_CLASSID); break;
                 [ #  # ]
     255                 :            :                     case XML_DRAWING:
     256                 :            :                     case XML_GRAPHICS:
     257 [ #  # ][ #  # ]:          0 :                     case XML_IMAGE:     aName = SvGlobalName(SO3_SDRAW_CLASSID); break;
                 [ #  # ]
     258 [ #  # ][ #  # ]:          0 :                     case XML_PRESENTATION:  aName = SvGlobalName(SO3_SIMPRESS_CLASSID); break;
                 [ #  # ]
     259 [ #  # ][ #  # ]:          0 :                     case XML_CHART:         aName = SvGlobalName(SO3_SCH_CLASSID); break;
                 [ #  # ]
     260                 :            :                     default:
     261                 :          0 :                         break;
     262                 :            :                     }
     263                 :            : 
     264                 :          0 :                     break;
     265                 :            :                 }
     266                 :          0 :                 pEntry++;
     267                 :            :             }
     268                 :          0 :         }
     269                 :            :     }
     270                 :            : 
     271 [ #  # ][ #  # ]:          0 :     sCLSID = aName.GetHexName();
         [ #  # ][ #  # ]
     272                 :          0 : }
     273                 :            : 
     274                 :          0 : XMLEmbeddedObjectImportContext::~XMLEmbeddedObjectImportContext()
     275                 :            : {
     276         [ #  # ]:          0 : }
     277                 :            : 
     278                 :          0 : SvXMLImportContext *XMLEmbeddedObjectImportContext::CreateChildContext(
     279                 :            :         sal_uInt16 nPrefix, const OUString& rLocalName,
     280                 :            :         const Reference< XAttributeList >& )
     281                 :            : {
     282         [ #  # ]:          0 :     if( xHandler.is() )
     283                 :          0 :         return new XMLEmbeddedObjectImportContext_Impl( GetImport(),
     284                 :            :                                                         nPrefix, rLocalName,
     285         [ #  # ]:          0 :                                                         xHandler );
     286                 :            :     else
     287         [ #  # ]:          0 :         return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     288                 :            : }
     289                 :            : 
     290                 :          0 : void XMLEmbeddedObjectImportContext::StartElement(
     291                 :            :         const Reference< XAttributeList >& rAttrList )
     292                 :            : {
     293         [ #  # ]:          0 :     if( xHandler.is() )
     294                 :            :     {
     295 [ #  # ][ #  # ]:          0 :         xHandler->startDocument();
     296                 :            :         // #i34042: copy namepspace declarations
     297         [ #  # ]:          0 :         SvXMLAttributeList *pAttrList = new SvXMLAttributeList( rAttrList );
     298 [ #  # ][ #  # ]:          0 :         Reference< XAttributeList > xAttrList( pAttrList );
     299                 :          0 :         const SvXMLNamespaceMap& rNamespaceMap = GetImport().GetNamespaceMap();
     300         [ #  # ]:          0 :         sal_uInt16 nPos = rNamespaceMap.GetFirstKey();
     301         [ #  # ]:          0 :         while( USHRT_MAX != nPos )
     302                 :            :         {
     303         [ #  # ]:          0 :             OUString aAttrName( rNamespaceMap.GetAttrNameByKey( nPos ) );
     304 [ #  # ][ #  # ]:          0 :             if( xAttrList->getValueByName( aAttrName ).isEmpty() )
                 [ #  # ]
     305                 :            :             {
     306                 :            :                 pAttrList->AddAttribute( aAttrName,
     307 [ #  # ][ #  # ]:          0 :                                           rNamespaceMap.GetNameByKey( nPos ) );
     308                 :            :             }
     309         [ #  # ]:          0 :             nPos = rNamespaceMap.GetNextKey( nPos );
     310                 :          0 :         }
     311         [ #  # ]:          0 :         xHandler->startElement( GetImport().GetNamespaceMap().GetQNameByKey(
     312                 :          0 :                                     GetPrefix(), GetLocalName() ),
     313 [ #  # ][ #  # ]:          0 :                                 xAttrList );
     314                 :            :     }
     315                 :          0 : }
     316                 :            : 
     317                 :          0 : void XMLEmbeddedObjectImportContext::EndElement()
     318                 :            : {
     319         [ #  # ]:          0 :     if( xHandler.is() )
     320                 :            :     {
     321                 :          0 :         xHandler->endElement( GetImport().GetNamespaceMap().GetQNameByKey(
     322         [ #  # ]:          0 :                                     GetPrefix(), GetLocalName() ) );
     323                 :          0 :         xHandler->endDocument();
     324                 :            : 
     325                 :            :     try
     326                 :            :     {
     327         [ #  # ]:          0 :         Reference < XModifiable2 > xModifiable2( xComp, UNO_QUERY_THROW );
     328 [ #  # ][ #  # ]:          0 :         xModifiable2->enableSetModified();
     329 [ #  # ][ #  # ]:          0 :         xModifiable2->setModified( sal_True ); // trigger new replacement image generation
                 [ #  # ]
     330                 :            :     }
     331                 :          0 :     catch( Exception& )
     332                 :            :     {
     333                 :            :     }
     334                 :            :     }
     335                 :          0 : }
     336                 :            : 
     337                 :          0 : void XMLEmbeddedObjectImportContext::Characters( const ::rtl::OUString& rChars )
     338                 :            : {
     339         [ #  # ]:          0 :     if( xHandler.is() )
     340                 :          0 :         xHandler->characters( rChars );
     341                 :          0 : }
     342                 :            : 
     343                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10