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