Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/embed/ElementModes.hpp>
30 : : #include <com/sun/star/embed/EntryInitModes.hpp>
31 : : #include <com/sun/star/beans/PropertyValue.hpp>
32 : : #include <com/sun/star/beans/XPropertySet.hpp>
33 : : #include <com/sun/star/container/XNameAccess.hpp>
34 : : #include <com/sun/star/embed/Aspects.hpp>
35 : :
36 : : #include <rtl/logfile.hxx>
37 : :
38 : :
39 : : #include "xolefactory.hxx"
40 : : #include "oleembobj.hxx"
41 : :
42 : :
43 : : using namespace ::com::sun::star;
44 : :
45 : : // TODO: do not create OLE objects that represent OOo documents
46 : :
47 : : //-------------------------------------------------------------------------
48 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
49 : : {
50 : 0 : uno::Sequence< ::rtl::OUString > aRet(2);
51 [ # # ][ # # ]: 0 : aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OLEEmbeddedObjectFactory"));
52 [ # # ][ # # ]: 0 : aRet[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.OLEEmbeddedObjectFactory"));
53 : 0 : return aRet;
54 : : }
55 : :
56 : : //-------------------------------------------------------------------------
57 : 0 : ::rtl::OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
58 : : {
59 : 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.OLEEmbeddedObjectFactory"));
60 : : }
61 : :
62 : : //-------------------------------------------------------------------------
63 : 0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
64 : : const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
65 : : {
66 [ # # ]: 0 : return uno::Reference< uno::XInterface >( *new OleEmbeddedObjectFactory( xServiceManager ) );
67 : : }
68 : :
69 : : //-------------------------------------------------------------------------
70 : 0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry(
71 : : const uno::Reference< embed::XStorage >& xStorage,
72 : : const ::rtl::OUString& sEntName,
73 : : const uno::Sequence< beans::PropertyValue >& aMedDescr,
74 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
75 : : throw ( lang::IllegalArgumentException,
76 : : container::NoSuchElementException,
77 : : io::IOException,
78 : : uno::Exception,
79 : : uno::RuntimeException)
80 : : {
81 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
82 : :
83 [ # # ]: 0 : if ( !xStorage.is() )
84 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
85 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
86 [ # # ][ # # ]: 0 : 1 );
[ # # ]
87 : :
88 [ # # ]: 0 : if ( sEntName.isEmpty() )
89 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
90 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
91 [ # # ][ # # ]: 0 : 2 );
[ # # ]
92 : :
93 [ # # ]: 0 : uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
94 [ # # ]: 0 : if ( !xNameAccess.is() )
95 [ # # ]: 0 : throw uno::RuntimeException(); //TODO
96 : :
97 : : // detect entry existence
98 [ # # ][ # # ]: 0 : if ( !xNameAccess->hasByName( sEntName ) )
[ # # ]
99 [ # # ]: 0 : throw container::NoSuchElementException();
100 : :
101 [ # # ][ # # ]: 0 : if ( !xStorage->isStreamElement( sEntName ) )
[ # # ]
102 : : {
103 : : // if it is not an OLE object throw an exception
104 [ # # ]: 0 : throw io::IOException(); // TODO:
105 : : }
106 : :
107 : : uno::Reference< uno::XInterface > xResult(
108 [ # # ]: 0 : static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
109 [ # # ]: 0 : uno::UNO_QUERY );
110 : :
111 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
112 : :
113 [ # # ]: 0 : if ( !xPersist.is() )
114 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
115 : :
116 [ # # ]: 0 : xPersist->setPersistentEntry( xStorage,
117 : : sEntName,
118 : : embed::EntryInitModes::DEFAULT_INIT,
119 : : aMedDescr,
120 [ # # ]: 0 : lObjArgs );
121 : :
122 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
123 : : {
124 [ # # ]: 0 : if ( lObjArgs[nInd].Name == "CloneFrom" )
125 : : {
126 : : try
127 : : {
128 : 0 : uno::Reference < embed::XEmbeddedObject > xObj;
129 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
130 [ # # ]: 0 : lObjArgs[nInd].Value >>= xObj;
131 [ # # ]: 0 : if ( xObj.is() )
132 [ # # ][ # # ]: 0 : xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
[ # # ][ # # ]
[ # # ]
133 : : }
134 [ # # ]: 0 : catch ( const uno::Exception& ) {}
135 : 0 : break;
136 : : }
137 : : }
138 : :
139 : 0 : return xResult;
140 : : }
141 : :
142 : : //-------------------------------------------------------------------------
143 : 0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
144 : : const uno::Reference< embed::XStorage >& xStorage,
145 : : const ::rtl::OUString& sEntName,
146 : : const uno::Sequence< beans::PropertyValue >& aMediaDescr,
147 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
148 : : throw ( lang::IllegalArgumentException,
149 : : io::IOException,
150 : : uno::Exception,
151 : : uno::RuntimeException)
152 : : {
153 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
154 : :
155 [ # # ]: 0 : if ( !xStorage.is() )
156 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
157 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
158 [ # # ][ # # ]: 0 : 1 );
[ # # ]
159 : :
160 [ # # ]: 0 : if ( sEntName.isEmpty() )
161 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
162 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
163 [ # # ][ # # ]: 0 : 2 );
[ # # ]
164 : :
165 : : uno::Reference< uno::XInterface > xResult(
166 [ # # ]: 0 : static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
167 [ # # ]: 0 : uno::UNO_QUERY );
168 : :
169 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
170 : :
171 [ # # ]: 0 : if ( !xPersist.is() )
172 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
173 : :
174 [ # # ]: 0 : xPersist->setPersistentEntry( xStorage,
175 : : sEntName,
176 : : embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
177 : : aMediaDescr,
178 [ # # ]: 0 : lObjArgs );
179 : :
180 : 0 : return xResult;
181 : : }
182 : :
183 : : //-------------------------------------------------------------------------
184 : 0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
185 : : const uno::Sequence< sal_Int8 >& aClassID,
186 : : const ::rtl::OUString& aClassName,
187 : : const uno::Reference< embed::XStorage >& xStorage,
188 : : const ::rtl::OUString& sEntName,
189 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
190 : : throw ( lang::IllegalArgumentException,
191 : : io::IOException,
192 : : uno::Exception,
193 : : uno::RuntimeException)
194 : : {
195 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
196 : :
197 [ # # ]: 0 : if ( !xStorage.is() )
198 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
199 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
200 [ # # ][ # # ]: 0 : 3 );
[ # # ]
201 : :
202 [ # # ]: 0 : if ( sEntName.isEmpty() )
203 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
204 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
205 [ # # ][ # # ]: 0 : 4 );
[ # # ]
206 : :
207 : : uno::Reference< uno::XInterface > xResult(
208 [ # # ]: 0 : static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
209 [ # # ]: 0 : uno::UNO_QUERY );
210 : :
211 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
212 : :
213 [ # # ]: 0 : if ( !xPersist.is() )
214 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
215 : :
216 [ # # ]: 0 : xPersist->setPersistentEntry( xStorage,
217 : : sEntName,
218 : : embed::EntryInitModes::TRUNCATE_INIT,
219 : : uno::Sequence< beans::PropertyValue >(),
220 [ # # ][ # # ]: 0 : lObjArgs );
[ # # ]
221 : :
222 : 0 : return xResult;
223 : : }
224 : :
225 : : //-------------------------------------------------------------------------
226 : 0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
227 : : const uno::Reference< embed::XStorage >& xStorage,
228 : : const ::rtl::OUString& sEntName,
229 : : const uno::Sequence< beans::PropertyValue >& aMediaDescr,
230 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
231 : : throw ( lang::IllegalArgumentException,
232 : : io::IOException,
233 : : uno::Exception,
234 : : uno::RuntimeException )
235 : : {
236 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
237 : :
238 [ # # ]: 0 : if ( !xStorage.is() )
239 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
240 : : uno::Reference< uno::XInterface >(
241 : : static_cast< ::cppu::OWeakObject* >(this) ),
242 [ # # ][ # # ]: 0 : 1 );
[ # # ]
243 : :
244 [ # # ]: 0 : if ( sEntName.isEmpty() )
245 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
246 : : uno::Reference< uno::XInterface >(
247 : : static_cast< ::cppu::OWeakObject* >(this) ),
248 [ # # ][ # # ]: 0 : 2 );
[ # # ]
249 : :
250 : : uno::Reference< uno::XInterface > xResult(
251 [ # # ]: 0 : static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_True ) ),
252 [ # # ]: 0 : uno::UNO_QUERY );
253 : :
254 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
255 : :
256 [ # # ]: 0 : if ( !xPersist.is() )
257 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
258 : :
259 [ # # ]: 0 : xPersist->setPersistentEntry( xStorage,
260 : : sEntName,
261 : : embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
262 : : aMediaDescr,
263 [ # # ]: 0 : lObjArgs );
264 : :
265 : 0 : return xResult;
266 : : }
267 : :
268 : : //-------------------------------------------------------------------------
269 : 0 : uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
270 : : const uno::Sequence< sal_Int8 >& aClassID,
271 : : const ::rtl::OUString& aClassName,
272 : : const uno::Reference< embed::XStorage >& xStorage,
273 : : const ::rtl::OUString& sEntName,
274 : : sal_Int32 /*nEntryConnectionMode*/,
275 : : const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
276 : : const uno::Sequence< beans::PropertyValue >& lObjArgs )
277 : : throw ( lang::IllegalArgumentException,
278 : : io::IOException,
279 : : uno::Exception,
280 : : uno::RuntimeException )
281 : : {
282 : : RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
283 : :
284 : : // the initialization is completelly controlled by user
285 [ # # ]: 0 : if ( !xStorage.is() )
286 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No parent storage is provided!\n" )),
287 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
288 [ # # ][ # # ]: 0 : 1 );
[ # # ]
289 : :
290 [ # # ]: 0 : if ( sEntName.isEmpty() )
291 : : throw lang::IllegalArgumentException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Empty element name is provided!\n" )),
292 : : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
293 [ # # ][ # # ]: 0 : 2 );
[ # # ]
294 : :
295 : : uno::Reference< uno::XInterface > xResult(
296 [ # # ]: 0 : static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
297 [ # # ]: 0 : uno::UNO_QUERY );
298 : :
299 [ # # ]: 0 : uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
300 [ # # ]: 0 : if ( xPersist.is() )
301 : : {
302 [ # # ]: 0 : xPersist->setPersistentEntry( xStorage,
303 : : sEntName,
304 : : embed::EntryInitModes::DEFAULT_INIT,
305 : : uno::Sequence< beans::PropertyValue >(),
306 [ # # ][ # # ]: 0 : lObjArgs );
[ # # ]
307 : :
308 : : }
309 : : else
310 [ # # ]: 0 : throw uno::RuntimeException(); // TODO:
311 : :
312 : 0 : return xResult;
313 : : }
314 : :
315 : : //-------------------------------------------------------------------------
316 : 0 : ::rtl::OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
317 : : throw ( uno::RuntimeException )
318 : : {
319 : 0 : return impl_staticGetImplementationName();
320 : : }
321 : :
322 : : //-------------------------------------------------------------------------
323 : 0 : sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const ::rtl::OUString& ServiceName )
324 : : throw ( uno::RuntimeException )
325 : : {
326 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
327 : :
328 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
329 [ # # ][ # # ]: 0 : if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
330 : 0 : return sal_True;
331 : :
332 [ # # ]: 0 : return sal_False;
333 : : }
334 : :
335 : : //-------------------------------------------------------------------------
336 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
337 : : throw ( uno::RuntimeException )
338 : : {
339 : 0 : return impl_staticGetSupportedServiceNames();
340 : : }
341 : :
342 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|