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/NoSupportException.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include "xolefactory.hxx"
29 #include <oleembobj.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <cppuhelper/weak.hxx>
34 #include <officecfg/Office/Common.hxx>
36 using namespace ::com::sun::star
;
38 // TODO: do not create OLE objects that represent OOo documents
41 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromEntry(
42 const uno::Reference
< embed::XStorage
>& xStorage
,
43 const OUString
& sEntName
,
44 const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
45 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
47 if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
48 throw lang::NoSupportException(u
"Active OLE content is disabled!"_ustr
);
50 throw lang::IllegalArgumentException( u
"No parent storage is provided!"_ustr
,
51 static_cast< ::cppu::OWeakObject
* >(this),
54 if ( sEntName
.isEmpty() )
55 throw lang::IllegalArgumentException( u
"Empty element name is provided!"_ustr
,
56 static_cast< ::cppu::OWeakObject
* >(this),
59 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY_THROW
);
61 // detect entry existence
62 if ( !xNameAccess
->hasByName( sEntName
) )
63 throw container::NoSuchElementException();
65 if ( !xStorage
->isStreamElement( sEntName
) )
67 // if it is not an OLE object throw an exception
68 throw io::IOException(); // TODO:
71 uno::Reference
< uno::XInterface
> xResult(
72 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, false ) ),
75 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
76 xPersist
->setPersistentEntry( xStorage
,
78 embed::EntryInitModes::DEFAULT_INIT
,
82 for ( beans::PropertyValue
const & prop
: lObjArgs
)
84 if ( prop
.Name
== "CloneFrom" )
88 uno::Reference
< embed::XEmbeddedObject
> xObj
;
89 uno::Reference
< embed::XEmbeddedObject
> xNew( xResult
, uno::UNO_QUERY
);
92 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
94 catch ( const uno::Exception
& ) {}
103 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
104 const uno::Reference
< embed::XStorage
>& xStorage
,
105 const OUString
& sEntName
,
106 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
107 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
109 if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
110 throw lang::NoSupportException(u
"Active OLE content is disabled!"_ustr
);
111 if ( !xStorage
.is() )
112 throw lang::IllegalArgumentException( u
"No parent storage is provided!"_ustr
,
113 static_cast< ::cppu::OWeakObject
* >(this),
116 if ( sEntName
.isEmpty() )
117 throw lang::IllegalArgumentException( u
"Empty element name is provided!"_ustr
,
118 static_cast< ::cppu::OWeakObject
* >(this),
121 uno::Reference
< uno::XInterface
> xResult(
122 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, false ) ),
125 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
126 xPersist
->setPersistentEntry( xStorage
,
128 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
136 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitNew(
137 const uno::Sequence
< sal_Int8
>& aClassID
,
138 const OUString
& aClassName
,
139 const uno::Reference
< embed::XStorage
>& xStorage
,
140 const OUString
& sEntName
,
141 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
143 if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
144 throw lang::NoSupportException(u
"Active OLE content is disabled!"_ustr
);
145 if ( !xStorage
.is() )
146 throw lang::IllegalArgumentException( u
"No parent storage is provided!"_ustr
,
147 static_cast< ::cppu::OWeakObject
* >(this),
150 if ( sEntName
.isEmpty() )
151 throw lang::IllegalArgumentException( u
"Empty element name is provided!"_ustr
,
152 static_cast< ::cppu::OWeakObject
* >(this),
155 uno::Reference
< uno::XInterface
> xResult(
156 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, aClassID
, aClassName
) ),
159 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
160 xPersist
->setPersistentEntry( xStorage
,
162 embed::EntryInitModes::TRUNCATE_INIT
,
163 uno::Sequence
< beans::PropertyValue
>(),
170 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceLink(
171 const uno::Reference
< embed::XStorage
>& xStorage
,
172 const OUString
& sEntName
,
173 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
174 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
176 if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
177 throw lang::NoSupportException(u
"Active OLE content is disabled!"_ustr
);
178 if ( !xStorage
.is() )
179 throw lang::IllegalArgumentException( u
"No parent storage is provided!"_ustr
,
180 static_cast< ::cppu::OWeakObject
* >(this),
183 if ( sEntName
.isEmpty() )
184 throw lang::IllegalArgumentException( u
"Empty element name is provided!"_ustr
,
185 static_cast< ::cppu::OWeakObject
* >(this),
188 uno::Reference
< uno::XInterface
> xResult(
189 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, true ) ),
192 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
193 xPersist
->setPersistentEntry( xStorage
,
195 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
203 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceUserInit(
204 const uno::Sequence
< sal_Int8
>& aClassID
,
205 const OUString
& aClassName
,
206 const uno::Reference
< embed::XStorage
>& xStorage
,
207 const OUString
& sEntName
,
208 sal_Int32
/*nEntryConnectionMode*/,
209 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
210 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
212 if (officecfg::Office::Common::Security::Scripting::DisableActiveContent::get())
213 throw lang::NoSupportException(u
"Active OLE content is disabled!"_ustr
);
214 // the initialization is completely controlled by user
215 if ( !xStorage
.is() )
216 throw lang::IllegalArgumentException( u
"No parent storage is provided!"_ustr
,
217 static_cast< ::cppu::OWeakObject
* >(this),
220 if ( sEntName
.isEmpty() )
221 throw lang::IllegalArgumentException( u
"Empty element name is provided!"_ustr
,
222 static_cast< ::cppu::OWeakObject
* >(this),
225 uno::Reference
< uno::XInterface
> xResult(
226 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xContext
, aClassID
, aClassName
) ),
229 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
230 xPersist
->setPersistentEntry( xStorage
,
232 embed::EntryInitModes::DEFAULT_INIT
,
233 uno::Sequence
< beans::PropertyValue
>(),
240 OUString SAL_CALL
OleEmbeddedObjectFactory::getImplementationName()
242 return u
"com.sun.star.comp.embed.OLEEmbeddedObjectFactory"_ustr
;
245 sal_Bool SAL_CALL
OleEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
247 return cppu::supportsService(this, ServiceName
);
251 uno::Sequence
< OUString
> SAL_CALL
OleEmbeddedObjectFactory::getSupportedServiceNames()
253 return { u
"com.sun.star.embed.OLEEmbeddedObjectFactory"_ustr
,
254 u
"com.sun.star.comp.embed.OLEEmbeddedObjectFactory"_ustr
};
257 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
258 embeddedobj_OleEmbeddedObjectFactory_get_implementation(
259 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
261 return cppu::acquire(new OleEmbeddedObjectFactory(context
));
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */