1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
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>
36 #include <rtl/logfile.hxx>
39 #include "xolefactory.hxx"
40 #include "oleembobj.hxx"
43 using namespace ::com::sun::star
;
45 // TODO: do not create OLE objects that represent OOo documents
47 //-------------------------------------------------------------------------
48 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
50 uno::Sequence
< ::rtl::OUString
> aRet(2);
51 aRet
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OLEEmbeddedObjectFactory"));
52 aRet
[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.OLEEmbeddedObjectFactory"));
56 //-------------------------------------------------------------------------
57 ::rtl::OUString SAL_CALL
OleEmbeddedObjectFactory::impl_staticGetImplementationName()
59 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.OLEEmbeddedObjectFactory"));
62 //-------------------------------------------------------------------------
63 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
64 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
66 return uno::Reference
< uno::XInterface
>( *new OleEmbeddedObjectFactory( xServiceManager
) );
69 //-------------------------------------------------------------------------
70 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
,
79 uno::RuntimeException
)
81 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
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) ),
88 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) ),
93 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY
);
94 if ( !xNameAccess
.is() )
95 throw uno::RuntimeException(); //TODO
97 // detect entry existence
98 if ( !xNameAccess
->hasByName( sEntName
) )
99 throw container::NoSuchElementException();
101 if ( !xStorage
->isStreamElement( sEntName
) )
103 // if it is not an OLE object throw an exception
104 throw io::IOException(); // TODO:
107 uno::Reference
< uno::XInterface
> xResult(
108 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_False
) ),
111 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
113 if ( !xPersist
.is() )
114 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
116 xPersist
->setPersistentEntry( xStorage
,
118 embed::EntryInitModes::DEFAULT_INIT
,
122 for ( sal_Int32 nInd
= 0; nInd
< lObjArgs
.getLength(); nInd
++ )
124 if ( lObjArgs
[nInd
].Name
== "CloneFrom" )
128 uno::Reference
< embed::XEmbeddedObject
> xObj
;
129 uno::Reference
< embed::XEmbeddedObject
> xNew( xResult
, uno::UNO_QUERY
);
130 lObjArgs
[nInd
].Value
>>= xObj
;
132 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
134 catch ( const uno::Exception
& ) {}
142 //-------------------------------------------------------------------------
143 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
,
151 uno::RuntimeException
)
153 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
155 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) ),
160 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) ),
165 uno::Reference
< uno::XInterface
> xResult(
166 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_False
) ),
169 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
171 if ( !xPersist
.is() )
172 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
174 xPersist
->setPersistentEntry( xStorage
,
176 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
183 //-------------------------------------------------------------------------
184 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
,
193 uno::RuntimeException
)
195 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
197 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) ),
202 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) ),
207 uno::Reference
< uno::XInterface
> xResult(
208 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
211 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
213 if ( !xPersist
.is() )
214 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
216 xPersist
->setPersistentEntry( xStorage
,
218 embed::EntryInitModes::TRUNCATE_INIT
,
219 uno::Sequence
< beans::PropertyValue
>(),
225 //-------------------------------------------------------------------------
226 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
,
234 uno::RuntimeException
)
236 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
238 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) ),
244 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) ),
250 uno::Reference
< uno::XInterface
> xResult(
251 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_True
) ),
254 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
256 if ( !xPersist
.is() )
257 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
259 xPersist
->setPersistentEntry( xStorage
,
261 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
268 //-------------------------------------------------------------------------
269 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
,
280 uno::RuntimeException
)
282 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
284 // the initialization is completelly controlled by user
285 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) ),
290 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) ),
295 uno::Reference
< uno::XInterface
> xResult(
296 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
299 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
302 xPersist
->setPersistentEntry( xStorage
,
304 embed::EntryInitModes::DEFAULT_INIT
,
305 uno::Sequence
< beans::PropertyValue
>(),
310 throw uno::RuntimeException(); // TODO:
315 //-------------------------------------------------------------------------
316 ::rtl::OUString SAL_CALL
OleEmbeddedObjectFactory::getImplementationName()
317 throw ( uno::RuntimeException
)
319 return impl_staticGetImplementationName();
322 //-------------------------------------------------------------------------
323 sal_Bool SAL_CALL
OleEmbeddedObjectFactory::supportsService( const ::rtl::OUString
& ServiceName
)
324 throw ( uno::RuntimeException
)
326 uno::Sequence
< ::rtl::OUString
> aSeq
= impl_staticGetSupportedServiceNames();
328 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
329 if ( ServiceName
.compareTo( aSeq
[nInd
] ) == 0 )
335 //-------------------------------------------------------------------------
336 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OleEmbeddedObjectFactory::getSupportedServiceNames()
337 throw ( uno::RuntimeException
)
339 return impl_staticGetSupportedServiceNames();
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */