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>
32 using namespace ::com::sun::star
;
34 // TODO: do not create OLE objects that represent OOo documents
37 uno::Sequence
< OUString
> OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
39 uno::Sequence
< OUString
> aRet(2);
40 aRet
[0] = "com.sun.star.embed.OLEEmbeddedObjectFactory";
41 aRet
[1] = "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
46 OUString
OleEmbeddedObjectFactory::impl_staticGetImplementationName()
48 return "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
52 uno::Reference
< uno::XInterface
> OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
53 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
55 return uno::Reference
< uno::XInterface
>( *new OleEmbeddedObjectFactory( xServiceManager
) );
59 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromEntry(
60 const uno::Reference
< embed::XStorage
>& xStorage
,
61 const OUString
& sEntName
,
62 const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
63 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
66 throw lang::IllegalArgumentException( "No parent storage is provided!",
67 static_cast< ::cppu::OWeakObject
* >(this),
70 if ( sEntName
.isEmpty() )
71 throw lang::IllegalArgumentException( "Empty element name is provided!",
72 static_cast< ::cppu::OWeakObject
* >(this),
75 uno::Reference
< container::XNameAccess
> xNameAccess( xStorage
, uno::UNO_QUERY_THROW
);
77 // detect entry existence
78 if ( !xNameAccess
->hasByName( sEntName
) )
79 throw container::NoSuchElementException();
81 if ( !xStorage
->isStreamElement( sEntName
) )
83 // if it is not an OLE object throw an exception
84 throw io::IOException(); // TODO:
87 uno::Reference
< uno::XInterface
> xResult(
88 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, false ) ),
91 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
92 xPersist
->setPersistentEntry( xStorage
,
94 embed::EntryInitModes::DEFAULT_INIT
,
98 for ( sal_Int32 nInd
= 0; nInd
< lObjArgs
.getLength(); nInd
++ )
100 if ( lObjArgs
[nInd
].Name
== "CloneFrom" )
104 uno::Reference
< embed::XEmbeddedObject
> xObj
;
105 uno::Reference
< embed::XEmbeddedObject
> xNew( xResult
, uno::UNO_QUERY
);
106 lObjArgs
[nInd
].Value
>>= xObj
;
108 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
110 catch ( const uno::Exception
& ) {}
119 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
120 const uno::Reference
< embed::XStorage
>& xStorage
,
121 const OUString
& sEntName
,
122 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
123 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
125 if ( !xStorage
.is() )
126 throw lang::IllegalArgumentException( "No parent storage is provided!",
127 static_cast< ::cppu::OWeakObject
* >(this),
130 if ( sEntName
.isEmpty() )
131 throw lang::IllegalArgumentException( "Empty element name is provided!",
132 static_cast< ::cppu::OWeakObject
* >(this),
135 uno::Reference
< uno::XInterface
> xResult(
136 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, false ) ),
139 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
140 xPersist
->setPersistentEntry( xStorage
,
142 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
150 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceInitNew(
151 const uno::Sequence
< sal_Int8
>& aClassID
,
152 const OUString
& aClassName
,
153 const uno::Reference
< embed::XStorage
>& xStorage
,
154 const OUString
& sEntName
,
155 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
157 if ( !xStorage
.is() )
158 throw lang::IllegalArgumentException( "No parent storage is provided!",
159 static_cast< ::cppu::OWeakObject
* >(this),
162 if ( sEntName
.isEmpty() )
163 throw lang::IllegalArgumentException( "Empty element name is provided!",
164 static_cast< ::cppu::OWeakObject
* >(this),
167 uno::Reference
< uno::XInterface
> xResult(
168 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
171 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
172 xPersist
->setPersistentEntry( xStorage
,
174 embed::EntryInitModes::TRUNCATE_INIT
,
175 uno::Sequence
< beans::PropertyValue
>(),
182 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceLink(
183 const uno::Reference
< embed::XStorage
>& xStorage
,
184 const OUString
& sEntName
,
185 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
186 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
188 if ( !xStorage
.is() )
189 throw lang::IllegalArgumentException( "No parent storage is provided!",
190 static_cast< ::cppu::OWeakObject
* >(this),
193 if ( sEntName
.isEmpty() )
194 throw lang::IllegalArgumentException( "Empty element name is provided!",
195 static_cast< ::cppu::OWeakObject
* >(this),
198 uno::Reference
< uno::XInterface
> xResult(
199 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, true ) ),
202 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
203 xPersist
->setPersistentEntry( xStorage
,
205 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
213 uno::Reference
< uno::XInterface
> SAL_CALL
OleEmbeddedObjectFactory::createInstanceUserInit(
214 const uno::Sequence
< sal_Int8
>& aClassID
,
215 const OUString
& aClassName
,
216 const uno::Reference
< embed::XStorage
>& xStorage
,
217 const OUString
& sEntName
,
218 sal_Int32
/*nEntryConnectionMode*/,
219 const uno::Sequence
< beans::PropertyValue
>& /*lArguments*/,
220 const uno::Sequence
< beans::PropertyValue
>& lObjArgs
)
222 // the initialization is completely controlled by user
223 if ( !xStorage
.is() )
224 throw lang::IllegalArgumentException( "No parent storage is provided!",
225 static_cast< ::cppu::OWeakObject
* >(this),
228 if ( sEntName
.isEmpty() )
229 throw lang::IllegalArgumentException( "Empty element name is provided!",
230 static_cast< ::cppu::OWeakObject
* >(this),
233 uno::Reference
< uno::XInterface
> xResult(
234 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
237 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY_THROW
);
238 xPersist
->setPersistentEntry( xStorage
,
240 embed::EntryInitModes::DEFAULT_INIT
,
241 uno::Sequence
< beans::PropertyValue
>(),
248 OUString SAL_CALL
OleEmbeddedObjectFactory::getImplementationName()
250 return impl_staticGetImplementationName();
253 sal_Bool SAL_CALL
OleEmbeddedObjectFactory::supportsService( const OUString
& ServiceName
)
255 return cppu::supportsService(this, ServiceName
);
259 uno::Sequence
< OUString
> SAL_CALL
OleEmbeddedObjectFactory::getSupportedServiceNames()
261 return impl_staticGetSupportedServiceNames();
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */