LCOV - code coverage report
Current view: top level - libreoffice/writerfilter/source/dmapper - OLEHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 77 95 81.1 %
Date: 2012-12-17 Functions: 8 8 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             : #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/ustring.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          44 : OLEHandler::OLEHandler() :
      49             : LoggedProperties(dmapper_logger, "OLEHandler"),
      50             : m_nDxaOrig(0),
      51             : m_nDyaOrig(0),
      52          44 :     m_nWrapMode(1)
      53             : {
      54          44 : }
      55             : 
      56             : 
      57          88 : OLEHandler::~OLEHandler()
      58             : {
      59          88 : }
      60             : 
      61             : 
      62          56 : void OLEHandler::lcl_attribute(Id rName, Value & rVal)
      63             : {
      64          56 :     OUString sStringValue = rVal.getString();
      65             :     (void)rName;
      66          56 :     switch( rName )
      67             :     {
      68             :         case NS_ooxml::LN_CT_OLEObject_Type:
      69           2 :             m_sObjectType = sStringValue;
      70           2 :         break;
      71             :         case NS_ooxml::LN_CT_OLEObject_ProgID:
      72           2 :             m_sProgId = sStringValue;
      73           2 :         break;
      74             :         case NS_ooxml::LN_CT_OLEObject_ShapeID:
      75           2 :             m_sShapeId = sStringValue;
      76           2 :         break;
      77             :         case NS_ooxml::LN_CT_OLEObject_DrawAspect:
      78           2 :             m_sDrawAspect = sStringValue;
      79           2 :         break;
      80             :         case NS_ooxml::LN_CT_OLEObject_ObjectID:
      81           2 :             m_sObjectId = sStringValue;
      82           2 :         break;
      83             :         case NS_ooxml::LN_CT_OLEObject_r_id:
      84           2 :             m_sr_id = sStringValue;
      85           2 :         break;
      86             :         case NS_ooxml::LN_inputstream:
      87           2 :             rVal.getAny() >>= m_xInputStream;
      88           2 :         break;
      89             :         case NS_ooxml::LN_CT_Object_dxaOrig:
      90           2 :             m_nDxaOrig = rVal.getInt();
      91           2 :         break;
      92             :         case NS_ooxml::LN_CT_Object_dyaOrig:
      93           2 :             m_nDyaOrig = rVal.getInt();
      94           2 :         break;
      95             :         case NS_ooxml::LN_shape:
      96             :         {
      97          38 :             uno::Reference< drawing::XShape > xTempShape;
      98          38 :             rVal.getAny() >>= xTempShape;
      99          38 :             if( xTempShape.is() )
     100             :             {
     101          38 :                 m_xShape.set( xTempShape );
     102          38 :                 uno::Reference< beans::XPropertySet > xShapeProps( xTempShape, uno::UNO_QUERY );
     103          38 :                 PropertyNameSupplier& rNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
     104             : 
     105             :                 try
     106             :                 {
     107          38 :                     m_aShapeSize = xTempShape->getSize();
     108          38 :                     m_aShapePosition = xTempShape->getPosition();
     109             : 
     110          22 :                     xShapeProps->getPropertyValue( rNameSupplier.GetName( PROP_BITMAP ) ) >>= m_xReplacement;
     111             :                 }
     112          16 :                 catch( const uno::Exception& e )
     113             :                 {
     114             :                     SAL_WARN("writerfilter", "Exception in OLE Handler: " << e.Message);
     115             :                 }
     116             : 
     117             :                 try
     118             :                 {
     119          38 :                     xShapeProps->setPropertyValue(
     120          38 :                         rNameSupplier.GetName( PROP_SURROUND ),
     121          76 :                         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          38 :                 }
     127          38 :             }
     128             :         }
     129          38 :         break;
     130             :         default:
     131             :             OSL_FAIL( "unknown attribute");
     132          56 :     }
     133          56 : }
     134             : 
     135             : 
     136           2 : void OLEHandler::lcl_sprm(Sprm & rSprm)
     137             : {
     138           2 :     sal_uInt32 nSprmId = rSprm.getId();
     139           2 :     switch( nSprmId )
     140             :     {
     141             :         case NS_ooxml::LN_OLEObject_OLEObject:
     142             :         {
     143           2 :             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     144           2 :             if( pProperties.get())
     145             :             {
     146           2 :                 pProperties->resolve(*this);
     147           2 :             }
     148             :         }
     149           2 :         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           2 : }
     182             : 
     183             : 
     184           2 : OUString OLEHandler::copyOLEOStream( uno::Reference< text::XTextDocument > xTextDocument )
     185             : {
     186           2 :     OUString sRet;
     187           2 :     if( !m_xInputStream.is( ) )
     188           0 :         return sRet;
     189             :     try
     190             :     {
     191           2 :         uno::Reference < lang::XMultiServiceFactory > xFactory(xTextDocument, uno::UNO_QUERY_THROW);
     192             :         uno::Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver(
     193           2 :             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           2 :         uno::Reference< container::XNameAccess > xNA( xEmbeddedResolver, uno::UNO_QUERY_THROW );
     197           2 :         OUString aURL("Obj");
     198           2 :         aURL += OUString::valueOf( nObjectCount++ );
     199           2 :         uno::Reference < io::XOutputStream > xOLEStream;
     200           2 :         if( (xNA->getByName( aURL ) >>= xOLEStream) && xOLEStream.is() )
     201             :         {
     202           2 :             const sal_Int32 nReadRequest = 0x1000;
     203           2 :             uno::Sequence< sal_Int8 > aData;
     204             : 
     205           0 :             while( true )
     206             :             {
     207           2 :                 sal_Int32 nRead = m_xInputStream->readBytes( aData, nReadRequest );
     208           2 :                 xOLEStream->writeBytes( aData );
     209           2 :                 if( nRead < nReadRequest )
     210             :                 {
     211           2 :                     xOLEStream->closeOutput();
     212           2 :                     break;
     213             :                 }
     214             :             }
     215             : 
     216           2 :             static const OUString sProtocol("vnd.sun.star.EmbeddedObject:");
     217           2 :             OUString aPersistName( xEmbeddedResolver->resolveEmbeddedObjectURL( aURL ) );
     218           2 :             sRet = aPersistName.copy( sProtocol.getLength() );
     219             : 
     220             :         }
     221           2 :         uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, uno::UNO_QUERY_THROW );
     222           2 :         xComp->dispose();
     223             :     }
     224           0 :     catch( const uno::Exception& )
     225             :     {
     226             :         OSL_FAIL("exception in OLEHandler::createOLEObject");
     227             :     }
     228           2 :     return sRet;
     229             : }
     230             : 
     231             : } //namespace dmapper
     232          30 : } //namespace writerfilter
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10