crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / ucb / source / core / provprox.cxx
blob863e3c1469b1234549b70c4d58fc0c95b942dc44
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <osl/diagnose.h>
21 #include <osl/thread.h>
22 #include <rtl/strbuf.hxx>
23 #include <comphelper/diagnose_ex.hxx>
24 #include "provprox.hxx"
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <cppuhelper/weak.hxx>
29 #include <ucbhelper/macros.hxx>
30 #include <utility>
32 using namespace com::sun::star::lang;
33 using namespace com::sun::star::ucb;
34 using namespace com::sun::star::uno;
36 // UcbContentProviderProxyFactory Implementation.
39 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
40 const Reference< XComponentContext >& rxContext )
41 : m_xContext( rxContext )
46 // virtual
47 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
51 // XServiceInfo methods.
53 OUString SAL_CALL UcbContentProviderProxyFactory::getImplementationName()
55 return u"com.sun.star.comp.ucb.UcbContentProviderProxyFactory"_ustr;
57 sal_Bool SAL_CALL UcbContentProviderProxyFactory::supportsService( const OUString& ServiceName )
59 return cppu::supportsService( this, ServiceName );
61 css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxyFactory::getSupportedServiceNames()
63 return { u"com.sun.star.ucb.ContentProviderProxyFactory"_ustr };
66 // Service factory implementation.
69 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
70 ucb_UcbContentProviderProxyFactory_get_implementation(
71 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
73 return cppu::acquire(new UcbContentProviderProxyFactory(context));
77 // XContentProviderFactory methods.
80 // virtual
81 Reference< XContentProvider > SAL_CALL
82 UcbContentProviderProxyFactory::createContentProvider(
83 const OUString& Service )
85 return Reference< XContentProvider >(
86 new UcbContentProviderProxy( m_xContext, Service ) );
90 // UcbContentProviderProxy Implementation.
93 UcbContentProviderProxy::UcbContentProviderProxy(
94 const Reference< XComponentContext >& rxContext,
95 OUString Service )
96 : m_aService(std::move( Service )),
97 m_bReplace( false ),
98 m_bRegister( false ),
99 m_xContext( rxContext )
104 // virtual
105 UcbContentProviderProxy::~UcbContentProviderProxy()
110 // XInterface methods.
112 // virtual
113 Any SAL_CALL
114 UcbContentProviderProxy::queryInterface( const Type & rType )
116 Any aRet = UcbContentProviderProxy_BASE::queryInterface(rType);
118 if ( !aRet.hasValue() )
120 // Get original provider and forward the call...
121 Reference< XContentProvider > xProvider = getContentProvider();
122 if ( xProvider.is() )
123 aRet = xProvider->queryInterface( rType );
126 return aRet;
130 // XTypeProvider methods.
132 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes()
134 // Get original provider and forward the call...
135 if (Reference<XTypeProvider> xProvider{ getContentProvider(), UNO_QUERY })
136 return xProvider->getTypes();
138 return UcbContentProviderProxy_BASE::getTypes();
142 // XServiceInfo methods.
144 OUString SAL_CALL UcbContentProviderProxy::getImplementationName()
146 return u"com.sun.star.comp.ucb.UcbContentProviderProxy"_ustr;
149 sal_Bool SAL_CALL UcbContentProviderProxy::supportsService( const OUString& ServiceName )
151 return cppu::supportsService( this, ServiceName );
154 css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxy::getSupportedServiceNames()
156 return { u"com.sun.star.ucb.ContentProviderProxy"_ustr };
160 // XContentProvider methods.
163 // virtual
164 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
165 const Reference< XContentIdentifier >& Identifier )
167 // Get original provider and forward the call...
169 Reference< XContentProvider > xProvider = getContentProvider();
170 if ( xProvider.is() )
171 return xProvider->queryContent( Identifier );
173 return Reference< XContent >();
177 // virtual
178 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
179 const Reference< XContentIdentifier >& Id1,
180 const Reference< XContentIdentifier >& Id2 )
182 // Get original provider and forward the call...
184 Reference< XContentProvider > xProvider = getContentProvider();
185 if ( xProvider.is() )
186 return xProvider->compareContentIds( Id1, Id2 );
188 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
190 // @@@ What else?
191 return 0;
195 // XParameterizedContentProvider methods.
198 // virtual
199 Reference< XContentProvider > SAL_CALL
200 UcbContentProviderProxy::registerInstance( const OUString& Template,
201 const OUString& Arguments,
202 sal_Bool ReplaceExisting )
204 // Just remember that this method was called ( and the params ).
206 std::scoped_lock aGuard( m_aMutex );
208 if ( !m_bRegister )
210 // m_xTargetProvider = 0;
211 m_aTemplate = Template;
212 m_aArguments = Arguments;
213 m_bReplace = ReplaceExisting;
215 m_bRegister = true;
217 return this;
221 // virtual
222 Reference< XContentProvider > SAL_CALL
223 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
224 const OUString& Arguments )
226 std::scoped_lock aGuard( m_aMutex );
228 // registerInstance called at proxy and at original?
229 if ( m_bRegister && m_xTargetProvider.is() )
231 m_bRegister = false;
232 m_xTargetProvider = nullptr;
234 Reference< XParameterizedContentProvider >
235 xParamProvider( m_xProvider, UNO_QUERY );
236 if ( xParamProvider.is() )
240 xParamProvider->deregisterInstance( Template, Arguments );
242 catch ( IllegalIdentifierException const & )
244 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
245 "Caught IllegalIdentifierException!" );
250 return this;
254 // XContentProviderSupplier methods.
257 // virtual
258 Reference< XContentProvider > SAL_CALL
259 UcbContentProviderProxy::getContentProvider()
261 std::scoped_lock aGuard( m_aMutex );
262 if ( !m_xProvider.is() )
266 m_xProvider.set( m_xContext->getServiceManager()->createInstanceWithContext( m_aService,m_xContext ), UNO_QUERY );
267 if ( m_aArguments == "NoConfig" )
269 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
270 if(xInit.is()) {
271 xInit->initialize({ Any(m_aArguments) });
275 catch ( RuntimeException const & )
277 throw;
279 catch ( Exception const & )
281 TOOLS_INFO_EXCEPTION( "ucb.core", "Exception getting content provider");
284 // registerInstance called at proxy, but not yet at original?
285 if ( m_xProvider.is() && m_bRegister )
287 Reference< XParameterizedContentProvider >
288 xParamProvider( m_xProvider, UNO_QUERY );
289 if ( xParamProvider.is() )
293 m_xTargetProvider
294 = xParamProvider->registerInstance( m_aTemplate,
295 m_aArguments,
296 m_bReplace );
298 catch ( IllegalIdentifierException const & )
300 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
301 "Caught IllegalIdentifierException!" );
304 OSL_ENSURE( m_xTargetProvider.is(),
305 "UcbContentProviderProxy::getContentProvider - "
306 "No provider!" );
309 if ( !m_xTargetProvider.is() )
310 m_xTargetProvider = m_xProvider;
313 OSL_ENSURE( m_xProvider.is(),
314 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '" +
315 OUStringToOString(m_aService, osl_getThreadTextEncoding()) +
316 ".").getStr() );
317 return m_xTargetProvider;
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */