LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - OLEHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 95 28.4 %
Date: 2012-08-25 Functions: 6 8 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 30 188 16.0 %

           Branch data     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                 :            : #include <OLEHandler.hxx>
      20                 :            : #include <PropertyMap.hxx>
      21                 :            : #include "GraphicHelpers.hxx"
      22                 :            : 
      23                 :            : #include <doctok/resourceids.hxx>
      24                 :            : #include <ooxml/resourceids.hxx>
      25                 :            : #include <rtl/oustringostreaminserter.hxx>
      26                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      27                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      28                 :            : #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
      29                 :            : #include <com/sun/star/document/XStorageBasedDocument.hpp>
      30                 :            : #include <com/sun/star/drawing/XShape.hpp>
      31                 :            : #include <com/sun/star/embed/XEmbeddedObject.hpp>
      32                 :            : #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
      33                 :            : #include <com/sun/star/graphic/XGraphic.hpp>
      34                 :            : #include <com/sun/star/io/XStream.hpp>
      35                 :            : #include <com/sun/star/lang/XComponent.hpp>
      36                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      37                 :            : #include <com/sun/star/text/XTextDocument.hpp>
      38                 :            : #include <com/sun/star/uno/XComponentContext.hpp>
      39                 :            : 
      40                 :            : #include "dmapperLoggers.hxx"
      41                 :            : 
      42                 :            : namespace writerfilter {
      43                 :            : namespace dmapper {
      44                 :            : 
      45                 :            : using namespace ::com::sun::star;
      46                 :            : 
      47                 :            : 
      48                 :         42 : OLEHandler::OLEHandler() :
      49                 :            : LoggedProperties(dmapper_logger, "OLEHandler"),
      50                 :            : m_nDxaOrig(0),
      51                 :            : m_nDyaOrig(0),
      52 [ +  - ][ +  - ]:         42 :     m_nWrapMode(1)
         [ +  - ][ +  - ]
      53                 :            : {
      54                 :         42 : }
      55                 :            : 
      56                 :            : 
      57                 :         42 : OLEHandler::~OLEHandler()
      58                 :            : {
      59         [ -  + ]:         84 : }
      60                 :            : 
      61                 :            : 
      62                 :         33 : void OLEHandler::lcl_attribute(Id rName, Value & rVal)
      63                 :            : {
      64         [ +  - ]:         33 :     OUString sStringValue = rVal.getString();
      65                 :            :     (void)rName;
      66   [ -  -  -  -  :         33 :     switch( rName )
          -  -  -  -  -  
                   +  - ]
      67                 :            :     {
      68                 :            :         case NS_ooxml::LN_CT_OLEObject_Type:
      69                 :          0 :             m_sObjectType = sStringValue;
      70                 :          0 :         break;
      71                 :            :         case NS_ooxml::LN_CT_OLEObject_ProgID:
      72                 :          0 :             m_sProgId = sStringValue;
      73                 :          0 :         break;
      74                 :            :         case NS_ooxml::LN_CT_OLEObject_ShapeID:
      75                 :          0 :             m_sShapeId = sStringValue;
      76                 :          0 :         break;
      77                 :            :         case NS_ooxml::LN_CT_OLEObject_DrawAspect:
      78                 :          0 :             m_sDrawAspect = sStringValue;
      79                 :          0 :         break;
      80                 :            :         case NS_ooxml::LN_CT_OLEObject_ObjectID:
      81                 :          0 :             m_sObjectId = sStringValue;
      82                 :          0 :         break;
      83                 :            :         case NS_ooxml::LN_CT_OLEObject_r_id:
      84                 :          0 :             m_sr_id = sStringValue;
      85                 :          0 :         break;
      86                 :            :         case NS_ooxml::LN_inputstream:
      87 [ #  # ][ #  # ]:          0 :             rVal.getAny() >>= m_xInputStream;
      88                 :          0 :         break;
      89                 :            :         case NS_ooxml::LN_CT_Object_dxaOrig:
      90         [ #  # ]:          0 :             m_nDxaOrig = rVal.getInt();
      91                 :          0 :         break;
      92                 :            :         case NS_ooxml::LN_CT_Object_dyaOrig:
      93         [ #  # ]:          0 :             m_nDyaOrig = rVal.getInt();
      94                 :          0 :         break;
      95                 :            :         case NS_ooxml::LN_shape:
      96                 :            :         {
      97                 :         33 :             uno::Reference< drawing::XShape > xTempShape;
      98 [ +  - ][ +  - ]:         33 :             rVal.getAny() >>= xTempShape;
      99         [ +  - ]:         33 :             if( xTempShape.is() )
     100                 :            :             {
     101         [ +  - ]:         33 :                 m_xShape.set( xTempShape );
     102         [ +  - ]:         33 :                 uno::Reference< beans::XPropertySet > xShapeProps( xTempShape, uno::UNO_QUERY );
     103         [ +  - ]:         33 :                 PropertyNameSupplier& rNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     104                 :            : 
     105                 :            :                 try
     106                 :            :                 {
     107 [ +  - ][ +  - ]:         33 :                     m_aShapeSize = xTempShape->getSize();
     108 [ +  - ][ +  + ]:         33 :                     m_aShapePosition = xTempShape->getPosition();
     109                 :            : 
     110 [ +  - ][ +  - ]:         33 :                     xShapeProps->getPropertyValue( rNameSupplier.GetName( PROP_BITMAP ) ) >>= m_xReplacement;
         [ +  - ][ +  - ]
                 [ -  + ]
     111                 :            :                 }
     112         [ +  - ]:         12 :                 catch( const uno::Exception& e )
     113                 :            :                 {
     114                 :            :                     SAL_WARN("writerfilter", "Exception in OLE Handler: " << e.Message);
     115                 :            :                 }
     116                 :            : 
     117                 :            :                 try
     118                 :            :                 {
     119         [ +  - ]:         33 :                     xShapeProps->setPropertyValue(
     120         [ +  - ]:         33 :                         rNameSupplier.GetName( PROP_SURROUND ),
     121 [ +  - ][ +  - ]:         66 :                         uno::makeAny( m_nWrapMode ) );
                 [ #  # ]
     122                 :            :                 }
     123         [ #  # ]:          0 :                 catch( const uno::Exception& e )
     124                 :            :                 {
     125                 :            :                     SAL_WARN("writerfilter", "Exception while setting wrap mode: " << e.Message);
     126                 :         33 :                 }
     127                 :         33 :             }
     128                 :            :         }
     129                 :         33 :         break;
     130                 :            :         default:
     131                 :            :             OSL_FAIL( "unknown attribute");
     132                 :         33 :     }
     133                 :         33 : }
     134                 :            : 
     135                 :            : 
     136                 :          0 : void OLEHandler::lcl_sprm(Sprm & rSprm)
     137                 :            : {
     138                 :          0 :     sal_uInt32 nSprmId = rSprm.getId();
     139      [ #  #  # ]:          0 :     switch( nSprmId )
     140                 :            :     {
     141                 :            :         case NS_ooxml::LN_OLEObject_OLEObject:
     142                 :            :         {
     143         [ #  # ]:          0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     144         [ #  # ]:          0 :             if( pProperties.get())
     145                 :            :             {
     146         [ #  # ]:          0 :                 pProperties->resolve(*this);
     147         [ #  # ]:          0 :             }
     148                 :            :         }
     149                 :          0 :         break;
     150                 :            :         case NS_ooxml::LN_wrap_wrap:
     151                 :            :         {
     152         [ #  # ]:          0 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     153         [ #  # ]:          0 :             if ( pProperties.get( ) )
     154                 :            :             {
     155 [ #  # ][ #  # ]:          0 :                 WrapHandlerPtr pHandler( new WrapHandler );
                 [ #  # ]
     156         [ #  # ]:          0 :                 pProperties->resolve( *pHandler );
     157                 :            : 
     158         [ #  # ]:          0 :                 m_nWrapMode = pHandler->getWrapMode( );
     159                 :            : 
     160                 :            :                 try
     161                 :            :                 {
     162         [ #  # ]:          0 :                     uno::Reference< beans::XPropertySet > xShapeProps( m_xShape, uno::UNO_QUERY_THROW );
     163         [ #  # ]:          0 :                     PropertyNameSupplier& rNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     164                 :            : 
     165         [ #  # ]:          0 :                     xShapeProps->setPropertyValue(
     166         [ #  # ]:          0 :                         rNameSupplier.GetName( PROP_SURROUND ),
     167 [ #  # ][ #  # ]:          0 :                         uno::makeAny( m_nWrapMode ) );
                 [ #  # ]
     168                 :            :                 }
     169         [ #  # ]:          0 :                 catch( const uno::Exception& e )
     170                 :            :                 {
     171                 :            :                     SAL_WARN("writerfilter", "Exception in OLE Handler: " << e.Message);
     172         [ #  # ]:          0 :                 }
     173         [ #  # ]:          0 :             }
     174                 :            :         }
     175                 :          0 :         break;
     176                 :            :         default:
     177                 :            :         {
     178                 :            :             OSL_FAIL( "unknown attribute");
     179                 :            :         }
     180                 :            :     }
     181                 :          0 : }
     182                 :            : 
     183                 :            : 
     184                 :          0 : OUString OLEHandler::copyOLEOStream( uno::Reference< text::XTextDocument > xTextDocument )
     185                 :            : {
     186                 :          0 :     OUString sRet;
     187         [ #  # ]:          0 :     if( !m_xInputStream.is( ) )
     188                 :          0 :         return sRet;
     189                 :            :     try
     190                 :            :     {
     191         [ #  # ]:          0 :         uno::Reference < lang::XMultiServiceFactory > xFactory(xTextDocument, uno::UNO_QUERY_THROW);
     192                 :            :         uno::Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver(
     193 [ #  # ][ #  # ]:          0 :             xFactory->createInstance("com.sun.star.document.ImportEmbeddedObjectResolver"), uno::UNO_QUERY_THROW );
                 [ #  # ]
     194                 :            :         //hack to work with the ImportEmbeddedObjectResolver
     195                 :            :         static sal_Int32 nObjectCount = 100;
     196         [ #  # ]:          0 :         uno::Reference< container::XNameAccess > xNA( xEmbeddedResolver, uno::UNO_QUERY_THROW );
     197                 :          0 :         OUString aURL("Obj");
     198                 :          0 :         aURL += OUString::valueOf( nObjectCount++ );
     199                 :          0 :         uno::Reference < io::XOutputStream > xOLEStream;
     200 [ #  # ][ #  # ]:          0 :         if( (xNA->getByName( aURL ) >>= xOLEStream) && xOLEStream.is() )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     201                 :            :         {
     202                 :          0 :             const sal_Int32 nReadRequest = 0x1000;
     203         [ #  # ]:          0 :             uno::Sequence< sal_Int8 > aData;
     204                 :            : 
     205                 :          0 :             while( true )
     206                 :            :             {
     207 [ #  # ][ #  # ]:          0 :                 sal_Int32 nRead = m_xInputStream->readBytes( aData, nReadRequest );
     208 [ #  # ][ #  # ]:          0 :                 xOLEStream->writeBytes( aData );
     209         [ #  # ]:          0 :                 if( nRead < nReadRequest )
     210                 :            :                 {
     211 [ #  # ][ #  # ]:          0 :                     xOLEStream->closeOutput();
     212                 :          0 :                     break;
     213                 :            :                 }
     214                 :            :             }
     215                 :            : 
     216 [ #  # ][ #  # ]:          0 :             static const OUString sProtocol("vnd.sun.star.EmbeddedObject:");
     217 [ #  # ][ #  # ]:          0 :             OUString aPersistName( xEmbeddedResolver->resolveEmbeddedObjectURL( aURL ) );
     218         [ #  # ]:          0 :             sRet = aPersistName.copy( sProtocol.getLength() );
     219                 :            : 
     220                 :            :         }
     221         [ #  # ]:          0 :         uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, uno::UNO_QUERY_THROW );
     222 [ #  # ][ #  # ]:          0 :         xComp->dispose();
                 [ #  # ]
     223                 :            :     }
     224         [ #  # ]:          0 :     catch( const uno::Exception& )
     225                 :            :     {
     226                 :            :         OSL_FAIL("exception in OLEHandler::createOLEObject");
     227                 :            :     }
     228                 :          0 :     return sRet;
     229                 :            : }
     230                 :            : 
     231                 :            : } //namespace dmapper
     232 [ +  - ][ +  - ]:         60 : } //namespace writerfilter
     233                 :            : 
     234                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10