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

Generated by: LCOV version 1.10