LCOV - code coverage report
Current view: top level - embeddedobj/source/msole - xolefactory.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 96 0.0 %
Date: 2014-04-14 Functions: 0 11 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 <com/sun/star/embed/ElementModes.hpp>
      21             : #include <com/sun/star/embed/EntryInitModes.hpp>
      22             : #include <com/sun/star/beans/PropertyValue.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/container/XNameAccess.hpp>
      25             : #include <com/sun/star/embed/Aspects.hpp>
      26             : 
      27             : #include "xolefactory.hxx"
      28             : #include "oleembobj.hxx"
      29             : 
      30             : #include <cppuhelper/supportsservice.hxx>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : // TODO: do not create OLE objects that represent OOo documents
      35             : 
      36             : 
      37           0 : uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
      38             : {
      39           0 :     uno::Sequence< OUString > aRet(2);
      40           0 :     aRet[0] = "com.sun.star.embed.OLEEmbeddedObjectFactory";
      41           0 :     aRet[1] = "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
      42           0 :     return aRet;
      43             : }
      44             : 
      45             : 
      46           0 : OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
      47             : {
      48           0 :     return OUString("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
      49             : }
      50             : 
      51             : 
      52           0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
      53             :             const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
      54             : {
      55           0 :     return uno::Reference< uno::XInterface >( *new OleEmbeddedObjectFactory( xServiceManager ) );
      56             : }
      57             : 
      58             : 
      59           0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry(
      60             :                                                                     const uno::Reference< embed::XStorage >& xStorage,
      61             :                                                                     const OUString& sEntName,
      62             :                                                                     const uno::Sequence< beans::PropertyValue >& aMedDescr,
      63             :                                                                     const uno::Sequence< beans::PropertyValue >& lObjArgs )
      64             :     throw ( lang::IllegalArgumentException,
      65             :             container::NoSuchElementException,
      66             :             io::IOException,
      67             :             uno::Exception,
      68             :             uno::RuntimeException, std::exception)
      69             : {
      70             :     SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
      71             : 
      72           0 :     if ( !xStorage.is() )
      73             :         throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
      74             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
      75           0 :                                             1 );
      76             : 
      77           0 :     if ( sEntName.isEmpty() )
      78             :         throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
      79             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
      80           0 :                                             2 );
      81             : 
      82           0 :     uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
      83           0 :     if ( !xNameAccess.is() )
      84           0 :         throw uno::RuntimeException(); //TODO
      85             : 
      86             :     // detect entry existence
      87           0 :     if ( !xNameAccess->hasByName( sEntName ) )
      88           0 :         throw container::NoSuchElementException();
      89             : 
      90           0 :     if ( !xStorage->isStreamElement( sEntName ) )
      91             :     {
      92             :         // if it is not an OLE object throw an exception
      93           0 :         throw io::IOException(); // TODO:
      94             :     }
      95             : 
      96             :     uno::Reference< uno::XInterface > xResult(
      97           0 :                     static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
      98           0 :                     uno::UNO_QUERY );
      99             : 
     100           0 :     uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
     101             : 
     102           0 :     if ( !xPersist.is() )
     103           0 :         throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
     104             : 
     105           0 :     xPersist->setPersistentEntry( xStorage,
     106             :                                     sEntName,
     107             :                                     embed::EntryInitModes::DEFAULT_INIT,
     108             :                                     aMedDescr,
     109           0 :                                     lObjArgs );
     110             : 
     111           0 :     for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
     112             :     {
     113           0 :         if ( lObjArgs[nInd].Name == "CloneFrom" )
     114             :         {
     115             :             try
     116             :             {
     117           0 :                 uno::Reference < embed::XEmbeddedObject > xObj;
     118           0 :                 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
     119           0 :                 lObjArgs[nInd].Value >>= xObj;
     120           0 :                 if ( xObj.is() )
     121           0 :                     xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
     122             :             }
     123           0 :             catch ( const uno::Exception& ) {}
     124           0 :             break;
     125             :         }
     126             :     }
     127             : 
     128           0 :     return xResult;
     129             : }
     130             : 
     131             : 
     132           0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
     133             :         const uno::Reference< embed::XStorage >& xStorage,
     134             :         const OUString& sEntName,
     135             :         const uno::Sequence< beans::PropertyValue >& aMediaDescr,
     136             :         const uno::Sequence< beans::PropertyValue >& lObjArgs )
     137             :     throw ( lang::IllegalArgumentException,
     138             :             io::IOException,
     139             :             uno::Exception,
     140             :             uno::RuntimeException, std::exception)
     141             : {
     142             :     SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
     143             : 
     144           0 :     if ( !xStorage.is() )
     145             :         throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
     146             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     147           0 :                                             1 );
     148             : 
     149           0 :     if ( sEntName.isEmpty() )
     150             :         throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
     151             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     152           0 :                                             2 );
     153             : 
     154             :     uno::Reference< uno::XInterface > xResult(
     155           0 :                     static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
     156           0 :                     uno::UNO_QUERY );
     157             : 
     158           0 :     uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
     159             : 
     160           0 :     if ( !xPersist.is() )
     161           0 :         throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
     162             : 
     163           0 :     xPersist->setPersistentEntry( xStorage,
     164             :                                     sEntName,
     165             :                                     embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
     166             :                                     aMediaDescr,
     167           0 :                                     lObjArgs );
     168             : 
     169           0 :     return xResult;
     170             : }
     171             : 
     172             : 
     173           0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
     174             :                                             const uno::Sequence< sal_Int8 >& aClassID,
     175             :                                             const OUString& aClassName,
     176             :                                             const uno::Reference< embed::XStorage >& xStorage,
     177             :                                             const OUString& sEntName,
     178             :                                             const uno::Sequence< beans::PropertyValue >& lObjArgs )
     179             :     throw ( lang::IllegalArgumentException,
     180             :             io::IOException,
     181             :             uno::Exception,
     182             :             uno::RuntimeException, std::exception)
     183             : {
     184             :     SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
     185             : 
     186           0 :     if ( !xStorage.is() )
     187             :         throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
     188             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     189           0 :                                             3 );
     190             : 
     191           0 :     if ( sEntName.isEmpty() )
     192             :         throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
     193             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     194           0 :                                             4 );
     195             : 
     196             :     uno::Reference< uno::XInterface > xResult(
     197           0 :                     static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
     198           0 :                     uno::UNO_QUERY );
     199             : 
     200           0 :     uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
     201             : 
     202           0 :     if ( !xPersist.is() )
     203           0 :         throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
     204             : 
     205           0 :     xPersist->setPersistentEntry( xStorage,
     206             :                                     sEntName,
     207             :                                     embed::EntryInitModes::TRUNCATE_INIT,
     208             :                                     uno::Sequence< beans::PropertyValue >(),
     209           0 :                                     lObjArgs );
     210             : 
     211           0 :     return xResult;
     212             : }
     213             : 
     214             : 
     215           0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
     216             :                                             const uno::Reference< embed::XStorage >& xStorage,
     217             :                                             const OUString& sEntName,
     218             :                                             const uno::Sequence< beans::PropertyValue >& aMediaDescr,
     219             :                                             const uno::Sequence< beans::PropertyValue >& lObjArgs )
     220             :         throw ( lang::IllegalArgumentException,
     221             :                 io::IOException,
     222             :                 uno::Exception,
     223             :                 uno::RuntimeException, std::exception )
     224             : {
     225             :     SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
     226             : 
     227           0 :     if ( !xStorage.is() )
     228             :         throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
     229             :                                             uno::Reference< uno::XInterface >(
     230             :                                                 static_cast< ::cppu::OWeakObject* >(this) ),
     231           0 :                                             1 );
     232             : 
     233           0 :     if ( sEntName.isEmpty() )
     234             :         throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
     235             :                                             uno::Reference< uno::XInterface >(
     236             :                                                 static_cast< ::cppu::OWeakObject* >(this) ),
     237           0 :                                             2 );
     238             : 
     239             :     uno::Reference< uno::XInterface > xResult(
     240           0 :                 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_True ) ),
     241           0 :                 uno::UNO_QUERY );
     242             : 
     243           0 :     uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
     244             : 
     245           0 :     if ( !xPersist.is() )
     246           0 :         throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
     247             : 
     248           0 :     xPersist->setPersistentEntry( xStorage,
     249             :                                     sEntName,
     250             :                                     embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
     251             :                                     aMediaDescr,
     252           0 :                                     lObjArgs );
     253             : 
     254           0 :     return xResult;
     255             : }
     256             : 
     257             : 
     258           0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
     259             :             const uno::Sequence< sal_Int8 >& aClassID,
     260             :             const OUString& aClassName,
     261             :             const uno::Reference< embed::XStorage >& xStorage,
     262             :             const OUString& sEntName,
     263             :             sal_Int32 /*nEntryConnectionMode*/,
     264             :             const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
     265             :             const uno::Sequence< beans::PropertyValue >& lObjArgs )
     266             :     throw ( lang::IllegalArgumentException,
     267             :             io::IOException,
     268             :             uno::Exception,
     269             :             uno::RuntimeException, std::exception )
     270             : {
     271             :     SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
     272             : 
     273             :     // the initialization is completelly controlled by user
     274           0 :     if ( !xStorage.is() )
     275             :         throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
     276             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     277           0 :                                             1 );
     278             : 
     279           0 :     if ( sEntName.isEmpty() )
     280             :         throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
     281             :                                             uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
     282           0 :                                             2 );
     283             : 
     284             :     uno::Reference< uno::XInterface > xResult(
     285           0 :                 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
     286           0 :                 uno::UNO_QUERY );
     287             : 
     288           0 :     uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
     289           0 :     if ( xPersist.is() )
     290             :     {
     291           0 :         xPersist->setPersistentEntry( xStorage,
     292             :                                     sEntName,
     293             :                                     embed::EntryInitModes::DEFAULT_INIT,
     294             :                                     uno::Sequence< beans::PropertyValue >(),
     295           0 :                                     lObjArgs );
     296             : 
     297             :     }
     298             :     else
     299           0 :         throw uno::RuntimeException(); // TODO:
     300             : 
     301           0 :     return xResult;
     302             : }
     303             : 
     304             : 
     305           0 : OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
     306             :     throw ( uno::RuntimeException, std::exception )
     307             : {
     308           0 :     return impl_staticGetImplementationName();
     309             : }
     310             : 
     311           0 : sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const OUString& ServiceName )
     312             :     throw ( uno::RuntimeException, std::exception )
     313             : {
     314           0 :     return cppu::supportsService(this, ServiceName);
     315             : }
     316             : 
     317             : 
     318           0 : uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
     319             :     throw ( uno::RuntimeException, std::exception )
     320             : {
     321           0 :     return impl_staticGetSupportedServiceNames();
     322             : }
     323             : 
     324             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10