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