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 <rtl/logfile.hxx>
28 #include <comphelper/processfactory.hxx>
31 #include "xfactory.hxx"
32 #include "commonembobj.hxx"
33 #include "specialobject.hxx"
34 #include "oleembobj.hxx"
37 using namespace ::com::sun::star
;
39 //-------------------------------------------------------------------------
40 uno::Sequence
< OUString
> SAL_CALL
OOoEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
42 uno::Sequence
< OUString
> aRet(2);
43 aRet
[0] = OUString("com.sun.star.embed.OOoEmbeddedObjectFactory");
44 aRet
[1] = OUString("com.sun.star.comp.embed.OOoEmbeddedObjectFactory");
48 //-------------------------------------------------------------------------
49 OUString SAL_CALL
OOoEmbeddedObjectFactory::impl_staticGetImplementationName()
51 return OUString("com.sun.star.comp.embed.OOoEmbeddedObjectFactory");
54 //-------------------------------------------------------------------------
55 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::impl_staticCreateSelfInstance(
56 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
58 return uno::Reference
< uno::XInterface
>( *new OOoEmbeddedObjectFactory( comphelper::getComponentContext(xServiceManager
) ) );
61 //-------------------------------------------------------------------------
62 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitFromEntry(
63 const uno::Reference
< embed::XStorage
>& xStorage
,
64 const OUString
& sEntName
,
65 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
66 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
67 throw ( lang::IllegalArgumentException
,
68 container::NoSuchElementException
,
71 uno::RuntimeException
)
73 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitFromEntry" );
76 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
77 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
80 if ( sEntName
.isEmpty() )
81 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
82 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
85 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY
);
86 if ( !xNameAccess
.is() )
87 throw uno::RuntimeException(); //TODO
89 // detect entry existence
90 if ( !xNameAccess
->hasByName( sEntName
) )
91 throw container::NoSuchElementException();
93 uno::Reference
< uno::XInterface
> xResult
;
94 if ( xStorage
->isStorageElement( sEntName
) )
96 // the object must be based on storage
97 uno::Reference
< embed::XStorage
> xSubStorage
=
98 xStorage
->openStorageElement( sEntName
, embed::ElementModes::READ
);
100 uno::Reference
< beans::XPropertySet
> xPropSet( xSubStorage
, uno::UNO_QUERY
);
101 if ( !xPropSet
.is() )
102 throw uno::RuntimeException();
106 uno::Any aAny
= xPropSet
->getPropertyValue( OUString( "MediaType" ) );
109 catch ( const uno::Exception
& )
114 uno::Reference
< lang::XComponent
> xComp( xSubStorage
, uno::UNO_QUERY
);
118 catch ( const uno::Exception
& )
121 xSubStorage
= uno::Reference
< embed::XStorage
>();
123 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByMediaType( aMediaType
);
124 if ( !aObject
.getLength() )
125 throw io::IOException(); // unexpected mimetype of the storage
127 xResult
= uno::Reference
< uno::XInterface
>(
128 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
135 // the object must be OOo embedded object, if it is not an exception must be thrown
136 throw io::IOException(); // TODO:
139 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
141 if ( !xPersist
.is() )
142 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
144 xPersist
->setPersistentEntry( xStorage
,
146 embed::EntryInitModes::DEFAULT_INIT
,
153 //-------------------------------------------------------------------------
154 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
155 const uno::Reference
< embed::XStorage
>& xStorage
,
156 const OUString
& sEntName
,
157 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
158 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
159 throw ( lang::IllegalArgumentException
,
162 uno::RuntimeException
)
164 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
166 if ( !xStorage
.is() )
167 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
168 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
171 if ( sEntName
.isEmpty() )
172 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
173 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
176 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( aMediaDescr
);
178 // check if there is FilterName
179 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, sal_False
);
181 uno::Reference
< uno::XInterface
> xResult
;
183 // find document service name
184 if ( !aFilterName
.isEmpty() )
186 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByFilter( aFilterName
);
187 if ( !aObject
.getLength() )
188 throw io::IOException(); // unexpected mimetype of the storage
191 xResult
= uno::Reference
< uno::XInterface
>(
192 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
199 // the object must be OOo embedded object, if it is not an exception must be thrown
200 throw io::IOException(); // TODO:
203 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
205 if ( !xPersist
.is() )
206 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
208 xPersist
->setPersistentEntry( xStorage
,
210 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
217 //-------------------------------------------------------------------------
218 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceInitNew(
219 const uno::Sequence
< sal_Int8
>& aClassID
,
220 const OUString
& /*aClassName*/,
221 const uno::Reference
< embed::XStorage
>& xStorage
,
222 const OUString
& sEntName
,
223 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
224 throw ( lang::IllegalArgumentException
,
227 uno::RuntimeException
)
229 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceInitNew" );
231 uno::Reference
< uno::XInterface
> xResult
;
233 if ( !xStorage
.is() )
234 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
235 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
238 if ( sEntName
.isEmpty() )
239 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
240 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
243 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
244 if ( !aObject
.getLength() )
245 throw io::IOException(); // unexpected mimetype of the storage
247 xResult
= uno::Reference
< uno::XInterface
>(
248 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
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::TRUNCATE_INIT
,
262 uno::Sequence
< beans::PropertyValue
>(),
268 //-------------------------------------------------------------------------
269 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceUserInit(
270 const uno::Sequence
< sal_Int8
>& aClassID
,
271 const OUString
& /*aClassName*/,
272 const uno::Reference
< embed::XStorage
>& xStorage
,
273 const 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) OOoEmbeddedObjectFactory::createInstanceUserInit" );
284 // the initialization is completelly controlled by user
285 if ( !xStorage
.is() )
286 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
287 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
290 if ( sEntName
.isEmpty() )
291 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
292 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
295 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
296 if ( !aObject
.getLength() )
297 throw io::IOException(); // unexpected mimetype of the storage
299 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( lArguments
);
300 if ( nEntryConnectionMode
== embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
)
302 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, aObject
);
303 if ( aFilterName
.isEmpty() )
304 // the object must be OOo embedded object, if it is not an exception must be thrown
305 throw io::IOException(); // TODO:
308 uno::Reference
< uno::XInterface
> xResult
= uno::Reference
< uno::XInterface
> (
309 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
314 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
317 xPersist
->setPersistentEntry( xStorage
,
319 nEntryConnectionMode
,
325 throw uno::RuntimeException(); // TODO:
331 //-------------------------------------------------------------------------
332 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceLink(
333 const uno::Reference
< embed::XStorage
>& /*xStorage*/,
334 const OUString
& /*sEntName*/,
335 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
336 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
337 throw ( lang::IllegalArgumentException
,
340 uno::RuntimeException
)
342 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceLink" );
344 uno::Reference
< uno::XInterface
> xResult
;
346 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( aMediaDescr
);
348 // check if there is URL, URL must exist
350 for ( sal_Int32 nInd
= 0; nInd
< aTempMedDescr
.getLength(); nInd
++ )
351 if ( aTempMedDescr
[nInd
].Name
== "URL" )
352 aTempMedDescr
[nInd
].Value
>>= aURL
;
354 if ( aURL
.isEmpty() )
355 throw lang::IllegalArgumentException( OUString( "No URL for the link is provided!\n" ),
356 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
359 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, sal_False
);
361 if ( !aFilterName
.isEmpty() )
363 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByFilter( aFilterName
);
364 if ( !aObject
.getLength() )
365 throw io::IOException(); // unexpected mimetype of the storage
368 xResult
= uno::Reference
< uno::XInterface
>(
369 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
378 // the object must be OOo embedded object, if it is not an exception must be thrown
379 throw io::IOException(); // TODO:
385 //-------------------------------------------------------------------------
386 uno::Reference
< uno::XInterface
> SAL_CALL
OOoEmbeddedObjectFactory::createInstanceLinkUserInit(
387 const uno::Sequence
< sal_Int8
>& aClassID
,
388 const OUString
& /*aClassName*/,
389 const uno::Reference
< embed::XStorage
>& xStorage
,
390 const OUString
& sEntName
,
391 const uno::Sequence
< beans::PropertyValue
>& lArguments
,
392 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
393 throw ( lang::IllegalArgumentException
,
396 uno::RuntimeException
)
398 RTL_LOGFILE_CONTEXT( aLog
, "embeddedobj (mv76033) OOoEmbeddedObjectFactory::createInstanceLinkUserInit" );
400 uno::Reference
< uno::XInterface
> xResult
;
402 // the initialization is completelly controlled by user
403 if ( !xStorage
.is() )
404 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
405 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
408 if ( sEntName
.isEmpty() )
409 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
410 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
413 uno::Sequence
< beans::PropertyValue
> aTempMedDescr( lArguments
);
416 for ( sal_Int32 nInd
= 0; nInd
< aTempMedDescr
.getLength(); nInd
++ )
417 if ( aTempMedDescr
[nInd
].Name
== "URL" )
418 aTempMedDescr
[nInd
].Value
>>= aURL
;
420 if ( aURL
.isEmpty() )
421 throw lang::IllegalArgumentException( OUString( "No URL for the link is provided!\n" ),
422 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
425 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
426 if ( !aObject
.getLength() )
427 throw io::IOException(); // unexpected mimetype of the storage
429 OUString aFilterName
= m_aConfigHelper
.UpdateMediaDescriptorWithFilterName( aTempMedDescr
, aObject
);
431 if ( !aFilterName
.isEmpty() )
434 xResult
= uno::Reference
< uno::XInterface
>(
435 static_cast< ::cppu::OWeakObject
* > ( new OCommonEmbeddedObject(
444 // the object must be OOo embedded object, if it is not an exception must be thrown
445 throw io::IOException(); // TODO:
451 //-------------------------------------------------------------------------
452 OUString SAL_CALL
OOoEmbeddedObjectFactory::getImplementationName()
453 throw ( uno::RuntimeException
)
455 return impl_staticGetImplementationName();
458 //-------------------------------------------------------------------------
459 sal_Bool SAL_CALL
OOoEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
460 throw ( uno::RuntimeException
)
462 uno::Sequence
< OUString
> aSeq
= impl_staticGetSupportedServiceNames();
464 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
465 if ( ServiceName
== aSeq
[nInd
] )
471 //-------------------------------------------------------------------------
472 uno::Sequence
< OUString
> SAL_CALL
OOoEmbeddedObjectFactory::getSupportedServiceNames()
473 throw ( uno::RuntimeException
)
475 return impl_staticGetSupportedServiceNames();
478 //-------------------------------------------------------------------------
479 uno::Sequence
< OUString
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
481 uno::Sequence
< OUString
> aRet(2);
482 aRet
[0] = OUString("com.sun.star.embed.OOoSpecialEmbeddedObjectFactory");
483 aRet
[1] = OUString("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory");
487 //-------------------------------------------------------------------------
488 OUString SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticGetImplementationName()
490 return OUString("com.sun.star.comp.embed.OOoSpecialEmbeddedObjectFactory");
493 //-------------------------------------------------------------------------
494 uno::Reference
< uno::XInterface
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::impl_staticCreateSelfInstance(
495 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
497 return uno::Reference
< uno::XInterface
>( *new OOoSpecialEmbeddedObjectFactory( comphelper::getComponentContext(xServiceManager
) ) );
500 //-------------------------------------------------------------------------
501 uno::Reference
< uno::XInterface
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::createInstanceUserInit(
502 const uno::Sequence
< sal_Int8
>& aClassID
,
503 const OUString
& /*aClassName*/,
504 const uno::Reference
< embed::XStorage
>& /*xStorage*/,
505 const OUString
& /*sEntName*/,
506 sal_Int32
/*nEntryConnectionMode*/,
507 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
508 const uno::Sequence
< beans::PropertyValue
>& /*lObjArgs*/ )
509 throw ( lang::IllegalArgumentException
,
512 uno::RuntimeException
)
514 uno::Sequence
< beans::NamedValue
> aObject
= m_aConfigHelper
.GetObjectPropsByClassID( aClassID
);
515 if ( !aObject
.getLength() )
516 throw io::IOException(); // unexpected mimetype of the storage
518 uno::Reference
< uno::XInterface
> xResult(
519 static_cast< ::cppu::OWeakObject
* > ( new OSpecialEmbeddedObject(
526 //-------------------------------------------------------------------------
527 OUString SAL_CALL
OOoSpecialEmbeddedObjectFactory::getImplementationName()
528 throw ( uno::RuntimeException
)
530 return impl_staticGetImplementationName();
533 //-------------------------------------------------------------------------
534 sal_Bool SAL_CALL
OOoSpecialEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
535 throw ( uno::RuntimeException
)
537 uno::Sequence
< OUString
> aSeq
= impl_staticGetSupportedServiceNames();
539 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
540 if ( ServiceName
== aSeq
[nInd
] )
546 //-------------------------------------------------------------------------
547 uno::Sequence
< OUString
> SAL_CALL
OOoSpecialEmbeddedObjectFactory::getSupportedServiceNames()
548 throw ( uno::RuntimeException
)
550 return impl_staticGetSupportedServiceNames();
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */