LCOV - code coverage report
Current view: top level - libreoffice/oox/source/ole - oleobjecthelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 37 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "oox/ole/oleobjecthelper.hxx"
      21             : 
      22             : #include <com/sun/star/awt/Rectangle.hpp>
      23             : #include <com/sun/star/awt/Size.hpp>
      24             : #include <com/sun/star/container/XNameAccess.hpp>
      25             : #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
      26             : #include <com/sun/star/embed/Aspects.hpp>
      27             : #include <com/sun/star/io/XOutputStream.hpp>
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include "oox/helper/propertymap.hxx"
      31             : 
      32             : namespace oox {
      33             : namespace ole {
      34             : 
      35             : // ============================================================================
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::container;
      39             : using namespace ::com::sun::star::embed;
      40             : using namespace ::com::sun::star::io;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::com::sun::star::uno;
      43             : 
      44             : using ::rtl::OUString;
      45             : 
      46             : // ============================================================================
      47             : 
      48           0 : OleObjectInfo::OleObjectInfo() :
      49             :     mbLinked( false ),
      50             :     mbShowAsIcon( false ),
      51           0 :     mbAutoUpdate( false )
      52             : {
      53           0 : }
      54             : 
      55             : // ============================================================================
      56             : 
      57           0 : OleObjectHelper::OleObjectHelper( const Reference< XMultiServiceFactory >& rxModelFactory ) :
      58             :     maEmbeddedObjScheme( CREATE_OUSTRING( "vnd.sun.star.EmbeddedObject:" ) ),
      59           0 :     mnObjectId( 100 )
      60             : {
      61           0 :     if( rxModelFactory.is() ) try
      62             :     {
      63           0 :         mxResolver.set( rxModelFactory->createInstance( CREATE_OUSTRING( "com.sun.star.document.ImportEmbeddedObjectResolver" ) ), UNO_QUERY );
      64             :     }
      65           0 :     catch(const Exception& )
      66             :     {
      67             :     }
      68           0 : }
      69             : 
      70           0 : OleObjectHelper::~OleObjectHelper()
      71             : {
      72             :     try
      73             :     {
      74           0 :         Reference< XComponent > xResolverComp( mxResolver, UNO_QUERY_THROW );
      75           0 :         xResolverComp->dispose();
      76             :     }
      77           0 :     catch(const Exception& )
      78             :     {
      79             :     }
      80           0 : }
      81             : 
      82           0 : bool OleObjectHelper::importOleObject( PropertyMap& rPropMap, const OleObjectInfo& rOleObject, const awt::Size& rObjSize )
      83             : {
      84           0 :     bool bRet = false;
      85             : 
      86           0 :     if( rOleObject.mbLinked )
      87             :     {
      88             :         // linked OLE object - set target URL
      89           0 :         if( !rOleObject.maTargetLink.isEmpty() )
      90             :         {
      91           0 :             rPropMap[ PROP_LinkURL ] <<= rOleObject.maTargetLink;
      92           0 :             bRet = true;
      93             :         }
      94             :     }
      95             :     else
      96             :     {
      97             :         // embedded OLE object - import the embedded data
      98           0 :         if( rOleObject.maEmbeddedData.hasElements() && mxResolver.is() ) try
      99             :         {
     100           0 :             OUString aObjectId = CREATE_OUSTRING( "Obj" ) + OUString::valueOf( mnObjectId++ );
     101             : 
     102           0 :             Reference< XNameAccess > xResolverNA( mxResolver, UNO_QUERY_THROW );
     103           0 :             Reference< XOutputStream > xOutStrm( xResolverNA->getByName( aObjectId ), UNO_QUERY_THROW );
     104           0 :             xOutStrm->writeBytes( rOleObject.maEmbeddedData );
     105           0 :             xOutStrm->closeOutput();
     106             : 
     107           0 :             OUString aUrl = mxResolver->resolveEmbeddedObjectURL( aObjectId );
     108             :             OSL_ENSURE( aUrl.match( maEmbeddedObjScheme ), "OleObjectHelper::importOleObject - unexpected URL scheme" );
     109           0 :             OUString aPersistName = aUrl.copy( maEmbeddedObjScheme.getLength() );
     110           0 :             if( !aPersistName.isEmpty() )
     111             :             {
     112           0 :                 rPropMap[ PROP_PersistName ] <<= aPersistName;
     113           0 :                 bRet = true;
     114           0 :             }
     115             :         }
     116           0 :         catch(const Exception& )
     117             :         {
     118             :         }
     119             :     }
     120             : 
     121           0 :     if( bRet )
     122             :     {
     123           0 :         rPropMap[ PROP_Aspect ] <<= (rOleObject.mbShowAsIcon ? Aspects::MSOLE_ICON : Aspects::MSOLE_CONTENT);
     124           0 :         rPropMap[ PROP_VisualArea ] <<= awt::Rectangle( 0, 0, rObjSize.Width, rObjSize.Height );
     125             :     }
     126           0 :     return bRet;
     127             : }
     128             : 
     129             : // ============================================================================
     130             : 
     131             : } // namespace ole
     132             : } // namespace oox
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10