1*bfd08df8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bfd08df8SAndrew Rist * distributed with this work for additional information 6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance 9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an 15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the 17*bfd08df8SAndrew Rist * specific language governing permissions and limitations 18*bfd08df8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*bfd08df8SAndrew Rist *************************************************************/ 21*bfd08df8SAndrew Rist 22*bfd08df8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 26cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 27cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp> 28cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedObjectFactory.hpp> 29cdf0e10cSrcweir #include <com/sun/star/embed/XLinkFactory.hpp> 30cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp> 31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 33cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 34cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <rtl/logfile.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <xcreator.hxx> 40cdf0e10cSrcweir #include <dummyobject.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::com::sun::star; 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir //------------------------------------------------------------------------- 47cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL UNOEmbeddedObjectCreator::impl_staticGetSupportedServiceNames() 48cdf0e10cSrcweir { 49cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(2); 50cdf0e10cSrcweir aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.EmbeddedObjectCreator"); 51cdf0e10cSrcweir aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.EmbeddedObjectCreator"); 52cdf0e10cSrcweir return aRet; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir //------------------------------------------------------------------------- 56cdf0e10cSrcweir ::rtl::OUString SAL_CALL UNOEmbeddedObjectCreator::impl_staticGetImplementationName() 57cdf0e10cSrcweir { 58cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.EmbeddedObjectCreator"); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir //------------------------------------------------------------------------- 62cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::impl_staticCreateSelfInstance( 63cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir return uno::Reference< uno::XInterface >( *new UNOEmbeddedObjectCreator( xServiceManager ) ); 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir //------------------------------------------------------------------------- 69cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceInitNew( 70cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 71cdf0e10cSrcweir const ::rtl::OUString& aClassName, 72cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 73cdf0e10cSrcweir const ::rtl::OUString& sEntName, 74cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 75cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 76cdf0e10cSrcweir io::IOException, 77cdf0e10cSrcweir uno::Exception, 78cdf0e10cSrcweir uno::RuntimeException) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) UNOEmbeddedObjectCreator::createInstanceInitNew" ); 81cdf0e10cSrcweir 82cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 83cdf0e10cSrcweir 84cdf0e10cSrcweir if ( !xStorage.is() ) 85cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 86cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 87cdf0e10cSrcweir 3 ); 88cdf0e10cSrcweir 89cdf0e10cSrcweir if ( !sEntName.getLength() ) 90cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 91cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 92cdf0e10cSrcweir 4 ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir ::rtl::OUString aEmbedFactory = m_aConfigHelper.GetFactoryNameByClassID( aClassID ); 95cdf0e10cSrcweir if ( !aEmbedFactory.getLength() ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir // use system fallback 98cdf0e10cSrcweir // TODO: in future users factories can be tested 99cdf0e10cSrcweir aEmbedFactory = ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLEEmbeddedObjectFactory" ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir uno::Reference < uno::XInterface > xFact( m_xFactory->createInstance( aEmbedFactory ) ); 103cdf0e10cSrcweir uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY ); 104cdf0e10cSrcweir if ( xEmbCreator.is() ) 105cdf0e10cSrcweir return xEmbCreator->createInstanceInitNew( aClassID, aClassName, xStorage, sEntName, lObjArgs ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir uno::Reference < embed::XEmbedObjectFactory > xEmbFact( xFact, uno::UNO_QUERY ); 108cdf0e10cSrcweir if ( !xEmbFact.is() ) 109cdf0e10cSrcweir throw uno::RuntimeException(); 110cdf0e10cSrcweir return xEmbFact->createInstanceUserInit( aClassID, aClassName, xStorage, sEntName, embed::EntryInitModes::TRUNCATE_INIT, uno::Sequence < beans::PropertyValue >(), lObjArgs); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //------------------------------------------------------------------------- 114cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceInitFromEntry( 115cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 116cdf0e10cSrcweir const ::rtl::OUString& sEntName, 117cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMedDescr, 118cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 119cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 120cdf0e10cSrcweir container::NoSuchElementException, 121cdf0e10cSrcweir io::IOException, 122cdf0e10cSrcweir uno::Exception, 123cdf0e10cSrcweir uno::RuntimeException) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) UNOEmbeddedObjectCreator::createInstanceInitFromEntry" ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir if ( !xStorage.is() ) 128cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 129cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 130cdf0e10cSrcweir 1 ); 131cdf0e10cSrcweir 132cdf0e10cSrcweir if ( !sEntName.getLength() ) 133cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 134cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 135cdf0e10cSrcweir 2 ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); 138cdf0e10cSrcweir if ( !xNameAccess.is() ) 139cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 140cdf0e10cSrcweir 141cdf0e10cSrcweir // detect entry existence 142cdf0e10cSrcweir if ( !xNameAccess->hasByName( sEntName ) ) 143cdf0e10cSrcweir throw container::NoSuchElementException(); 144cdf0e10cSrcweir 145cdf0e10cSrcweir ::rtl::OUString aMediaType; 146cdf0e10cSrcweir ::rtl::OUString aEmbedFactory; 147cdf0e10cSrcweir if ( xStorage->isStorageElement( sEntName ) ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir // the object must be based on storage 150cdf0e10cSrcweir uno::Reference< embed::XStorage > xSubStorage = 151cdf0e10cSrcweir xStorage->openStorageElement( sEntName, embed::ElementModes::READ ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xSubStorage, uno::UNO_QUERY ); 154cdf0e10cSrcweir if ( !xPropSet.is() ) 155cdf0e10cSrcweir throw uno::RuntimeException(); 156cdf0e10cSrcweir 157cdf0e10cSrcweir try { 158cdf0e10cSrcweir uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 159cdf0e10cSrcweir aAny >>= aMediaType; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir catch ( uno::Exception& ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir try { 166cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( xSubStorage, uno::UNO_QUERY ); 167cdf0e10cSrcweir if ( xComp.is() ) 168cdf0e10cSrcweir xComp->dispose(); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir catch ( uno::Exception& ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir else 175cdf0e10cSrcweir { 176cdf0e10cSrcweir // the object must be based on stream 177cdf0e10cSrcweir // it means for now that this is an OLE object 178cdf0e10cSrcweir 179cdf0e10cSrcweir // the object will be created as embedded object 180cdf0e10cSrcweir // after it is loaded it can detect that it is a link 181cdf0e10cSrcweir 182cdf0e10cSrcweir uno::Reference< io::XStream > xSubStream = 183cdf0e10cSrcweir xStorage->openStreamElement( sEntName, embed::ElementModes::READ ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xSubStream, uno::UNO_QUERY ); 186cdf0e10cSrcweir if ( !xPropSet.is() ) 187cdf0e10cSrcweir throw uno::RuntimeException(); 188cdf0e10cSrcweir 189cdf0e10cSrcweir try { 190cdf0e10cSrcweir uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 191cdf0e10cSrcweir aAny >>= aMediaType; 192cdf0e10cSrcweir if ( aMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.oleobject" ) ) ) ) 193cdf0e10cSrcweir aEmbedFactory = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.OLEEmbeddedObjectFactory" ) ); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir catch ( uno::Exception& ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir try { 200cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( xSubStream, uno::UNO_QUERY ); 201cdf0e10cSrcweir if ( xComp.is() ) 202cdf0e10cSrcweir xComp->dispose(); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir catch ( uno::Exception& ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir } 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir OSL_ENSURE( aMediaType.getLength(), "No media type is specified for the object!" ); 210cdf0e10cSrcweir if ( aMediaType.getLength() && !aEmbedFactory.getLength() ) 211cdf0e10cSrcweir aEmbedFactory = m_aConfigHelper.GetFactoryNameByMediaType( aMediaType ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir if ( aEmbedFactory.getLength() ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir uno::Reference< uno::XInterface > xFact = m_xFactory->createInstance( aEmbedFactory ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY ); 218cdf0e10cSrcweir if ( xEmbCreator.is() ) 219cdf0e10cSrcweir return xEmbCreator->createInstanceInitFromEntry( xStorage, sEntName, aMedDescr, lObjArgs ); 220cdf0e10cSrcweir 221cdf0e10cSrcweir uno::Reference < embed::XEmbedObjectFactory > xEmbFact( xFact, uno::UNO_QUERY ); 222cdf0e10cSrcweir if ( xEmbFact.is() ) 223cdf0e10cSrcweir return xEmbFact->createInstanceUserInit( uno::Sequence< sal_Int8 >(), ::rtl::OUString(), xStorage, sEntName, embed::EntryInitModes::DEFAULT_INIT, aMedDescr, lObjArgs); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir // the default object should be created, it will allow to store the contents on the next saving 227cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult( static_cast< cppu::OWeakObject* >( new ODummyEmbeddedObject() ) ); 228cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW ); 229cdf0e10cSrcweir xPersist->setPersistentEntry( xStorage, sEntName, embed::EntryInitModes::DEFAULT_INIT, aMedDescr, lObjArgs ); 230cdf0e10cSrcweir return xResult; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir //------------------------------------------------------------------------- 234cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceInitFromMediaDescriptor( 235cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 236cdf0e10cSrcweir const ::rtl::OUString& sEntName, 237cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMediaDescr, 238cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 239cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 240cdf0e10cSrcweir io::IOException, 241cdf0e10cSrcweir uno::Exception, 242cdf0e10cSrcweir uno::RuntimeException) 243cdf0e10cSrcweir { 244cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) UNOEmbeddedObjectCreator::createInstanceInitFromMediaDescriptor" ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir // TODO: use lObjArgs 247cdf0e10cSrcweir 248cdf0e10cSrcweir if ( !xStorage.is() ) 249cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 250cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 251cdf0e10cSrcweir 1 ); 252cdf0e10cSrcweir 253cdf0e10cSrcweir if ( !sEntName.getLength() ) 254cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 255cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 256cdf0e10cSrcweir 2 ); 257cdf0e10cSrcweir 258cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 259cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr ); 260cdf0e10cSrcweir 261cdf0e10cSrcweir // check if there is FilterName 262cdf0e10cSrcweir ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, sal_False ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir if ( aFilterName.getLength() ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir // the object can be loaded by one of the office application 267cdf0e10cSrcweir uno::Reference< embed::XEmbedObjectCreator > xOOoEmbCreator( 268cdf0e10cSrcweir m_xFactory->createInstance( 269cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OOoEmbeddedObjectFactory" ) ), 270cdf0e10cSrcweir uno::UNO_QUERY ); 271cdf0e10cSrcweir if ( !xOOoEmbCreator.is() ) 272cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 273cdf0e10cSrcweir 274cdf0e10cSrcweir xResult = xOOoEmbCreator->createInstanceInitFromMediaDescriptor( xStorage, 275cdf0e10cSrcweir sEntName, 276cdf0e10cSrcweir aTempMedDescr, 277cdf0e10cSrcweir lObjArgs ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir else 280cdf0e10cSrcweir { 281cdf0e10cSrcweir // must be an OLE object 282cdf0e10cSrcweir 283cdf0e10cSrcweir // TODO: in future, when more object types are possible this place seems 284cdf0e10cSrcweir // to be a weak one, probably configuration must provide a type detection service 285cdf0e10cSrcweir // for every factory, so any file could go through services until it is recognized 286cdf0e10cSrcweir // or there is no more services 287cdf0e10cSrcweir // Or for example the typename can be used to detect object type if typedetection 288cdf0e10cSrcweir // was also extended. 289cdf0e10cSrcweir 290cdf0e10cSrcweir uno::Reference< embed::XEmbedObjectCreator > xOleEmbCreator( 291cdf0e10cSrcweir m_xFactory->createInstance( 292cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLEEmbeddedObjectFactory" ) ), 293cdf0e10cSrcweir uno::UNO_QUERY ); 294cdf0e10cSrcweir if ( !xOleEmbCreator.is() ) 295cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 296cdf0e10cSrcweir 297cdf0e10cSrcweir xResult = xOleEmbCreator->createInstanceInitFromMediaDescriptor( xStorage, sEntName, aTempMedDescr, lObjArgs ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir return xResult; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir //------------------------------------------------------------------------- 304cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceUserInit( 305cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 306cdf0e10cSrcweir const ::rtl::OUString& sClassName, 307cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 308cdf0e10cSrcweir const ::rtl::OUString& sEntName, 309cdf0e10cSrcweir sal_Int32 nEntryConnectionMode, 310cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aArgs, 311cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aObjectArgs ) 312cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 313cdf0e10cSrcweir io::IOException, 314cdf0e10cSrcweir uno::Exception, 315cdf0e10cSrcweir uno::RuntimeException) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) UNOEmbeddedObjectCreator::createInstanceUserInit" ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 320cdf0e10cSrcweir 321cdf0e10cSrcweir if ( !xStorage.is() ) 322cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 323cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 324cdf0e10cSrcweir 3 ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir if ( !sEntName.getLength() ) 327cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 328cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 329cdf0e10cSrcweir 4 ); 330cdf0e10cSrcweir 331cdf0e10cSrcweir ::rtl::OUString aEmbedFactory = m_aConfigHelper.GetFactoryNameByClassID( aClassID ); 332cdf0e10cSrcweir uno::Reference< embed::XEmbedObjectFactory > xEmbFactory( 333cdf0e10cSrcweir m_xFactory->createInstance( aEmbedFactory ), 334cdf0e10cSrcweir uno::UNO_QUERY ); 335cdf0e10cSrcweir if ( !xEmbFactory.is() ) 336cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 337cdf0e10cSrcweir 338cdf0e10cSrcweir return xEmbFactory->createInstanceUserInit( aClassID, 339cdf0e10cSrcweir sClassName, 340cdf0e10cSrcweir xStorage, 341cdf0e10cSrcweir sEntName, 342cdf0e10cSrcweir nEntryConnectionMode, 343cdf0e10cSrcweir aArgs, 344cdf0e10cSrcweir aObjectArgs ); 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir //------------------------------------------------------------------------- 348cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceLink( 349cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 350cdf0e10cSrcweir const ::rtl::OUString& sEntName, 351cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMediaDescr, 352cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 353cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 354cdf0e10cSrcweir io::IOException, 355cdf0e10cSrcweir uno::Exception, 356cdf0e10cSrcweir uno::RuntimeException ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) UNOEmbeddedObjectCreator::createInstanceLink" ); 359cdf0e10cSrcweir 360cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 361cdf0e10cSrcweir 362cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr ); 363cdf0e10cSrcweir 364cdf0e10cSrcweir // check if there is URL, URL must exist 365cdf0e10cSrcweir ::rtl::OUString aURL; 366cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aTempMedDescr.getLength(); nInd++ ) 367cdf0e10cSrcweir if ( aTempMedDescr[nInd].Name.equalsAscii( "URL" ) ) 368cdf0e10cSrcweir aTempMedDescr[nInd].Value >>= aURL; 369cdf0e10cSrcweir 370cdf0e10cSrcweir if ( !aURL.getLength() ) 371cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No URL for the link is provided!\n" ), 372cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 373cdf0e10cSrcweir 3 ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, sal_False ); 376cdf0e10cSrcweir 377cdf0e10cSrcweir if ( aFilterName.getLength() ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir // the object can be loaded by one of the office application 380cdf0e10cSrcweir uno::Reference< embed::XLinkCreator > xOOoLinkCreator( 381cdf0e10cSrcweir m_xFactory->createInstance( 382cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OOoEmbeddedObjectFactory" ) ), 383cdf0e10cSrcweir uno::UNO_QUERY ); 384cdf0e10cSrcweir if ( !xOOoLinkCreator.is() ) 385cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 386cdf0e10cSrcweir 387cdf0e10cSrcweir xResult = xOOoLinkCreator->createInstanceLink( xStorage, 388cdf0e10cSrcweir sEntName, 389cdf0e10cSrcweir aTempMedDescr, 390cdf0e10cSrcweir lObjArgs ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir else 393cdf0e10cSrcweir { 394cdf0e10cSrcweir // must be an OLE link 395cdf0e10cSrcweir 396cdf0e10cSrcweir // TODO: in future, when more object types are possible this place seems 397cdf0e10cSrcweir // to be a weak one, probably configuration must provide a type detection service 398cdf0e10cSrcweir // for every factory, so any file could go through services until it is recognized 399cdf0e10cSrcweir // or there is no more services 400cdf0e10cSrcweir // Or for example the typename can be used to detect object type if typedetection 401cdf0e10cSrcweir // was also extended. 402cdf0e10cSrcweir 403cdf0e10cSrcweir if ( !xStorage.is() ) 404cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 405cdf0e10cSrcweir uno::Reference< uno::XInterface >( 406cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this) ), 407cdf0e10cSrcweir 3 ); 408cdf0e10cSrcweir 409cdf0e10cSrcweir if ( !sEntName.getLength() ) 410cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 411cdf0e10cSrcweir uno::Reference< uno::XInterface >( 412cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >(this) ), 413cdf0e10cSrcweir 4 ); 414cdf0e10cSrcweir 415cdf0e10cSrcweir uno::Reference< embed::XLinkCreator > xLinkCreator( 416cdf0e10cSrcweir m_xFactory->createInstance( 417cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLEEmbeddedObjectFactory" ) ), 418cdf0e10cSrcweir uno::UNO_QUERY ); 419cdf0e10cSrcweir if ( !xLinkCreator.is() ) 420cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 421cdf0e10cSrcweir 422cdf0e10cSrcweir xResult = xLinkCreator->createInstanceLink( xStorage, sEntName, aTempMedDescr, lObjArgs ); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir return xResult; 426cdf0e10cSrcweir } 427cdf0e10cSrcweir 428cdf0e10cSrcweir //------------------------------------------------------------------------- 429cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL UNOEmbeddedObjectCreator::createInstanceLinkUserInit( 430cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 431cdf0e10cSrcweir const ::rtl::OUString& aClassName, 432cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 433cdf0e10cSrcweir const ::rtl::OUString& sEntName, 434cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 435cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 436cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 437cdf0e10cSrcweir io::IOException, 438cdf0e10cSrcweir uno::Exception, 439cdf0e10cSrcweir uno::RuntimeException ) 440cdf0e10cSrcweir { 441cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) UNOEmbeddedObjectCreator::createInstanceLinkUserInit" ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 444cdf0e10cSrcweir 445cdf0e10cSrcweir ::rtl::OUString aEmbedFactory = m_aConfigHelper.GetFactoryNameByClassID( aClassID ); 446cdf0e10cSrcweir uno::Reference< embed::XLinkFactory > xLinkFactory( 447cdf0e10cSrcweir m_xFactory->createInstance( aEmbedFactory ), 448cdf0e10cSrcweir uno::UNO_QUERY ); 449cdf0e10cSrcweir if ( !xLinkFactory.is() ) 450cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 451cdf0e10cSrcweir 452cdf0e10cSrcweir return xLinkFactory->createInstanceLinkUserInit( aClassID, 453cdf0e10cSrcweir aClassName, 454cdf0e10cSrcweir xStorage, 455cdf0e10cSrcweir sEntName, 456cdf0e10cSrcweir lArguments, 457cdf0e10cSrcweir lObjArgs ); 458cdf0e10cSrcweir 459cdf0e10cSrcweir } 460cdf0e10cSrcweir 461cdf0e10cSrcweir //------------------------------------------------------------------------- 462cdf0e10cSrcweir ::rtl::OUString SAL_CALL UNOEmbeddedObjectCreator::getImplementationName() 463cdf0e10cSrcweir throw ( uno::RuntimeException ) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir return impl_staticGetImplementationName(); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir //------------------------------------------------------------------------- 469cdf0e10cSrcweir sal_Bool SAL_CALL UNOEmbeddedObjectCreator::supportsService( const ::rtl::OUString& ServiceName ) 470cdf0e10cSrcweir throw ( uno::RuntimeException ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); 473cdf0e10cSrcweir 474cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) 475cdf0e10cSrcweir if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) 476cdf0e10cSrcweir return sal_True; 477cdf0e10cSrcweir 478cdf0e10cSrcweir return sal_False; 479cdf0e10cSrcweir } 480cdf0e10cSrcweir 481cdf0e10cSrcweir //------------------------------------------------------------------------- 482cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL UNOEmbeddedObjectCreator::getSupportedServiceNames() 483cdf0e10cSrcweir throw ( uno::RuntimeException ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir return impl_staticGetSupportedServiceNames(); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488