1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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");
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
,
70 uno::RuntimeException
)
72 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
75 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
76 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
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) ),
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
) ),
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
,
109 embed::EntryInitModes::DEFAULT_INIT
,
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
;
123 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
125 catch ( const uno::Exception
& ) {}
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
,
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) ),
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) ),
156 uno::Reference
< uno::XInterface
> xResult(
157 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_False
) ),
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
,
167 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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) ),
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) ),
198 uno::Reference
< uno::XInterface
> xResult(
199 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
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
,
209 embed::EntryInitModes::TRUNCATE_INIT
,
210 uno::Sequence
< beans::PropertyValue
>(),
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
,
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) ),
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) ),
241 uno::Reference
< uno::XInterface
> xResult(
242 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_True
) ),
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
,
252 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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) ),
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) ),
286 uno::Reference
< uno::XInterface
> xResult(
287 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
290 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
293 xPersist
->setPersistentEntry( xStorage
,
295 embed::EntryInitModes::DEFAULT_INIT
,
296 uno::Sequence
< beans::PropertyValue
>(),
301 throw uno::RuntimeException(); // TODO:
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
] )
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: */