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

Generated by: LCOV version 1.10