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/EntryInitModes.hpp>
21 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <com/sun/star/container/XNameAccess.hpp>
23 #include <com/sun/star/embed/Aspects.hpp>
24 #include <com/sun/star/io/IOException.hpp>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include "xolefactory.hxx"
28 #include <oleembobj.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <cppuhelper/weak.hxx>
33 using namespace ::com::sun::star
;
35 // TODO: do not create OLE objects that represent OOo documents
38 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromEntry(
39 const uno::Reference
< embed::XStorage
>& xStorage
,
40 const OUString
& sEntName
,
41 const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
42 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
45 throw lang::IllegalArgumentException( "No parent storage is provided!",
46 static_cast< ::cppu::OWeakObject
* >(this),
49 if ( sEntName
.isEmpty() )
50 throw lang::IllegalArgumentException( "Empty element name is provided!",
51 static_cast< ::cppu::OWeakObject
* >(this),
54 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY_THROW
);
56 // detect entry existence
57 if ( !xNameAccess
->hasByName( sEntName
) )
58 throw container::NoSuchElementException();
60 if ( !xStorage
->isStreamElement( sEntName
) )
62 // if it is not an OLE object throw an exception
63 throw io::IOException(); // TODO:
66 uno::Reference
< uno::XInterface
> xResult(
67 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, false ) ),
70 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
71 xPersist
->setPersistentEntry( xStorage
,
73 embed::EntryInitModes::DEFAULT_INIT
,
77 for ( beans::PropertyValue
const & prop
: lObjArgs
)
79 if ( prop
.Name
== "CloneFrom" )
83 uno::Reference
< embed::XEmbeddedObject
> xObj
;
84 uno::Reference
< embed::XEmbeddedObject
> xNew( xResult
, uno::UNO_QUERY
);
87 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
89 catch ( const uno::Exception
& ) {}
98 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
99 const uno::Reference
< embed::XStorage
>& xStorage
,
100 const OUString
& sEntName
,
101 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
102 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
104 if ( !xStorage
.is() )
105 throw lang::IllegalArgumentException( "No parent storage is provided!",
106 static_cast< ::cppu::OWeakObject
* >(this),
109 if ( sEntName
.isEmpty() )
110 throw lang::IllegalArgumentException( "Empty element name is provided!",
111 static_cast< ::cppu::OWeakObject
* >(this),
114 uno::Reference
< uno::XInterface
> xResult(
115 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, false ) ),
118 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
119 xPersist
->setPersistentEntry( xStorage
,
121 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
129 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitNew(
130 const uno::Sequence
< sal_Int8
>& aClassID
,
131 const OUString
& aClassName
,
132 const uno::Reference
< embed::XStorage
>& xStorage
,
133 const OUString
& sEntName
,
134 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
136 if ( !xStorage
.is() )
137 throw lang::IllegalArgumentException( "No parent storage is provided!",
138 static_cast< ::cppu::OWeakObject
* >(this),
141 if ( sEntName
.isEmpty() )
142 throw lang::IllegalArgumentException( "Empty element name is provided!",
143 static_cast< ::cppu::OWeakObject
* >(this),
146 uno::Reference
< uno::XInterface
> xResult(
147 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, aClassID
, aClassName
) ),
150 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
151 xPersist
->setPersistentEntry( xStorage
,
153 embed::EntryInitModes::TRUNCATE_INIT
,
154 uno::Sequence
< beans::PropertyValue
>(),
161 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceLink(
162 const uno::Reference
< embed::XStorage
>& xStorage
,
163 const OUString
& sEntName
,
164 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
165 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
167 if ( !xStorage
.is() )
168 throw lang::IllegalArgumentException( "No parent storage is provided!",
169 static_cast< ::cppu::OWeakObject
* >(this),
172 if ( sEntName
.isEmpty() )
173 throw lang::IllegalArgumentException( "Empty element name is provided!",
174 static_cast< ::cppu::OWeakObject
* >(this),
177 uno::Reference
< uno::XInterface
> xResult(
178 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, true ) ),
181 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
182 xPersist
->setPersistentEntry( xStorage
,
184 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
192 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceUserInit(
193 const uno::Sequence
< sal_Int8
>& aClassID
,
194 const OUString
& aClassName
,
195 const uno::Reference
< embed::XStorage
>& xStorage
,
196 const OUString
& sEntName
,
197 sal_Int32
/*nEntryConnectionMode*/,
198 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
199 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
201 // the initialization is completely controlled by user
202 if ( !xStorage
.is() )
203 throw lang::IllegalArgumentException( "No parent storage is provided!",
204 static_cast< ::cppu::OWeakObject
* >(this),
207 if ( sEntName
.isEmpty() )
208 throw lang::IllegalArgumentException( "Empty element name is provided!",
209 static_cast< ::cppu::OWeakObject
* >(this),
212 uno::Reference
< uno::XInterface
> xResult(
213 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, aClassID
, aClassName
) ),
216 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
217 xPersist
->setPersistentEntry( xStorage
,
219 embed::EntryInitModes::DEFAULT_INIT
,
220 uno::Sequence
< beans::PropertyValue
>(),
227 OUString SAL_CALL
OleEmbeddedObjectFactory::getImplementationName()
229 return "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
232 sal_Bool SAL_CALL
OleEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
234 return cppu::supportsService(this, ServiceName
);
238 uno::Sequence
< OUString
> SAL_CALL
OleEmbeddedObjectFactory::getSupportedServiceNames()
240 return { "com.sun.star.embed.OLEEmbeddedObjectFactory",
241 "com.sun.star.comp.embed.OLEEmbeddedObjectFactory" };
244 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
245 embeddedobj_OleEmbeddedObjectFactory_get_implementation(
246 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
248 return cppu::acquire(new OleEmbeddedObjectFactory(context
));
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */