lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / ucbhelper / source / provider / registerucb.cxx
blob7130c33b84c88a39de3a4e265aa456bb6a5e878c
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 <ucbhelper/registerucb.hxx>
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/ucb/DuplicateProviderException.hpp>
24 #include <com/sun/star/ucb/XContentProviderManager.hpp>
25 #include <com/sun/star/ucb/XParameterizedContentProvider.hpp>
26 #include <com/sun/star/ucb/ContentProviderProxyFactory.hpp>
27 #include <com/sun/star/ucb/XContentProviderFactory.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/uno/RuntimeException.hpp>
31 #include <osl/diagnose.h>
33 using namespace com::sun::star;
35 namespace ucbhelper {
38 // registerAtUcb
41 bool
42 registerAtUcb(
43 uno::Reference< ucb::XContentProviderManager > const & rManager,
44 uno::Reference< uno::XComponentContext > const & rxContext,
45 OUString const & rName,
46 OUString const & rArguments,
47 OUString const & rTemplate)
49 OSL_ENSURE(rxContext.is(),
50 "ucb::registerAtUcb(): No service factory");
52 bool bNoProxy = rArguments.startsWith("{noproxy}");
53 OUString
54 aProviderArguments(bNoProxy ?
55 rArguments.
56 copy(RTL_CONSTASCII_LENGTH("{noproxy}")) :
57 rArguments);
59 uno::Reference< ucb::XContentProvider > xProvider;
61 if (!rName.isEmpty())
63 // First, try to instantiate proxy for provider:
64 if (!bNoProxy)
66 uno::Reference< ucb::XContentProviderFactory > xProxyFactory;
67 try
69 xProxyFactory = ucb::ContentProviderProxyFactory::create( rxContext );
71 catch (uno::Exception const &) {}
72 OSL_ENSURE(xProxyFactory.is(), "No ContentProviderProxyFactory");
73 if (xProxyFactory.is())
74 xProvider = xProxyFactory->createContentProvider(rName);
77 // Then, try to instantiate provider directly:
78 if (!xProvider.is())
79 try
81 xProvider.set(
82 rxContext->getServiceManager()->createInstanceWithContext(rName, rxContext),
83 uno::UNO_QUERY);
85 catch (uno::RuntimeException const &) { throw; }
86 catch (uno::Exception const &) {}
89 uno::Reference< ucb::XParameterizedContentProvider >
90 xParameterized(xProvider, uno::UNO_QUERY);
91 if (xParameterized.is())
93 uno::Reference< ucb::XContentProvider > xInstance;
94 try
96 xInstance = xParameterized->registerInstance(rTemplate,
97 aProviderArguments,
98 true);
99 //@@@ if this call replaces an old instance, the commit-or-
100 // rollback code below will not work
102 catch (lang::IllegalArgumentException const &) {}
104 if (xInstance.is())
105 xProvider = xInstance;
108 bool bSuccess = false;
109 if (rManager.is() && (rName.isEmpty() || xProvider.is()))
113 rManager->registerContentProvider(xProvider, rTemplate, true);
114 bSuccess = true;
116 catch (ucb::DuplicateProviderException const &)
118 if (xParameterized.is())
121 xParameterized->deregisterInstance(rTemplate,
122 aProviderArguments);
124 catch (lang::IllegalArgumentException const &) {}
126 catch (...)
128 if (xParameterized.is())
131 xParameterized->deregisterInstance(rTemplate,
132 aProviderArguments);
134 catch (lang::IllegalArgumentException const &) {}
135 catch (uno::RuntimeException const &) {}
136 throw;
139 return bSuccess;
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */