20#include <com/sun/star/embed/ElementModes.hpp>
21#include <com/sun/star/embed/EntryInitModes.hpp>
22#include <com/sun/star/embed/XEmbedObjectFactory.hpp>
23#include <com/sun/star/embed/OOoEmbeddedObjectFactory.hpp>
24#include <com/sun/star/embed/OLEEmbeddedObjectFactory.hpp>
25#include <com/sun/star/beans/PropertyValue.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/container/XNameAccess.hpp>
28#include <com/sun/star/lang/XComponent.hpp>
33#include <officecfg/Office/Common.hxx>
42 const uno::Sequence< sal_Int8 >& aClassID,
43 const OUString& aClassName,
44 const uno::Reference< embed::XStorage >& xStorage,
45 const OUString& sEntName,
46 const uno::Sequence< beans::PropertyValue >& lObjArgs )
49 throw lang::IllegalArgumentException(
"No parent storage is provided!",
53 if ( sEntName.isEmpty() )
54 throw lang::IllegalArgumentException(
"Empty element name is provided!",
59 if ( aEmbedFactory.isEmpty() )
63 aEmbedFactory =
"com.sun.star.embed.OLEEmbeddedObjectFactory";
66 uno::Reference < uno::XInterface > xFact(
m_xContext->getServiceManager()->createInstanceWithContext(aEmbedFactory,
m_xContext) );
67 uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY );
68 if ( xEmbCreator.is() )
69 return xEmbCreator->createInstanceInitNew(
aClassID, aClassName, xStorage, sEntName, lObjArgs );
71 uno::Reference < embed::XEmbedObjectFactory > xEmbFact( xFact, uno::UNO_QUERY_THROW );
72 return xEmbFact->createInstanceUserInit(
aClassID, aClassName, xStorage, sEntName, embed::EntryInitModes::TRUNCATE_INIT, uno::Sequence < beans::PropertyValue >(), lObjArgs);
77 const uno::Reference< embed::XStorage >& xStorage,
78 const OUString& sEntName,
79 const uno::Sequence< beans::PropertyValue >& aMedDescr,
80 const uno::Sequence< beans::PropertyValue >& lObjArgs )
83 throw lang::IllegalArgumentException(
"No parent storage is provided!",
87 if ( sEntName.isEmpty() )
88 throw lang::IllegalArgumentException(
"Empty element name is provided!",
92 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY_THROW );
95 if ( !xNameAccess->hasByName( sEntName ) )
96 throw container::NoSuchElementException();
99 OUString aEmbedFactory;
100 if ( xStorage->isStorageElement( sEntName ) )
103 uno::Reference< embed::XStorage > xSubStorage =
104 xStorage->openStorageElement( sEntName, embed::ElementModes::READ );
106 uno::Reference< beans::XPropertySet > xPropSet( xSubStorage, uno::UNO_QUERY_THROW );
109 uno::Any aAny = xPropSet->getPropertyValue(
"MediaType");
112 catch (
const uno::Exception& )
117 if ( xSubStorage.is() )
118 xSubStorage->dispose();
120 catch (
const uno::Exception& )
132 uno::Reference< io::XStream > xSubStream =
133 xStorage->openStreamElement( sEntName, embed::ElementModes::READ );
135 uno::Reference< beans::XPropertySet > xPropSet( xSubStream, uno::UNO_QUERY_THROW );
138 uno::Any aAny = xPropSet->getPropertyValue(
"MediaType");
140 if ( aMediaType ==
"application/vnd.sun.star.oleobject" )
141 aEmbedFactory =
"com.sun.star.embed.OLEEmbeddedObjectFactory";
143 catch (
const uno::Exception& )
148 uno::Reference< lang::XComponent > xComp( xSubStream, uno::UNO_QUERY );
152 catch (
const uno::Exception& )
157 OSL_ENSURE( !aMediaType.isEmpty(),
"No media type is specified for the object!" );
158 if ( !aMediaType.isEmpty() && aEmbedFactory.isEmpty() )
167 if ( !aEmbedFactory.isEmpty() )
169 uno::Reference< uno::XInterface > xFact =
m_xContext->getServiceManager()->createInstanceWithContext(aEmbedFactory,
m_xContext);
171 uno::Reference< embed::XEmbedObjectCreator > xEmbCreator( xFact, uno::UNO_QUERY );
172 if ( xEmbCreator.is() )
173 return xEmbCreator->createInstanceInitFromEntry( xStorage, sEntName, aMedDescr, lObjArgs );
175 uno::Reference < embed::XEmbedObjectFactory > xEmbFact( xFact, uno::UNO_QUERY );
177 return xEmbFact->createInstanceUserInit( uno::Sequence< sal_Int8 >(), OUString(), xStorage, sEntName, embed::EntryInitModes::DEFAULT_INIT, aMedDescr, lObjArgs);
182 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY_THROW );
183 xPersist->setPersistentEntry( xStorage, sEntName, embed::EntryInitModes::DEFAULT_INIT, aMedDescr, lObjArgs );
193 OUString aRet = rFilter;
195 if (!officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::get())
197 if (rFilter ==
"MS Word 97" || rFilter ==
"MS Word 2007 XML")
203 if (!officecfg::Office::Common::Filter::Microsoft::Import::ExcelToCalc::get())
205 if (rFilter ==
"MS Excel 97" || rFilter ==
"Calc MS Excel 2007 XML")
210 if (!officecfg::Office::Common::Filter::Microsoft::Import::PowerPointToImpress::get())
212 if (rFilter ==
"MS PowerPoint 97" || rFilter ==
"Impress MS PowerPoint 2007 XML")
217 if (!officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::get())
219 if (rFilter ==
"Visio Document")
224 if (!officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get())
226 if (rFilter ==
"draw_pdf_import")
236 const uno::Reference< embed::XStorage >& xStorage,
237 const OUString& sEntName,
238 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
239 const uno::Sequence< beans::PropertyValue >& lObjArgs )
243 if ( !xStorage.is() )
244 throw lang::IllegalArgumentException(
"No parent storage is provided!",
248 if ( sEntName.isEmpty() )
249 throw lang::IllegalArgumentException(
"Empty element name is provided!",
253 uno::Reference< uno::XInterface > xResult;
254 uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr );
261 if ( !aFilterName.isEmpty() )
264 uno::Reference< embed::XEmbeddedObjectCreator > xOOoEmbCreator =
265 embed::OOoEmbeddedObjectFactory::create(
m_xContext );
267 xResult = xOOoEmbCreator->createInstanceInitFromMediaDescriptor( xStorage,
283 uno::Reference< embed::XEmbeddedObjectCreator > xOleEmbCreator =
284 embed::OLEEmbeddedObjectFactory::create(
m_xContext );
286 xResult = xOleEmbCreator->createInstanceInitFromMediaDescriptor( xStorage, sEntName, aTempMedDescr, lObjArgs );
294 const uno::Sequence< sal_Int8 >& aClassID,
295 const OUString& sClassName,
296 const uno::Reference< embed::XStorage >& xStorage,
297 const OUString& sEntName,
298 sal_Int32 nEntryConnectionMode,
299 const uno::Sequence< beans::PropertyValue >& aArgs,
300 const uno::Sequence< beans::PropertyValue >& aObjectArgs )
302 if ( !xStorage.is() )
303 throw lang::IllegalArgumentException(
"No parent storage is provided!",
307 if ( sEntName.isEmpty() )
308 throw lang::IllegalArgumentException(
"Empty element name is provided!",
313 uno::Reference< embed::XEmbedObjectFactory > xEmbFactory(
315 uno::UNO_QUERY_THROW );
317 return xEmbFactory->createInstanceUserInit(
aClassID,
321 nEntryConnectionMode,
328 const uno::Reference< embed::XStorage >& xStorage,
329 const OUString& sEntName,
330 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
331 const uno::Sequence< beans::PropertyValue >& lObjArgs )
333 uno::Reference< uno::XInterface > xResult;
335 uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr );
339 for ( beans::PropertyValue
const & prop : std::as_const(aTempMedDescr) )
340 if ( prop.Name ==
"URL" )
343 if (
aURL.isEmpty() )
344 throw lang::IllegalArgumentException(
"No URL for the link is provided!",
350 if ( !aFilterName.isEmpty() )
353 uno::Reference< embed::XEmbeddedObjectCreator > xOOoLinkCreator =
354 embed::OOoEmbeddedObjectFactory::create(
m_xContext );
356 xResult = xOOoLinkCreator->createInstanceLink( xStorage,
372 if ( !xStorage.is() )
373 throw lang::IllegalArgumentException(
"No parent storage is provided!",
377 if ( sEntName.isEmpty() )
378 throw lang::IllegalArgumentException(
"Empty element name is provided!",
382 uno::Reference< embed::XEmbeddedObjectCreator > xLinkCreator =
383 embed::OLEEmbeddedObjectFactory::create(
m_xContext);
385 xResult = xLinkCreator->createInstanceLink( xStorage, sEntName, aTempMedDescr, lObjArgs );
393 return "com.sun.star.comp.embed.EmbeddedObjectCreator";
403 return {
"com.sun.star.embed.EmbeddedObjectCreator",
"com.sun.star.comp.embed.EmbeddedObjectCreator" };
406extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
408 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
Represents an OLE object that has native data (next to the replacement image), but we don't understan...
virtual OUString SAL_CALL getImplementationName() 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
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 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 &sClassName, const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, sal_Int32 nEntryConnectionMode, const css::uno::Sequence< css::beans::PropertyValue > &aArgs, const css::uno::Sequence< css::beans::PropertyValue > &aObjectArgs) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
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
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 css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
::comphelper::MimeConfigurationHelper m_aConfigHelper
OUString GetFactoryNameByClassID(const css::uno::Sequence< sal_Int8 > &aClassID)
OUString GetFactoryNameByMediaType(const OUString &aMediaType)
OUString UpdateMediaDescriptorWithFilterName(css::uno::Sequence< css::beans::PropertyValue > &aMediaDescr, bool bIgnoreType)
constexpr OUStringLiteral MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII
constexpr OUStringLiteral MIMETYPE_VND_SUN_XML_BASE_ASCII
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const char *const aClassID
static OUString HandleFilter(const OUString &rFilter)
Decides if rFilter should be used to load data into a doc model or real OLE embedding should happen.
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * embeddedobj_UNOEmbeddedObjectCreator_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)