1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xolefactory.cxx,v $
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");
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
,
83 uno::RuntimeException
)
85 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
88 throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
89 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
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) ),
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
) ),
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
,
122 embed::EntryInitModes::DEFAULT_INIT
,
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
;
136 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
138 catch ( uno::Exception
& ) {};
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
,
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) ),
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) ),
169 uno::Reference
< uno::XInterface
> xResult(
170 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_False
) ),
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
,
180 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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) ),
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) ),
211 uno::Reference
< uno::XInterface
> xResult(
212 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
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
,
222 embed::EntryInitModes::TRUNCATE_INIT
,
223 uno::Sequence
< beans::PropertyValue
>(),
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
,
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) ),
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) ),
254 uno::Reference
< uno::XInterface
> xResult(
255 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_True
) ),
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
,
265 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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) ),
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) ),
299 uno::Reference
< uno::XInterface
> xResult(
300 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
303 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
306 xPersist
->setPersistentEntry( xStorage
,
308 embed::EntryInitModes::DEFAULT_INIT
,
309 uno::Sequence
< beans::PropertyValue
>(),
314 throw uno::RuntimeException(); // TODO:
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 )
339 //-------------------------------------------------------------------------
340 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OleEmbeddedObjectFactory::getSupportedServiceNames()
341 throw ( uno::RuntimeException
)
343 return impl_staticGetSupportedServiceNames();