bump product version to 4.1.6.2
[LibreOffice.git] / embeddedobj / source / msole / xolefactory.cxx
blobfb3baeb05e667df2d75bbecad3b9bcc04d3f393c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/embed/ElementModes.hpp>
21 #include <com/sun/star/embed/EntryInitModes.hpp>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/embed/Aspects.hpp>
27 #include <rtl/logfile.hxx>
30 #include "xolefactory.hxx"
31 #include "oleembobj.hxx"
34 using namespace ::com::sun::star;
36 // TODO: do not create OLE objects that represent OOo documents
38 //-------------------------------------------------------------------------
39 uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
41 uno::Sequence< OUString > aRet(2);
42 aRet[0] = OUString("com.sun.star.embed.OLEEmbeddedObjectFactory");
43 aRet[1] = OUString("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
44 return aRet;
47 //-------------------------------------------------------------------------
48 OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
50 return OUString("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
53 //-------------------------------------------------------------------------
54 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
55 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
57 return uno::Reference< uno::XInterface >( *new OleEmbeddedObjectFactory( xServiceManager ) );
60 //-------------------------------------------------------------------------
61 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry(
62 const uno::Reference< embed::XStorage >& xStorage,
63 const OUString& sEntName,
64 const uno::Sequence< beans::PropertyValue >& aMedDescr,
65 const uno::Sequence< beans::PropertyValue >& lObjArgs )
66 throw ( lang::IllegalArgumentException,
67 container::NoSuchElementException,
68 io::IOException,
69 uno::Exception,
70 uno::RuntimeException)
72 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
74 if ( !xStorage.is() )
75 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
76 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
77 1 );
79 if ( sEntName.isEmpty() )
80 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
81 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
82 2 );
84 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
85 if ( !xNameAccess.is() )
86 throw uno::RuntimeException(); //TODO
88 // detect entry existence
89 if ( !xNameAccess->hasByName( sEntName ) )
90 throw container::NoSuchElementException();
92 if ( !xStorage->isStreamElement( sEntName ) )
94 // if it is not an OLE object throw an exception
95 throw io::IOException(); // TODO:
98 uno::Reference< uno::XInterface > xResult(
99 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
100 uno::UNO_QUERY );
102 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
104 if ( !xPersist.is() )
105 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
107 xPersist->setPersistentEntry( xStorage,
108 sEntName,
109 embed::EntryInitModes::DEFAULT_INIT,
110 aMedDescr,
111 lObjArgs );
113 for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
115 if ( lObjArgs[nInd].Name == "CloneFrom" )
119 uno::Reference < embed::XEmbeddedObject > xObj;
120 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
121 lObjArgs[nInd].Value >>= xObj;
122 if ( xObj.is() )
123 xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
125 catch ( const uno::Exception& ) {}
126 break;
130 return xResult;
133 //-------------------------------------------------------------------------
134 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
135 const uno::Reference< embed::XStorage >& xStorage,
136 const OUString& sEntName,
137 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
138 const uno::Sequence< beans::PropertyValue >& lObjArgs )
139 throw ( lang::IllegalArgumentException,
140 io::IOException,
141 uno::Exception,
142 uno::RuntimeException)
144 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
146 if ( !xStorage.is() )
147 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
148 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
149 1 );
151 if ( sEntName.isEmpty() )
152 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
153 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
154 2 );
156 uno::Reference< uno::XInterface > xResult(
157 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
158 uno::UNO_QUERY );
160 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
162 if ( !xPersist.is() )
163 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
165 xPersist->setPersistentEntry( xStorage,
166 sEntName,
167 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
168 aMediaDescr,
169 lObjArgs );
171 return xResult;
174 //-------------------------------------------------------------------------
175 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
176 const uno::Sequence< sal_Int8 >& aClassID,
177 const OUString& aClassName,
178 const uno::Reference< embed::XStorage >& xStorage,
179 const OUString& sEntName,
180 const uno::Sequence< beans::PropertyValue >& lObjArgs )
181 throw ( lang::IllegalArgumentException,
182 io::IOException,
183 uno::Exception,
184 uno::RuntimeException)
186 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
188 if ( !xStorage.is() )
189 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
190 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
191 3 );
193 if ( sEntName.isEmpty() )
194 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
195 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
196 4 );
198 uno::Reference< uno::XInterface > xResult(
199 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
200 uno::UNO_QUERY );
202 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
204 if ( !xPersist.is() )
205 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
207 xPersist->setPersistentEntry( xStorage,
208 sEntName,
209 embed::EntryInitModes::TRUNCATE_INIT,
210 uno::Sequence< beans::PropertyValue >(),
211 lObjArgs );
213 return xResult;
216 //-------------------------------------------------------------------------
217 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
218 const uno::Reference< embed::XStorage >& xStorage,
219 const OUString& sEntName,
220 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
221 const uno::Sequence< beans::PropertyValue >& lObjArgs )
222 throw ( lang::IllegalArgumentException,
223 io::IOException,
224 uno::Exception,
225 uno::RuntimeException )
227 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
229 if ( !xStorage.is() )
230 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
231 uno::Reference< uno::XInterface >(
232 static_cast< ::cppu::OWeakObject* >(this) ),
233 1 );
235 if ( sEntName.isEmpty() )
236 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
237 uno::Reference< uno::XInterface >(
238 static_cast< ::cppu::OWeakObject* >(this) ),
239 2 );
241 uno::Reference< uno::XInterface > xResult(
242 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_True ) ),
243 uno::UNO_QUERY );
245 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
247 if ( !xPersist.is() )
248 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
250 xPersist->setPersistentEntry( xStorage,
251 sEntName,
252 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
253 aMediaDescr,
254 lObjArgs );
256 return xResult;
259 //-------------------------------------------------------------------------
260 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
261 const uno::Sequence< sal_Int8 >& aClassID,
262 const OUString& aClassName,
263 const uno::Reference< embed::XStorage >& xStorage,
264 const OUString& sEntName,
265 sal_Int32 /*nEntryConnectionMode*/,
266 const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
267 const uno::Sequence< beans::PropertyValue >& lObjArgs )
268 throw ( lang::IllegalArgumentException,
269 io::IOException,
270 uno::Exception,
271 uno::RuntimeException )
273 RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
275 // the initialization is completelly controlled by user
276 if ( !xStorage.is() )
277 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
278 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
279 1 );
281 if ( sEntName.isEmpty() )
282 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
283 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
284 2 );
286 uno::Reference< uno::XInterface > xResult(
287 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
288 uno::UNO_QUERY );
290 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
291 if ( xPersist.is() )
293 xPersist->setPersistentEntry( xStorage,
294 sEntName,
295 embed::EntryInitModes::DEFAULT_INIT,
296 uno::Sequence< beans::PropertyValue >(),
297 lObjArgs );
300 else
301 throw uno::RuntimeException(); // TODO:
303 return xResult;
306 //-------------------------------------------------------------------------
307 OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
308 throw ( uno::RuntimeException )
310 return impl_staticGetImplementationName();
313 //-------------------------------------------------------------------------
314 sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const OUString& ServiceName )
315 throw ( uno::RuntimeException )
317 uno::Sequence< OUString > aSeq = impl_staticGetSupportedServiceNames();
319 for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
320 if ( ServiceName == aSeq[nInd] )
321 return sal_True;
323 return sal_False;
326 //-------------------------------------------------------------------------
327 uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
328 throw ( uno::RuntimeException )
330 return impl_staticGetSupportedServiceNames();
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */