1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_embeddedobj.hxx"
26 #include <com/sun/star/embed/ElementModes.hpp>
27 #include <com/sun/star/embed/EntryInitModes.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/embed/Aspects.hpp>
32
33 #include <rtl/logfile.hxx>
34
35
36 #include "xolefactory.hxx"
37 #include "oleembobj.hxx"
38
39
40 using namespace ::com::sun::star;
41
42 // TODO: do not create OLE objects that represent OOo documents
43
44 //-------------------------------------------------------------------------
impl_staticGetSupportedServiceNames()45 uno::Sequence< ::rtl::OUString > SAL_CALL OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
46 {
47 uno::Sequence< ::rtl::OUString > aRet(2);
48 aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.embed.OLEEmbeddedObjectFactory");
49 aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
50 return aRet;
51 }
52
53 //-------------------------------------------------------------------------
impl_staticGetImplementationName()54 ::rtl::OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
55 {
56 return ::rtl::OUString::createFromAscii("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
57 }
58
59 //-------------------------------------------------------------------------
impl_staticCreateSelfInstance(const uno::Reference<lang::XMultiServiceFactory> & xServiceManager)60 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
61 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
62 {
63 return uno::Reference< uno::XInterface >( *new OleEmbeddedObjectFactory( xServiceManager ) );
64 }
65
66 //-------------------------------------------------------------------------
createInstanceInitFromEntry(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> & aMedDescr,const uno::Sequence<beans::PropertyValue> & lObjArgs)67 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry(
68 const uno::Reference< embed::XStorage >& xStorage,
69 const ::rtl::OUString& sEntName,
70 const uno::Sequence< beans::PropertyValue >& aMedDescr,
71 const uno::Sequence< beans::PropertyValue >& lObjArgs )
72 throw ( lang::IllegalArgumentException,
73 container::NoSuchElementException,
74 io::IOException,
75 uno::Exception,
76 uno::RuntimeException)
77 {
78 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
79
80 if ( !xStorage.is() )
81 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
82 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
83 1 );
84
85 if ( !sEntName.getLength() )
86 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
87 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
88 2 );
89
90 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
91 if ( !xNameAccess.is() )
92 throw uno::RuntimeException(); //TODO
93
94 // detect entry existence
95 if ( !xNameAccess->hasByName( sEntName ) )
96 throw container::NoSuchElementException();
97
98 if ( !xStorage->isStreamElement( sEntName ) )
99 {
100 // if it is not an OLE object throw an exception
101 throw io::IOException(); // TODO:
102 }
103
104 uno::Reference< uno::XInterface > xResult(
105 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
106 uno::UNO_QUERY );
107
108 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
109
110 if ( !xPersist.is() )
111 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
112
113 xPersist->setPersistentEntry( xStorage,
114 sEntName,
115 embed::EntryInitModes::DEFAULT_INIT,
116 aMedDescr,
117 lObjArgs );
118
119 for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
120 {
121 if ( lObjArgs[nInd].Name.equalsAscii( "CloneFrom" ) )
122 {
123 try
124 {
125 uno::Reference < embed::XEmbeddedObject > xObj;
126 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
127 lObjArgs[nInd].Value >>= xObj;
128 if ( xObj.is() )
129 xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
130 }
131 catch ( uno::Exception& ) {};
132 break;
133 }
134 }
135
136 return xResult;
137 }
138
139 //-------------------------------------------------------------------------
createInstanceInitFromMediaDescriptor(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> & aMediaDescr,const uno::Sequence<beans::PropertyValue> & lObjArgs)140 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
141 const uno::Reference< embed::XStorage >& xStorage,
142 const ::rtl::OUString& sEntName,
143 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
144 const uno::Sequence< beans::PropertyValue >& lObjArgs )
145 throw ( lang::IllegalArgumentException,
146 io::IOException,
147 uno::Exception,
148 uno::RuntimeException)
149 {
150 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
151
152 if ( !xStorage.is() )
153 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
154 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
155 1 );
156
157 if ( !sEntName.getLength() )
158 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
159 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
160 2 );
161
162 uno::Reference< uno::XInterface > xResult(
163 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
164 uno::UNO_QUERY );
165
166 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
167
168 if ( !xPersist.is() )
169 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
170
171 xPersist->setPersistentEntry( xStorage,
172 sEntName,
173 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
174 aMediaDescr,
175 lObjArgs );
176
177 return xResult;
178 }
179
180 //-------------------------------------------------------------------------
createInstanceInitNew(const uno::Sequence<sal_Int8> & aClassID,const::rtl::OUString & aClassName,const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> & lObjArgs)181 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
182 const uno::Sequence< sal_Int8 >& aClassID,
183 const ::rtl::OUString& aClassName,
184 const uno::Reference< embed::XStorage >& xStorage,
185 const ::rtl::OUString& sEntName,
186 const uno::Sequence< beans::PropertyValue >& lObjArgs )
187 throw ( lang::IllegalArgumentException,
188 io::IOException,
189 uno::Exception,
190 uno::RuntimeException)
191 {
192 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
193
194 if ( !xStorage.is() )
195 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
196 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
197 3 );
198
199 if ( !sEntName.getLength() )
200 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
201 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
202 4 );
203
204 uno::Reference< uno::XInterface > xResult(
205 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
206 uno::UNO_QUERY );
207
208 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
209
210 if ( !xPersist.is() )
211 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
212
213 xPersist->setPersistentEntry( xStorage,
214 sEntName,
215 embed::EntryInitModes::TRUNCATE_INIT,
216 uno::Sequence< beans::PropertyValue >(),
217 lObjArgs );
218
219 return xResult;
220 }
221
222 //-------------------------------------------------------------------------
createInstanceLink(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> & aMediaDescr,const uno::Sequence<beans::PropertyValue> & lObjArgs)223 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
224 const uno::Reference< embed::XStorage >& xStorage,
225 const ::rtl::OUString& sEntName,
226 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
227 const uno::Sequence< beans::PropertyValue >& lObjArgs )
228 throw ( lang::IllegalArgumentException,
229 io::IOException,
230 uno::Exception,
231 uno::RuntimeException )
232 {
233 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
234
235 if ( !xStorage.is() )
236 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
237 uno::Reference< uno::XInterface >(
238 static_cast< ::cppu::OWeakObject* >(this) ),
239 1 );
240
241 if ( !sEntName.getLength() )
242 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
243 uno::Reference< uno::XInterface >(
244 static_cast< ::cppu::OWeakObject* >(this) ),
245 2 );
246
247 uno::Reference< uno::XInterface > xResult(
248 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_True ) ),
249 uno::UNO_QUERY );
250
251 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
252
253 if ( !xPersist.is() )
254 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
255
256 xPersist->setPersistentEntry( xStorage,
257 sEntName,
258 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
259 aMediaDescr,
260 lObjArgs );
261
262 return xResult;
263 }
264
265 //-------------------------------------------------------------------------
createInstanceUserInit(const uno::Sequence<sal_Int8> & aClassID,const::rtl::OUString & aClassName,const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,sal_Int32,const uno::Sequence<beans::PropertyValue> &,const uno::Sequence<beans::PropertyValue> & lObjArgs)266 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
267 const uno::Sequence< sal_Int8 >& aClassID,
268 const ::rtl::OUString& aClassName,
269 const uno::Reference< embed::XStorage >& xStorage,
270 const ::rtl::OUString& sEntName,
271 sal_Int32 /*nEntryConnectionMode*/,
272 const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
273 const uno::Sequence< beans::PropertyValue >& lObjArgs )
274 throw ( lang::IllegalArgumentException,
275 io::IOException,
276 uno::Exception,
277 uno::RuntimeException )
278 {
279 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
280
281 // the initialization is completelly controlled by user
282 if ( !xStorage.is() )
283 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
284 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
285 1 );
286
287 if ( !sEntName.getLength() )
288 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
289 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
290 2 );
291
292 uno::Reference< uno::XInterface > xResult(
293 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
294 uno::UNO_QUERY );
295
296 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
297 if ( xPersist.is() )
298 {
299 xPersist->setPersistentEntry( xStorage,
300 sEntName,
301 embed::EntryInitModes::DEFAULT_INIT,
302 uno::Sequence< beans::PropertyValue >(),
303 lObjArgs );
304
305 }
306 else
307 throw uno::RuntimeException(); // TODO:
308
309 return xResult;
310 }
311
312 //-------------------------------------------------------------------------
getImplementationName()313 ::rtl::OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
314 throw ( uno::RuntimeException )
315 {
316 return impl_staticGetImplementationName();
317 }
318
319 //-------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)320 sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName )
321 throw ( uno::RuntimeException )
322 {
323 uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
324
325 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
326 if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
327 return sal_True;
328
329 return sal_False;
330 }
331
332 //-------------------------------------------------------------------------
getSupportedServiceNames()333 uno::Sequence< ::rtl::OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
334 throw ( uno::RuntimeException )
335 {
336 return impl_staticGetSupportedServiceNames();
337 }
338
339