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/document/XTypeDetection.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <comphelper/documentconstants.hxx>
31 #include "xfactory.hxx"
32 #include "commonembobj.hxx"
33 #include "specialobject.hxx"
34 #include "oleembobj.hxx"
37 using namespace ::com::sun::star
;
39 uno::Sequence
< OUString
> SAL_CALL
OOoEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
41 uno::Sequence
< OUString
> aRet(2);
42 aRet
[0] = "com.sun.star.embed.OOoEmbeddedObjectFactory";
43 aRet
[1] = "com.sun.star.comp.embed.OOoEmbeddedObjectFactory";
47 OUString SAL_CALL
OOoEmbeddedObjectFactory::impl_staticGetImplementationName()
49 return OUString("com.sun.star.comp.embed.OOoEmbeddedObjectFactory");
52 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::impl_staticCreateSelfInstance(
53 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
55 return uno::Reference
< uno::XInterface
>( *new OOoEmbeddedObjectFactory( comphelper::getComponentContext(xServiceManager
) ) );
58 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitFromEntry(
59 const uno::Reference
< embed::XStorage
>& xStorage
,
60 const OUString
& sEntName
,
61 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
62 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
63 throw ( lang::IllegalArgumentException
,
64 container::NoSuchElementException
,
67 uno::RuntimeException
, std::exception
)
70 throw lang::IllegalArgumentException( "No parent storage is provided!",
71 static_cast< ::cppu::OWeakObject
* >(this),
74 if ( sEntName
.isEmpty() )
75 throw lang::IllegalArgumentException( "Empty element name is provided!",
76 static_cast< ::cppu::OWeakObject
* >(this),
79 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY
);
80 if ( !xNameAccess
.is() )
81 throw uno::RuntimeException(); //TODO
83 // detect entry existence
84 if ( !xNameAccess
->hasByName( sEntName
) )
85 throw container::NoSuchElementException();
87 uno::Reference
< uno::XInterface
> xResult
;
88 if ( xStorage
->isStorageElement( sEntName
) )
90 // the object must be based on storage
91 uno::Reference
< embed::XStorage
> xSubStorage
=
92 xStorage
->openStorageElement( sEntName
, embed::ElementModes::READ
);
94 uno::Reference
< beans::XPropertySet
> xPropSet( xSubStorage
, uno::UNO_QUERY
);
96 throw uno::RuntimeException();
100 uno::Any aAny
= xPropSet
->getPropertyValue("MediaType");
103 catch ( const uno::Exception
& )
108 uno::Reference
< lang::XComponent
> xComp( xSubStorage
, uno::UNO_QUERY
);
112 catch ( const uno::Exception
& )
117 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByMediaType( aMediaType
);
119 // If the sequence is empty, fall back to the FileFormatVersion=6200 filter, Base only has that.
120 if (!aObject
.hasElements() && aMediaType
== MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII
)
121 aObject
= m_aConfigHelper
.GetObjectPropsByMediaType(MIMETYPE_VND_SUN_XML_BASE_ASCII
);
123 if ( !aObject
.getLength() )
124 throw io::IOException(); // unexpected mimetype of the storage
126 xResult
.set(static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
133 // the object must be OOo embedded object, if it is not an exception must be thrown
134 throw io::IOException(); // TODO:
137 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
139 if ( !xPersist
.is() )
140 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
142 xPersist
->setPersistentEntry( xStorage
,
144 embed::EntryInitModes::DEFAULT_INIT
,
151 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
152 const uno::Reference
< embed::XStorage
>& xStorage
,
153 const OUString
& sEntName
,
154 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
155 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
156 throw ( lang::IllegalArgumentException
,
159 uno::RuntimeException
, std::exception
)
161 if ( !xStorage
.is() )
162 throw lang::IllegalArgumentException( "No parent storage is provided!",
163 static_cast< ::cppu::OWeakObject
* >(this),
166 if ( sEntName
.isEmpty() )
167 throw lang::IllegalArgumentException( "Empty element name is provided!",
168 static_cast< ::cppu::OWeakObject
* >(this),
171 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( aMediaDescr
);
173 // check if there is FilterName
174 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, false );
176 uno::Reference
< uno::XInterface
> xResult
;
178 // find document service name
179 if ( !aFilterName
.isEmpty() )
181 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByFilter( aFilterName
);
182 if ( !aObject
.getLength() )
183 throw io::IOException(); // unexpected mimetype of the storage
186 xResult
.set(static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
193 // the object must be OOo embedded object, if it is not an exception must be thrown
194 throw io::IOException(); // TODO:
197 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
199 if ( !xPersist
.is() )
200 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
202 xPersist
->setPersistentEntry( xStorage
,
204 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
211 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitNew(
212 const uno::Sequence
< sal_Int8
>& aClassID
,
213 const OUString
& /*aClassName*/,
214 const uno::Reference
< embed::XStorage
>& xStorage
,
215 const OUString
& sEntName
,
216 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
217 throw ( lang::IllegalArgumentException
,
220 uno::RuntimeException
, std::exception
)
222 uno::Reference
< uno::XInterface
> xResult
;
224 if ( !xStorage
.is() )
225 throw lang::IllegalArgumentException( "No parent storage is provided!",
226 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
229 if ( sEntName
.isEmpty() )
230 throw lang::IllegalArgumentException( "Empty element name is provided!",
231 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
234 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
235 if ( !aObject
.getLength() )
236 throw io::IOException(); // unexpected mimetype of the storage
238 xResult
.set( static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
244 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
246 if ( !xPersist
.is() )
247 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
249 xPersist
->setPersistentEntry( xStorage
,
251 embed::EntryInitModes::TRUNCATE_INIT
,
252 uno::Sequence
< beans::PropertyValue
>(),
258 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceUserInit(
259 const uno::Sequence
< sal_Int8
>& aClassID
,
260 const OUString
& /*aClassName*/,
261 const uno::Reference
< embed::XStorage
>& xStorage
,
262 const OUString
& sEntName
,
263 sal_Int32 nEntryConnectionMode
,
264 const uno::Sequence
< beans::PropertyValue
>& lArguments
,
265 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
266 throw ( lang::IllegalArgumentException
,
269 uno::RuntimeException
, std::exception
)
271 // the initialization is completely controlled by user
272 if ( !xStorage
.is() )
273 throw lang::IllegalArgumentException( "No parent storage is provided!",
274 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
277 if ( sEntName
.isEmpty() )
278 throw lang::IllegalArgumentException( "Empty element name is provided!",
279 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
282 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
283 if ( !aObject
.getLength() )
284 throw io::IOException(); // unexpected mimetype of the storage
286 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( lArguments
);
287 if ( nEntryConnectionMode
== embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
)
289 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, aObject
);
290 if ( aFilterName
.isEmpty() )
291 // the object must be OOo embedded object, if it is not an exception must be thrown
292 throw io::IOException(); // TODO:
295 uno::Reference
< uno::XInterface
> xResult(
296 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
301 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
304 xPersist
->setPersistentEntry( xStorage
,
306 nEntryConnectionMode
,
312 throw uno::RuntimeException(); // TODO:
317 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceLink(
318 const uno::Reference
< embed::XStorage
>& /*xStorage*/,
319 const OUString
& /*sEntName*/,
320 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
321 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
322 throw ( lang::IllegalArgumentException
,
325 uno::RuntimeException
, std::exception
)
327 uno::Reference
< uno::XInterface
> xResult
;
329 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( aMediaDescr
);
331 // check if there is URL, URL must exist
333 for ( sal_Int32 nInd
= 0; nInd
< aTempMedDescr
.getLength(); nInd
++ )
334 if ( aTempMedDescr
[nInd
].Name
== "URL" )
335 aTempMedDescr
[nInd
].Value
>>= aURL
;
337 if ( aURL
.isEmpty() )
338 throw lang::IllegalArgumentException( "No URL for the link is provided!",
339 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
342 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, false );
344 if ( !aFilterName
.isEmpty() )
346 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByFilter( aFilterName
);
347 if ( !aObject
.getLength() )
348 throw io::IOException(); // unexpected mimetype of the storage
351 xResult
.set(static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
360 // the object must be OOo embedded object, if it is not an exception must be thrown
361 throw io::IOException(); // TODO:
367 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceLinkUserInit(
368 const uno::Sequence
< sal_Int8
>& aClassID
,
369 const OUString
& /*aClassName*/,
370 const uno::Reference
< embed::XStorage
>& xStorage
,
371 const OUString
& sEntName
,
372 const uno::Sequence
< beans::PropertyValue
>& lArguments
,
373 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
374 throw ( lang::IllegalArgumentException
,
377 uno::RuntimeException
,
380 uno::Reference
< uno::XInterface
> xResult
;
382 // the initialization is completely controlled by user
383 if ( !xStorage
.is() )
384 throw lang::IllegalArgumentException( "No parent storage is provided!",
385 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
388 if ( sEntName
.isEmpty() )
389 throw lang::IllegalArgumentException( "Empty element name is provided!",
390 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
393 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( lArguments
);
396 for ( sal_Int32 nInd
= 0; nInd
< aTempMedDescr
.getLength(); nInd
++ )
397 if ( aTempMedDescr
[nInd
].Name
== "URL" )
398 aTempMedDescr
[nInd
].Value
>>= aURL
;
400 if ( aURL
.isEmpty() )
401 throw lang::IllegalArgumentException( "No URL for the link is provided!",
402 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
405 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
406 if ( !aObject
.getLength() )
407 throw io::IOException(); // unexpected mimetype of the storage
409 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, aObject
);
411 if ( !aFilterName
.isEmpty() )
414 xResult
.set(static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
423 // the object must be OOo embedded object, if it is not an exception must be thrown
424 throw io::IOException(); // TODO:
430 OUString SAL_CALL
OOoEmbeddedObjectFactory::getImplementationName()
431 throw ( uno::RuntimeException
, std::exception
)
433 return impl_staticGetImplementationName();
436 sal_Bool SAL_CALL
OOoEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
437 throw ( uno::RuntimeException
, std::exception
)
439 return cppu::supportsService(this, ServiceName
);
442 uno::Sequence
< OUString
> SAL_CALL
OOoEmbeddedObjectFactory::getSupportedServiceNames()
443 throw ( uno::RuntimeException
, std::exception
)
445 return impl_staticGetSupportedServiceNames();
448 uno::Sequence
< OUString
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
450 uno::Sequence
< OUString
> aRet(2);
451 aRet
[0] = "com.sun.star.embed.OOoSpecialEmbeddedObjectFactory";
452 aRet
[1] = "com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory";
456 OUString SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName()
458 return OUString("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory");
461 uno::Reference
< uno::XInterface
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticCreateSelfInstance(
462 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
464 return uno::Reference
< uno::XInterface
>( *new OOoSpecialEmbeddedObjectFactory( comphelper::getComponentContext(xServiceManager
) ) );
467 uno::Reference
< uno::XInterface
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::createInstanceUserInit(
468 const uno::Sequence
< sal_Int8
>& aClassID
,
469 const OUString
& /*aClassName*/,
470 const uno::Reference
< embed::XStorage
>& /*xStorage*/,
471 const OUString
& /*sEntName*/,
472 sal_Int32
/*nEntryConnectionMode*/,
473 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
474 const uno::Sequence
< beans::PropertyValue
>& /*lObjArgs*/ )
475 throw ( lang::IllegalArgumentException
,
478 uno::RuntimeException
, std::exception
)
480 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
481 if ( !aObject
.getLength() )
482 throw io::IOException(); // unexpected mimetype of the storage
484 uno::Reference
< uno::XInterface
> xResult(
485 static_cast< ::cppu::OWeakObject
* > ( new OSpecialEmbeddedObject(
492 OUString SAL_CALL
OOoSpecialEmbeddedObjectFactory::getImplementationName()
493 throw ( uno::RuntimeException
, std::exception
)
495 return impl_staticGetImplementationName();
498 sal_Bool SAL_CALL
OOoSpecialEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
499 throw ( uno::RuntimeException
, std::exception
)
501 return cppu::supportsService(this, ServiceName
);
504 uno::Sequence
< OUString
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::getSupportedServiceNames()
505 throw ( uno::RuntimeException
, std::exception
)
507 return impl_staticGetSupportedServiceNames();
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */