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/beans/PropertyValue.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/embed/Aspects.hpp>
26 #include <com/sun/star/io/IOException.hpp>
28 #include "xolefactory.hxx"
29 #include <oleembobj.hxx>
31 #include <cppuhelper/supportsservice.hxx>
33 using namespace ::com::sun::star
;
35 // TODO: do not create OLE objects that represent OOo documents
38 uno::Sequence
< OUString
> OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
40 uno::Sequence
< OUString
> aRet(2);
41 aRet
[0] = "com.sun.star.embed.OLEEmbeddedObjectFactory";
42 aRet
[1] = "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
47 OUString
OleEmbeddedObjectFactory::impl_staticGetImplementationName()
49 return OUString("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
53 uno::Reference
< uno::XInterface
> OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
54 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
56 return uno::Reference
< uno::XInterface
>( *new OleEmbeddedObjectFactory( xServiceManager
) );
60 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromEntry(
61 const uno::Reference
< embed::XStorage
>& xStorage
,
62 const OUString
& sEntName
,
63 const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
64 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
67 throw lang::IllegalArgumentException( "No parent storage is provided!",
68 static_cast< ::cppu::OWeakObject
* >(this),
71 if ( sEntName
.isEmpty() )
72 throw lang::IllegalArgumentException( "Empty element name is provided!",
73 static_cast< ::cppu::OWeakObject
* >(this),
76 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY_THROW
);
78 // detect entry existence
79 if ( !xNameAccess
->hasByName( sEntName
) )
80 throw container::NoSuchElementException();
82 if ( !xStorage
->isStreamElement( sEntName
) )
84 // if it is not an OLE object throw an exception
85 throw io::IOException(); // TODO:
88 uno::Reference
< uno::XInterface
> xResult(
89 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, false ) ),
92 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
93 xPersist
->setPersistentEntry( xStorage
,
95 embed::EntryInitModes::DEFAULT_INIT
,
99 for ( sal_Int32 nInd
= 0; nInd
< lObjArgs
.getLength(); nInd
++ )
101 if ( lObjArgs
[nInd
].Name
== "CloneFrom" )
105 uno::Reference
< embed::XEmbeddedObject
> xObj
;
106 uno::Reference
< embed::XEmbeddedObject
> xNew( xResult
, uno::UNO_QUERY
);
107 lObjArgs
[nInd
].Value
>>= xObj
;
109 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
111 catch ( const uno::Exception
& ) {}
120 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
121 const uno::Reference
< embed::XStorage
>& xStorage
,
122 const OUString
& sEntName
,
123 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
124 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
126 if ( !xStorage
.is() )
127 throw lang::IllegalArgumentException( "No parent storage is provided!",
128 static_cast< ::cppu::OWeakObject
* >(this),
131 if ( sEntName
.isEmpty() )
132 throw lang::IllegalArgumentException( "Empty element name is provided!",
133 static_cast< ::cppu::OWeakObject
* >(this),
136 uno::Reference
< uno::XInterface
> xResult(
137 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, false ) ),
140 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
141 xPersist
->setPersistentEntry( xStorage
,
143 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
151 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitNew(
152 const uno::Sequence
< sal_Int8
>& aClassID
,
153 const OUString
& aClassName
,
154 const uno::Reference
< embed::XStorage
>& xStorage
,
155 const OUString
& sEntName
,
156 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
158 if ( !xStorage
.is() )
159 throw lang::IllegalArgumentException( "No parent storage is provided!",
160 static_cast< ::cppu::OWeakObject
* >(this),
163 if ( sEntName
.isEmpty() )
164 throw lang::IllegalArgumentException( "Empty element name is provided!",
165 static_cast< ::cppu::OWeakObject
* >(this),
168 uno::Reference
< uno::XInterface
> xResult(
169 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
172 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
173 xPersist
->setPersistentEntry( xStorage
,
175 embed::EntryInitModes::TRUNCATE_INIT
,
176 uno::Sequence
< beans::PropertyValue
>(),
183 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceLink(
184 const uno::Reference
< embed::XStorage
>& xStorage
,
185 const OUString
& sEntName
,
186 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
187 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
189 if ( !xStorage
.is() )
190 throw lang::IllegalArgumentException( "No parent storage is provided!",
191 static_cast< ::cppu::OWeakObject
* >(this),
194 if ( sEntName
.isEmpty() )
195 throw lang::IllegalArgumentException( "Empty element name is provided!",
196 static_cast< ::cppu::OWeakObject
* >(this),
199 uno::Reference
< uno::XInterface
> xResult(
200 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, true ) ),
203 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
204 xPersist
->setPersistentEntry( xStorage
,
206 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
214 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceUserInit(
215 const uno::Sequence
< sal_Int8
>& aClassID
,
216 const OUString
& aClassName
,
217 const uno::Reference
< embed::XStorage
>& xStorage
,
218 const OUString
& sEntName
,
219 sal_Int32
/*nEntryConnectionMode*/,
220 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
221 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
223 // the initialization is completely controlled by user
224 if ( !xStorage
.is() )
225 throw lang::IllegalArgumentException( "No parent storage is provided!",
226 static_cast< ::cppu::OWeakObject
* >(this),
229 if ( sEntName
.isEmpty() )
230 throw lang::IllegalArgumentException( "Empty element name is provided!",
231 static_cast< ::cppu::OWeakObject
* >(this),
234 uno::Reference
< uno::XInterface
> xResult(
235 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
238 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
239 xPersist
->setPersistentEntry( xStorage
,
241 embed::EntryInitModes::DEFAULT_INIT
,
242 uno::Sequence
< beans::PropertyValue
>(),
249 OUString SAL_CALL
OleEmbeddedObjectFactory::getImplementationName()
251 return impl_staticGetImplementationName();
254 sal_Bool SAL_CALL
OleEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
256 return cppu::supportsService(this, ServiceName
);
260 uno::Sequence
< OUString
> SAL_CALL
OleEmbeddedObjectFactory::getSupportedServiceNames()
262 return impl_staticGetSupportedServiceNames();
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */