1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <rtl/logfile.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include "xfactory.hxx" 41*cdf0e10cSrcweir #include "commonembobj.hxx" 42*cdf0e10cSrcweir #include "specialobject.hxx" 43*cdf0e10cSrcweir #include "oleembobj.hxx" 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::com::sun::star; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir //------------------------------------------------------------------------- 49*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OOoEmbeddedObjectFactory::impl_staticGetSupportedServiceNames() 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(2); 52*cdf0e10cSrcweir aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OOoEmbeddedObjectFactory"); 53*cdf0e10cSrcweir aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoEmbeddedObjectFactory"); 54*cdf0e10cSrcweir return aRet; 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //------------------------------------------------------------------------- 58*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OOoEmbeddedObjectFactory::impl_staticGetImplementationName() 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoEmbeddedObjectFactory"); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir //------------------------------------------------------------------------- 64*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::impl_staticCreateSelfInstance( 65*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir return uno::Reference< uno::XInterface >( *new OOoEmbeddedObjectFactory( xServiceManager ) ); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //------------------------------------------------------------------------- 71*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceInitFromEntry( 72*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 73*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 74*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMediaDescr, 75*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 76*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 77*cdf0e10cSrcweir container::NoSuchElementException, 78*cdf0e10cSrcweir io::IOException, 79*cdf0e10cSrcweir uno::Exception, 80*cdf0e10cSrcweir uno::RuntimeException) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitFromEntry" ); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir if ( !xStorage.is() ) 85*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 86*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 87*cdf0e10cSrcweir 1 ); 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir if ( !sEntName.getLength() ) 90*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 91*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 92*cdf0e10cSrcweir 2 ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); 95*cdf0e10cSrcweir if ( !xNameAccess.is() ) 96*cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // detect entry existence 99*cdf0e10cSrcweir if ( !xNameAccess->hasByName( sEntName ) ) 100*cdf0e10cSrcweir throw container::NoSuchElementException(); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 103*cdf0e10cSrcweir if ( xStorage->isStorageElement( sEntName ) ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir // the object must be based on storage 106*cdf0e10cSrcweir uno::Reference< embed::XStorage > xSubStorage = 107*cdf0e10cSrcweir xStorage->openStorageElement( sEntName, embed::ElementModes::READ ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xSubStorage, uno::UNO_QUERY ); 110*cdf0e10cSrcweir if ( !xPropSet.is() ) 111*cdf0e10cSrcweir throw uno::RuntimeException(); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir ::rtl::OUString aMediaType; 114*cdf0e10cSrcweir try { 115*cdf0e10cSrcweir uno::Any aAny = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 116*cdf0e10cSrcweir aAny >>= aMediaType; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir catch ( uno::Exception& ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir try { 123*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( xSubStorage, uno::UNO_QUERY ); 124*cdf0e10cSrcweir if ( xComp.is() ) 125*cdf0e10cSrcweir xComp->dispose(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir catch ( uno::Exception& ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir xSubStorage = uno::Reference< embed::XStorage >(); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir #if 0 133*cdf0e10cSrcweir ::rtl::OUString aDocServiceName = m_aConfigHelper.GetDocumentServiceFromMediaType( aMediaType ); 134*cdf0e10cSrcweir if ( !aDocServiceName.getLength() ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir // only own document can be based on storage 137*cdf0e10cSrcweir // in case it is not possible to find related 138*cdf0e10cSrcweir // document service name the storage entry is invalid 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir #endif 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByMediaType( aMediaType ); 145*cdf0e10cSrcweir if ( !aObject.getLength() ) 146*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir xResult = uno::Reference< uno::XInterface >( 149*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject( 150*cdf0e10cSrcweir m_xFactory, 151*cdf0e10cSrcweir aObject ) ), 152*cdf0e10cSrcweir #if 0 153*cdf0e10cSrcweir GetClassIDFromServName( aDocServiceName ), 154*cdf0e10cSrcweir GetClassNameFromServName( aDocServiceName ), 155*cdf0e10cSrcweir aDocServiceName ) ), 156*cdf0e10cSrcweir #endif 157*cdf0e10cSrcweir uno::UNO_QUERY ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir else 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir // the object must be OOo embedded object, if it is not an exception must be thrown 162*cdf0e10cSrcweir throw io::IOException(); // TODO: 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if ( !xPersist.is() ) 168*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir xPersist->setPersistentEntry( xStorage, 171*cdf0e10cSrcweir sEntName, 172*cdf0e10cSrcweir embed::EntryInitModes::DEFAULT_INIT, 173*cdf0e10cSrcweir aMediaDescr, 174*cdf0e10cSrcweir lObjArgs ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir return xResult; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //------------------------------------------------------------------------- 180*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor( 181*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 182*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 183*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMediaDescr, 184*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 185*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 186*cdf0e10cSrcweir io::IOException, 187*cdf0e10cSrcweir uno::Exception, 188*cdf0e10cSrcweir uno::RuntimeException) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if ( !xStorage.is() ) 193*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 194*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 195*cdf0e10cSrcweir 1 ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir if ( !sEntName.getLength() ) 198*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 199*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 200*cdf0e10cSrcweir 2 ); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir // check if there is FilterName 205*cdf0e10cSrcweir ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, sal_False ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // find document service name 210*cdf0e10cSrcweir if ( aFilterName.getLength() ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByFilter( aFilterName ); 213*cdf0e10cSrcweir if ( !aObject.getLength() ) 214*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir xResult = uno::Reference< uno::XInterface >( 218*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject( 219*cdf0e10cSrcweir m_xFactory, 220*cdf0e10cSrcweir aObject ) ), 221*cdf0e10cSrcweir uno::UNO_QUERY ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir else 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir // the object must be OOo embedded object, if it is not an exception must be thrown 226*cdf0e10cSrcweir throw io::IOException(); // TODO: 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir if ( !xPersist.is() ) 232*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? ) 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir xPersist->setPersistentEntry( xStorage, 235*cdf0e10cSrcweir sEntName, 236*cdf0e10cSrcweir embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT, 237*cdf0e10cSrcweir aTempMedDescr, 238*cdf0e10cSrcweir lObjArgs ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir return xResult; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //------------------------------------------------------------------------- 244*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceInitNew( 245*cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 246*cdf0e10cSrcweir const ::rtl::OUString& /*aClassName*/, 247*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 248*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 249*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 250*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 251*cdf0e10cSrcweir io::IOException, 252*cdf0e10cSrcweir uno::Exception, 253*cdf0e10cSrcweir uno::RuntimeException) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitNew" ); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if ( !xStorage.is() ) 260*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 261*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 262*cdf0e10cSrcweir 3 ); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir if ( !sEntName.getLength() ) 265*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 266*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 267*cdf0e10cSrcweir 4 ); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID ); 270*cdf0e10cSrcweir if ( !aObject.getLength() ) 271*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir xResult = uno::Reference< uno::XInterface >( 274*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject( 275*cdf0e10cSrcweir m_xFactory, 276*cdf0e10cSrcweir aObject ) ), 277*cdf0e10cSrcweir uno::UNO_QUERY ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY ); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if ( !xPersist.is() ) 283*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir xPersist->setPersistentEntry( xStorage, 286*cdf0e10cSrcweir sEntName, 287*cdf0e10cSrcweir embed::EntryInitModes::TRUNCATE_INIT, 288*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >(), 289*cdf0e10cSrcweir lObjArgs ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir return xResult; 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir //------------------------------------------------------------------------- 295*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceUserInit( 296*cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 297*cdf0e10cSrcweir const ::rtl::OUString& /*aClassName*/, 298*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 299*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 300*cdf0e10cSrcweir sal_Int32 nEntryConnectionMode, 301*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 302*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 303*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 304*cdf0e10cSrcweir io::IOException, 305*cdf0e10cSrcweir uno::Exception, 306*cdf0e10cSrcweir uno::RuntimeException ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceUserInit" ); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir // the initialization is completelly controlled by user 311*cdf0e10cSrcweir if ( !xStorage.is() ) 312*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 313*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 314*cdf0e10cSrcweir 1 ); 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir if ( !sEntName.getLength() ) 317*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 318*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 319*cdf0e10cSrcweir 2 ); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID ); 322*cdf0e10cSrcweir if ( !aObject.getLength() ) 323*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMedDescr( lArguments ); 326*cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT ) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, aObject ); 329*cdf0e10cSrcweir if ( !aFilterName.getLength() ) 330*cdf0e10cSrcweir // the object must be OOo embedded object, if it is not an exception must be thrown 331*cdf0e10cSrcweir throw io::IOException(); // TODO: 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult = uno::Reference< uno::XInterface > ( 335*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject( 336*cdf0e10cSrcweir m_xFactory, 337*cdf0e10cSrcweir aObject ) ), 338*cdf0e10cSrcweir uno::UNO_QUERY ); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY ); 341*cdf0e10cSrcweir if ( xPersist.is() ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir xPersist->setPersistentEntry( xStorage, 344*cdf0e10cSrcweir sEntName, 345*cdf0e10cSrcweir nEntryConnectionMode, 346*cdf0e10cSrcweir aTempMedDescr, 347*cdf0e10cSrcweir lObjArgs ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir else 351*cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir return xResult; 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //------------------------------------------------------------------------- 358*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceLink( 359*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& /*xStorage*/, 360*cdf0e10cSrcweir const ::rtl::OUString& /*sEntName*/, 361*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aMediaDescr, 362*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 363*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 364*cdf0e10cSrcweir io::IOException, 365*cdf0e10cSrcweir uno::Exception, 366*cdf0e10cSrcweir uno::RuntimeException ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceLink" ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr ); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir // check if there is URL, URL must exist 375*cdf0e10cSrcweir ::rtl::OUString aURL; 376*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aTempMedDescr.getLength(); nInd++ ) 377*cdf0e10cSrcweir if ( aTempMedDescr[nInd].Name.equalsAscii( "URL" ) ) 378*cdf0e10cSrcweir aTempMedDescr[nInd].Value >>= aURL; 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir if ( !aURL.getLength() ) 381*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No URL for the link is provided!\n" ), 382*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 383*cdf0e10cSrcweir 3 ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, sal_False ); 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir if ( aFilterName.getLength() ) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByFilter( aFilterName ); 390*cdf0e10cSrcweir if ( !aObject.getLength() ) 391*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir xResult = uno::Reference< uno::XInterface >( 395*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject( 396*cdf0e10cSrcweir m_xFactory, 397*cdf0e10cSrcweir aObject, 398*cdf0e10cSrcweir aTempMedDescr, 399*cdf0e10cSrcweir lObjArgs ) ), 400*cdf0e10cSrcweir uno::UNO_QUERY ); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir else 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir // the object must be OOo embedded object, if it is not an exception must be thrown 405*cdf0e10cSrcweir throw io::IOException(); // TODO: 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir return xResult; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir //------------------------------------------------------------------------- 412*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoEmbeddedObjectFactory::createInstanceLinkUserInit( 413*cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 414*cdf0e10cSrcweir const ::rtl::OUString& /*aClassName*/, 415*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 416*cdf0e10cSrcweir const ::rtl::OUString& sEntName, 417*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 418*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 419*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 420*cdf0e10cSrcweir io::IOException, 421*cdf0e10cSrcweir uno::Exception, 422*cdf0e10cSrcweir uno::RuntimeException ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceLinkUserInit" ); 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir // the initialization is completelly controlled by user 429*cdf0e10cSrcweir if ( !xStorage.is() ) 430*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 431*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 432*cdf0e10cSrcweir 1 ); 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if ( !sEntName.getLength() ) 435*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 436*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 437*cdf0e10cSrcweir 2 ); 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aTempMedDescr( lArguments ); 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir ::rtl::OUString aURL; 442*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aTempMedDescr.getLength(); nInd++ ) 443*cdf0e10cSrcweir if ( aTempMedDescr[nInd].Name.equalsAscii( "URL" ) ) 444*cdf0e10cSrcweir aTempMedDescr[nInd].Value >>= aURL; 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir if ( !aURL.getLength() ) 447*cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No URL for the link is provided!\n" ), 448*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 449*cdf0e10cSrcweir 3 ); 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID ); 452*cdf0e10cSrcweir if ( !aObject.getLength() ) 453*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir ::rtl::OUString aFilterName = m_aConfigHelper.UpdateMediaDescriptorWithFilterName( aTempMedDescr, aObject ); 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir if ( aFilterName.getLength() ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir xResult = uno::Reference< uno::XInterface >( 461*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OCommonEmbeddedObject( 462*cdf0e10cSrcweir m_xFactory, 463*cdf0e10cSrcweir aObject, 464*cdf0e10cSrcweir aTempMedDescr, 465*cdf0e10cSrcweir lObjArgs ) ), 466*cdf0e10cSrcweir uno::UNO_QUERY ); 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir else 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir // the object must be OOo embedded object, if it is not an exception must be thrown 471*cdf0e10cSrcweir throw io::IOException(); // TODO: 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir return xResult; 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir //------------------------------------------------------------------------- 478*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OOoEmbeddedObjectFactory::getImplementationName() 479*cdf0e10cSrcweir throw ( uno::RuntimeException ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir return impl_staticGetImplementationName(); 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir //------------------------------------------------------------------------- 485*cdf0e10cSrcweir sal_Bool SAL_CALL OOoEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName ) 486*cdf0e10cSrcweir throw ( uno::RuntimeException ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) 491*cdf0e10cSrcweir if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) 492*cdf0e10cSrcweir return sal_True; 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir return sal_False; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir //------------------------------------------------------------------------- 498*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OOoEmbeddedObjectFactory::getSupportedServiceNames() 499*cdf0e10cSrcweir throw ( uno::RuntimeException ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir return impl_staticGetSupportedServiceNames(); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir //------------------------------------------------------------------------- 505*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames() 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(2); 508*cdf0e10cSrcweir aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OOoSpecialEmbeddedObjectFactory"); 509*cdf0e10cSrcweir aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory"); 510*cdf0e10cSrcweir return aRet; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir //------------------------------------------------------------------------- 514*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName() 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory"); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir //------------------------------------------------------------------------- 520*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoSpecialEmbeddedObjectFactory::impl_staticCreateSelfInstance( 521*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir return uno::Reference< uno::XInterface >( *new OOoSpecialEmbeddedObjectFactory( xServiceManager ) ); 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir //------------------------------------------------------------------------- 527*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OOoSpecialEmbeddedObjectFactory::createInstanceUserInit( 528*cdf0e10cSrcweir const uno::Sequence< sal_Int8 >& aClassID, 529*cdf0e10cSrcweir const ::rtl::OUString& /*aClassName*/, 530*cdf0e10cSrcweir const uno::Reference< embed::XStorage >& /*xStorage*/, 531*cdf0e10cSrcweir const ::rtl::OUString& /*sEntName*/, 532*cdf0e10cSrcweir sal_Int32 /*nEntryConnectionMode*/, 533*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& /*lArguments*/, 534*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& /*lObjArgs*/ ) 535*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 536*cdf0e10cSrcweir io::IOException, 537*cdf0e10cSrcweir uno::Exception, 538*cdf0e10cSrcweir uno::RuntimeException ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aObject = m_aConfigHelper.GetObjectPropsByClassID( aClassID ); 541*cdf0e10cSrcweir if ( !aObject.getLength() ) 542*cdf0e10cSrcweir throw io::IOException(); // unexpected mimetype of the storage 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir uno::Reference< uno::XInterface > xResult( 545*cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* > ( new OSpecialEmbeddedObject( 546*cdf0e10cSrcweir m_xFactory, 547*cdf0e10cSrcweir aObject ) ), 548*cdf0e10cSrcweir uno::UNO_QUERY ); 549*cdf0e10cSrcweir return xResult; 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir //------------------------------------------------------------------------- 553*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OOoSpecialEmbeddedObjectFactory::getImplementationName() 554*cdf0e10cSrcweir throw ( uno::RuntimeException ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir return impl_staticGetImplementationName(); 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir //------------------------------------------------------------------------- 560*cdf0e10cSrcweir sal_Bool SAL_CALL OOoSpecialEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName ) 561*cdf0e10cSrcweir throw ( uno::RuntimeException ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) 566*cdf0e10cSrcweir if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) 567*cdf0e10cSrcweir return sal_True; 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir return sal_False; 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir //------------------------------------------------------------------------- 573*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OOoSpecialEmbeddedObjectFactory::getSupportedServiceNames() 574*cdf0e10cSrcweir throw ( uno::RuntimeException ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir return impl_staticGetSupportedServiceNames(); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir 580