Update ooo320-m1
[ooovba.git] / embeddedobj / source / msole / xolefactory.cxx
blobd78c841f0a5ec22a9244b998f1f4a59988d07807
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xolefactory.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
33 #include <com/sun/star/embed/ElementModes.hpp>
34 #include <com/sun/star/embed/EntryInitModes.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/embed/Aspects.hpp>
40 #include <rtl/logfile.hxx>
43 #include "xolefactory.hxx"
44 #include "oleembobj.hxx"
47 using namespace ::com::sun::star;
49 // TODO: do not create OLE objects that represent OOo documents
51 //-------------------------------------------------------------------------
52 uno::Sequence< ::rtl::OUString > SAL_CALL OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
54 uno::Sequence< ::rtl::OUString > aRet(2);
55 aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OLEEmbeddedObjectFactory");
56 aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
57 return aRet;
60 //-------------------------------------------------------------------------
61 ::rtl::OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
63 return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
66 //-------------------------------------------------------------------------
67 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
68 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
70 return uno::Reference< uno::XInterface >( *new OleEmbeddedObjectFactory( xServiceManager ) );
73 //-------------------------------------------------------------------------
74 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry(
75 const uno::Reference< embed::XStorage >& xStorage,
76 const ::rtl::OUString& sEntName,
77 const uno::Sequence< beans::PropertyValue >& aMedDescr,
78 const uno::Sequence< beans::PropertyValue >& lObjArgs )
79 throw ( lang::IllegalArgumentException,
80 container::NoSuchElementException,
81 io::IOException,
82 uno::Exception,
83 uno::RuntimeException)
85 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
87 if ( !xStorage.is() )
88 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
89 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
90 1 );
92 if ( !sEntName.getLength() )
93 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
94 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
95 2 );
97 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
98 if ( !xNameAccess.is() )
99 throw uno::RuntimeException(); //TODO
101 // detect entry existence
102 if ( !xNameAccess->hasByName( sEntName ) )
103 throw container::NoSuchElementException();
105 if ( !xStorage->isStreamElement( sEntName ) )
107 // if it is not an OLE object throw an exception
108 throw io::IOException(); // TODO:
111 uno::Reference< uno::XInterface > xResult(
112 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
113 uno::UNO_QUERY );
115 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
117 if ( !xPersist.is() )
118 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
120 xPersist->setPersistentEntry( xStorage,
121 sEntName,
122 embed::EntryInitModes::DEFAULT_INIT,
123 aMedDescr,
124 lObjArgs );
126 for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
128 if ( lObjArgs[nInd].Name.equalsAscii( "CloneFrom" ) )
132 uno::Reference < embed::XEmbeddedObject > xObj;
133 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
134 lObjArgs[nInd].Value >>= xObj;
135 if ( xObj.is() )
136 xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
138 catch ( uno::Exception& ) {};
139 break;
143 return xResult;
146 //-------------------------------------------------------------------------
147 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
148 const uno::Reference< embed::XStorage >& xStorage,
149 const ::rtl::OUString& sEntName,
150 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
151 const uno::Sequence< beans::PropertyValue >& lObjArgs )
152 throw ( lang::IllegalArgumentException,
153 io::IOException,
154 uno::Exception,
155 uno::RuntimeException)
157 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
159 if ( !xStorage.is() )
160 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
161 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
162 1 );
164 if ( !sEntName.getLength() )
165 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
166 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
167 2 );
169 uno::Reference< uno::XInterface > xResult(
170 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
171 uno::UNO_QUERY );
173 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
175 if ( !xPersist.is() )
176 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
178 xPersist->setPersistentEntry( xStorage,
179 sEntName,
180 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
181 aMediaDescr,
182 lObjArgs );
184 return xResult;
187 //-------------------------------------------------------------------------
188 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
189 const uno::Sequence< sal_Int8 >& aClassID,
190 const ::rtl::OUString& aClassName,
191 const uno::Reference< embed::XStorage >& xStorage,
192 const ::rtl::OUString& sEntName,
193 const uno::Sequence< beans::PropertyValue >& lObjArgs )
194 throw ( lang::IllegalArgumentException,
195 io::IOException,
196 uno::Exception,
197 uno::RuntimeException)
199 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
201 if ( !xStorage.is() )
202 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
203 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
204 3 );
206 if ( !sEntName.getLength() )
207 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
208 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
209 4 );
211 uno::Reference< uno::XInterface > xResult(
212 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
213 uno::UNO_QUERY );
215 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
217 if ( !xPersist.is() )
218 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
220 xPersist->setPersistentEntry( xStorage,
221 sEntName,
222 embed::EntryInitModes::TRUNCATE_INIT,
223 uno::Sequence< beans::PropertyValue >(),
224 lObjArgs );
226 return xResult;
229 //-------------------------------------------------------------------------
230 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
231 const uno::Reference< embed::XStorage >& xStorage,
232 const ::rtl::OUString& sEntName,
233 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
234 const uno::Sequence< beans::PropertyValue >& lObjArgs )
235 throw ( lang::IllegalArgumentException,
236 io::IOException,
237 uno::Exception,
238 uno::RuntimeException )
240 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
242 if ( !xStorage.is() )
243 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
244 uno::Reference< uno::XInterface >(
245 static_cast< ::cppu::OWeakObject* >(this) ),
246 1 );
248 if ( !sEntName.getLength() )
249 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
250 uno::Reference< uno::XInterface >(
251 static_cast< ::cppu::OWeakObject* >(this) ),
252 2 );
254 uno::Reference< uno::XInterface > xResult(
255 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_True ) ),
256 uno::UNO_QUERY );
258 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
260 if ( !xPersist.is() )
261 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
263 xPersist->setPersistentEntry( xStorage,
264 sEntName,
265 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
266 aMediaDescr,
267 lObjArgs );
269 return xResult;
272 //-------------------------------------------------------------------------
273 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
274 const uno::Sequence< sal_Int8 >& aClassID,
275 const ::rtl::OUString& aClassName,
276 const uno::Reference< embed::XStorage >& xStorage,
277 const ::rtl::OUString& sEntName,
278 sal_Int32 /*nEntryConnectionMode*/,
279 const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
280 const uno::Sequence< beans::PropertyValue >& lObjArgs )
281 throw ( lang::IllegalArgumentException,
282 io::IOException,
283 uno::Exception,
284 uno::RuntimeException )
286 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
288 // the initialization is completelly controlled by user
289 if ( !xStorage.is() )
290 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
291 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
292 1 );
294 if ( !sEntName.getLength() )
295 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
296 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
297 2 );
299 uno::Reference< uno::XInterface > xResult(
300 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
301 uno::UNO_QUERY );
303 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
304 if ( xPersist.is() )
306 xPersist->setPersistentEntry( xStorage,
307 sEntName,
308 embed::EntryInitModes::DEFAULT_INIT,
309 uno::Sequence< beans::PropertyValue >(),
310 lObjArgs );
313 else
314 throw uno::RuntimeException(); // TODO:
316 return xResult;
319 //-------------------------------------------------------------------------
320 ::rtl::OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
321 throw ( uno::RuntimeException )
323 return impl_staticGetImplementationName();
326 //-------------------------------------------------------------------------
327 sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName )
328 throw ( uno::RuntimeException )
330 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
332 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
333 if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
334 return sal_True;
336 return sal_False;
339 //-------------------------------------------------------------------------
340 uno::Sequence< ::rtl::OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
341 throw ( uno::RuntimeException )
343 return impl_staticGetSupportedServiceNames();