LibreOffice Module embeddedobj (master) 1
xolefactory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
26
27#include "xolefactory.hxx"
28#include <oleembobj.hxx>
29
31#include <cppuhelper/weak.hxx>
32
33using namespace ::com::sun::star;
34
35// TODO: do not create OLE objects that represent OOo documents
36
37
38uno::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 )
43{
44 if ( !xStorage.is() )
45 throw lang::IllegalArgumentException( "No parent storage is provided!",
46 static_cast< ::cppu::OWeakObject* >(this),
47 1 );
48
49 if ( sEntName.isEmpty() )
50 throw lang::IllegalArgumentException( "Empty element name is provided!",
51 static_cast< ::cppu::OWeakObject* >(this),
52 2 );
53
54 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY_THROW );
55
56 // detect entry existence
57 if ( !xNameAccess->hasByName( sEntName ) )
58 throw container::NoSuchElementException();
59
60 if ( !xStorage->isStreamElement( sEntName ) )
61 {
62 // if it is not an OLE object throw an exception
63 throw io::IOException(); // TODO:
64 }
65
66 uno::Reference< uno::XInterface > xResult(
67 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, false ) ),
68 uno::UNO_QUERY );
69
70 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
71 xPersist->setPersistentEntry( xStorage,
72 sEntName,
73 embed::EntryInitModes::DEFAULT_INIT,
74 aMedDescr,
75 lObjArgs );
76
77 for ( beans::PropertyValue const & prop : lObjArgs )
78 {
79 if ( prop.Name == "CloneFrom" )
80 {
81 try
82 {
83 uno::Reference < embed::XEmbeddedObject > xObj;
84 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
85 prop.Value >>= xObj;
86 if ( xObj.is() )
87 xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
88 }
89 catch ( const uno::Exception& ) {}
90 break;
91 }
92 }
93
94 return xResult;
95}
96
97
98uno::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 )
103{
104 if ( !xStorage.is() )
105 throw lang::IllegalArgumentException( "No parent storage is provided!",
106 static_cast< ::cppu::OWeakObject* >(this),
107 1 );
108
109 if ( sEntName.isEmpty() )
110 throw lang::IllegalArgumentException( "Empty element name is provided!",
111 static_cast< ::cppu::OWeakObject* >(this),
112 2 );
113
114 uno::Reference< uno::XInterface > xResult(
115 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, false ) ),
116 uno::UNO_QUERY );
117
118 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
119 xPersist->setPersistentEntry( xStorage,
120 sEntName,
121 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
122 aMediaDescr,
123 lObjArgs );
124
125 return xResult;
126}
127
128
129uno::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 )
135{
136 if ( !xStorage.is() )
137 throw lang::IllegalArgumentException( "No parent storage is provided!",
138 static_cast< ::cppu::OWeakObject* >(this),
139 3 );
140
141 if ( sEntName.isEmpty() )
142 throw lang::IllegalArgumentException( "Empty element name is provided!",
143 static_cast< ::cppu::OWeakObject* >(this),
144 4 );
145
146 uno::Reference< uno::XInterface > xResult(
147 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, aClassID, aClassName ) ),
148 uno::UNO_QUERY );
149
150 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
151 xPersist->setPersistentEntry( xStorage,
152 sEntName,
153 embed::EntryInitModes::TRUNCATE_INIT,
154 uno::Sequence< beans::PropertyValue >(),
155 lObjArgs );
156
157 return xResult;
158}
159
160
161uno::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 )
166{
167 if ( !xStorage.is() )
168 throw lang::IllegalArgumentException( "No parent storage is provided!",
169 static_cast< ::cppu::OWeakObject* >(this),
170 1 );
171
172 if ( sEntName.isEmpty() )
173 throw lang::IllegalArgumentException( "Empty element name is provided!",
174 static_cast< ::cppu::OWeakObject* >(this),
175 2 );
176
177 uno::Reference< uno::XInterface > xResult(
178 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, true ) ),
179 uno::UNO_QUERY );
180
181 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
182 xPersist->setPersistentEntry( xStorage,
183 sEntName,
184 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
185 aMediaDescr,
186 lObjArgs );
187
188 return xResult;
189}
190
191
192uno::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 )
200{
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),
205 1 );
206
207 if ( sEntName.isEmpty() )
208 throw lang::IllegalArgumentException( "Empty element name is provided!",
209 static_cast< ::cppu::OWeakObject* >(this),
210 2 );
211
212 uno::Reference< uno::XInterface > xResult(
213 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xContext, aClassID, aClassName ) ),
214 uno::UNO_QUERY );
215
216 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
217 xPersist->setPersistentEntry( xStorage,
218 sEntName,
219 embed::EntryInitModes::DEFAULT_INIT,
220 uno::Sequence< beans::PropertyValue >(),
221 lObjArgs );
222
223 return xResult;
224}
225
226
228{
229 return "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
230}
231
232sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const OUString& ServiceName )
233{
235}
236
237
238uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
239{
240 return { "com.sun.star.embed.OLEEmbeddedObjectFactory",
241 "com.sun.star.comp.embed.OLEEmbeddedObjectFactory" };
242}
243
244extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
246 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
247{
248 return cppu::acquire(new OleEmbeddedObjectFactory(context));
249}
250
251/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceInitNew(const css::uno::Sequence< sal_Int8 > &aClassID, const OUString &aClassName, const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceUserInit(const css::uno::Sequence< sal_Int8 > &aClassID, const OUString &aClassName, const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, sal_Int32 nEntryConnectionMode, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceInitFromMediaDescriptor(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescr, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
Definition: xolefactory.cxx:98
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceInitFromEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &aMedDescr, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
Definition: xolefactory.cxx:38
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceLink(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &aMediaDescr, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: xolefactory.hxx:34
Represents an OLE object that has native data and we try to let an external application handle that d...
Definition: oleembobj.hxx:120
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const char *const aClassID
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * embeddedobj_OleEmbeddedObjectFactory_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)