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
& )
115 xSubStorage
= uno::Reference
< embed::XStorage
>();
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
= uno::Reference
< uno::XInterface
>(
127 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
134 // the object must be OOo embedded object, if it is not an exception must be thrown
135 throw io::IOException(); // TODO:
138 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
140 if ( !xPersist
.is() )
141 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
143 xPersist
->setPersistentEntry( xStorage
,
145 embed::EntryInitModes::DEFAULT_INIT
,
152 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
153 const uno::Reference
< embed::XStorage
>& xStorage
,
154 const OUString
& sEntName
,
155 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
156 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
157 throw ( lang::IllegalArgumentException
,
160 uno::RuntimeException
, std::exception
)
162 if ( !xStorage
.is() )
163 throw lang::IllegalArgumentException( "No parent storage is provided!",
164 static_cast< ::cppu::OWeakObject
* >(this),
167 if ( sEntName
.isEmpty() )
168 throw lang::IllegalArgumentException( "Empty element name is provided!",
169 static_cast< ::cppu::OWeakObject
* >(this),
172 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( aMediaDescr
);
174 // check if there is FilterName
175 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, false );
177 uno::Reference
< uno::XInterface
> xResult
;
179 // find document service name
180 if ( !aFilterName
.isEmpty() )
182 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByFilter( aFilterName
);
183 if ( !aObject
.getLength() )
184 throw io::IOException(); // unexpected mimetype of the storage
187 xResult
= uno::Reference
< uno::XInterface
>(
188 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
195 // the object must be OOo embedded object, if it is not an exception must be thrown
196 throw io::IOException(); // TODO:
199 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
201 if ( !xPersist
.is() )
202 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
204 xPersist
->setPersistentEntry( xStorage
,
206 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
213 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitNew(
214 const uno::Sequence
< sal_Int8
>& aClassID
,
215 const OUString
& /*aClassName*/,
216 const uno::Reference
< embed::XStorage
>& xStorage
,
217 const OUString
& sEntName
,
218 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
219 throw ( lang::IllegalArgumentException
,
222 uno::RuntimeException
, std::exception
)
224 uno::Reference
< uno::XInterface
> xResult
;
226 if ( !xStorage
.is() )
227 throw lang::IllegalArgumentException( "No parent storage is provided!",
228 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
231 if ( sEntName
.isEmpty() )
232 throw lang::IllegalArgumentException( "Empty element name is provided!",
233 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
236 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
237 if ( !aObject
.getLength() )
238 throw io::IOException(); // unexpected mimetype of the storage
240 xResult
= uno::Reference
< uno::XInterface
>(
241 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
247 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
249 if ( !xPersist
.is() )
250 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
252 xPersist
->setPersistentEntry( xStorage
,
254 embed::EntryInitModes::TRUNCATE_INIT
,
255 uno::Sequence
< beans::PropertyValue
>(),
261 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceUserInit(
262 const uno::Sequence
< sal_Int8
>& aClassID
,
263 const OUString
& /*aClassName*/,
264 const uno::Reference
< embed::XStorage
>& xStorage
,
265 const OUString
& sEntName
,
266 sal_Int32 nEntryConnectionMode
,
267 const uno::Sequence
< beans::PropertyValue
>& lArguments
,
268 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
269 throw ( lang::IllegalArgumentException
,
272 uno::RuntimeException
, std::exception
)
274 // the initialization is completelly controlled by user
275 if ( !xStorage
.is() )
276 throw lang::IllegalArgumentException( "No parent storage is provided!",
277 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
280 if ( sEntName
.isEmpty() )
281 throw lang::IllegalArgumentException( "Empty element name is provided!",
282 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
285 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
286 if ( !aObject
.getLength() )
287 throw io::IOException(); // unexpected mimetype of the storage
289 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( lArguments
);
290 if ( nEntryConnectionMode
== embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
)
292 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, aObject
);
293 if ( aFilterName
.isEmpty() )
294 // the object must be OOo embedded object, if it is not an exception must be thrown
295 throw io::IOException(); // TODO:
298 uno::Reference
< uno::XInterface
> xResult
= uno::Reference
< uno::XInterface
> (
299 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
304 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
307 xPersist
->setPersistentEntry( xStorage
,
309 nEntryConnectionMode
,
315 throw uno::RuntimeException(); // TODO:
320 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceLink(
321 const uno::Reference
< embed::XStorage
>& /*xStorage*/,
322 const OUString
& /*sEntName*/,
323 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
324 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
325 throw ( lang::IllegalArgumentException
,
328 uno::RuntimeException
, std::exception
)
330 uno::Reference
< uno::XInterface
> xResult
;
332 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( aMediaDescr
);
334 // check if there is URL, URL must exist
336 for ( sal_Int32 nInd
= 0; nInd
< aTempMedDescr
.getLength(); nInd
++ )
337 if ( aTempMedDescr
[nInd
].Name
== "URL" )
338 aTempMedDescr
[nInd
].Value
>>= aURL
;
340 if ( aURL
.isEmpty() )
341 throw lang::IllegalArgumentException( "No URL for the link is provided!",
342 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
345 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, false );
347 if ( !aFilterName
.isEmpty() )
349 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByFilter( aFilterName
);
350 if ( !aObject
.getLength() )
351 throw io::IOException(); // unexpected mimetype of the storage
354 xResult
= uno::Reference
< uno::XInterface
>(
355 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
364 // the object must be OOo embedded object, if it is not an exception must be thrown
365 throw io::IOException(); // TODO:
371 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceLinkUserInit(
372 const uno::Sequence
< sal_Int8
>& aClassID
,
373 const OUString
& /*aClassName*/,
374 const uno::Reference
< embed::XStorage
>& xStorage
,
375 const OUString
& sEntName
,
376 const uno::Sequence
< beans::PropertyValue
>& lArguments
,
377 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
378 throw ( lang::IllegalArgumentException
,
381 uno::RuntimeException
)
383 uno::Reference
< uno::XInterface
> xResult
;
385 // the initialization is completelly controlled by user
386 if ( !xStorage
.is() )
387 throw lang::IllegalArgumentException( "No parent storage is provided!",
388 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
391 if ( sEntName
.isEmpty() )
392 throw lang::IllegalArgumentException( "Empty element name is provided!",
393 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
396 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( lArguments
);
399 for ( sal_Int32 nInd
= 0; nInd
< aTempMedDescr
.getLength(); nInd
++ )
400 if ( aTempMedDescr
[nInd
].Name
== "URL" )
401 aTempMedDescr
[nInd
].Value
>>= aURL
;
403 if ( aURL
.isEmpty() )
404 throw lang::IllegalArgumentException( "No URL for the link is provided!",
405 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
408 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
409 if ( !aObject
.getLength() )
410 throw io::IOException(); // unexpected mimetype of the storage
412 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, aObject
);
414 if ( !aFilterName
.isEmpty() )
417 xResult
= uno::Reference
< uno::XInterface
>(
418 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
427 // the object must be OOo embedded object, if it is not an exception must be thrown
428 throw io::IOException(); // TODO:
434 OUString SAL_CALL
OOoEmbeddedObjectFactory::getImplementationName()
435 throw ( uno::RuntimeException
, std::exception
)
437 return impl_staticGetImplementationName();
440 sal_Bool SAL_CALL
OOoEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
441 throw ( uno::RuntimeException
, std::exception
)
443 return cppu::supportsService(this, ServiceName
);
446 uno::Sequence
< OUString
> SAL_CALL
OOoEmbeddedObjectFactory::getSupportedServiceNames()
447 throw ( uno::RuntimeException
, std::exception
)
449 return impl_staticGetSupportedServiceNames();
452 uno::Sequence
< OUString
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
454 uno::Sequence
< OUString
> aRet(2);
455 aRet
[0] = "com.sun.star.embed.OOoSpecialEmbeddedObjectFactory";
456 aRet
[1] = "com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory";
460 OUString SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName()
462 return OUString("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory");
465 uno::Reference
< uno::XInterface
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticCreateSelfInstance(
466 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
468 return uno::Reference
< uno::XInterface
>( *new OOoSpecialEmbeddedObjectFactory( comphelper::getComponentContext(xServiceManager
) ) );
471 uno::Reference
< uno::XInterface
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::createInstanceUserInit(
472 const uno::Sequence
< sal_Int8
>& aClassID
,
473 const OUString
& /*aClassName*/,
474 const uno::Reference
< embed::XStorage
>& /*xStorage*/,
475 const OUString
& /*sEntName*/,
476 sal_Int32
/*nEntryConnectionMode*/,
477 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
478 const uno::Sequence
< beans::PropertyValue
>& /*lObjArgs*/ )
479 throw ( lang::IllegalArgumentException
,
482 uno::RuntimeException
, std::exception
)
484 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
485 if ( !aObject
.getLength() )
486 throw io::IOException(); // unexpected mimetype of the storage
488 uno::Reference
< uno::XInterface
> xResult(
489 static_cast< ::cppu::OWeakObject
* > ( new OSpecialEmbeddedObject(
496 OUString SAL_CALL
OOoSpecialEmbeddedObjectFactory::getImplementationName()
497 throw ( uno::RuntimeException
, std::exception
)
499 return impl_staticGetImplementationName();
502 sal_Bool SAL_CALL
OOoSpecialEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
503 throw ( uno::RuntimeException
, std::exception
)
505 return cppu::supportsService(this, ServiceName
);
508 uno::Sequence
< OUString
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::getSupportedServiceNames()
509 throw ( uno::RuntimeException
, std::exception
)
511 return impl_staticGetSupportedServiceNames();
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */