1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: registerucb.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
33 #include <registerucb.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/ucb/XContentProviderManager.hpp>
36 #include <com/sun/star/ucb/XParameterizedContentProvider.hpp>
37 #include <com/sun/star/ucb/XContentProviderFactory.hpp>
38 #include <com/sun/star/uno/RuntimeException.hpp>
40 #include "osl/diagnose.h"
41 #include <ucbhelper/configureucb.hxx>
43 using namespace com::sun::star
;
47 //============================================================================
51 //============================================================================
55 uno::Reference
< ucb::XContentProviderManager
> const & rManager
,
56 uno::Reference
< lang::XMultiServiceFactory
> const & rServiceFactory
,
57 rtl::OUString
const & rName
,
58 rtl::OUString
const & rArguments
,
59 rtl::OUString
const & rTemplate
,
60 ContentProviderRegistrationInfo
* pInfo
)
61 throw (uno::RuntimeException
)
63 OSL_ENSURE(rServiceFactory
.is(),
64 "ucb::registerAtUcb(): No service factory");
67 = rArguments
.compareToAscii(RTL_CONSTASCII_STRINGPARAM("{noproxy}"))
70 aProviderArguments(bNoProxy
?
72 copy(RTL_CONSTASCII_LENGTH("{noproxy}")) :
75 // First, try to instantiate proxy for provider:
76 uno::Reference
< ucb::XContentProvider
> xProvider
;
79 uno::Reference
< ucb::XContentProviderFactory
> xProxyFactory
;
83 = uno::Reference
< ucb::XContentProviderFactory
>(
87 RTL_CONSTASCII_USTRINGPARAM(
88 "com.sun.star.ucb.ContentProviderProxyFactory"))),
91 catch (uno::Exception
const &) {}
92 OSL_ENSURE(xProxyFactory
.is(), "No ContentProviderProxyFactory");
93 if (xProxyFactory
.is())
94 xProvider
= xProxyFactory
->createContentProvider(rName
);
97 // Then, try to instantiate provider directly:
101 xProvider
= uno::Reference
< ucb::XContentProvider
>(
102 rServiceFactory
->createInstance(rName
),
105 catch (uno::RuntimeException
const &) { throw; }
106 catch (uno::Exception
const &) {}
108 uno::Reference
< ucb::XContentProvider
>
109 xOriginalProvider(xProvider
);
110 uno::Reference
< ucb::XParameterizedContentProvider
>
111 xParameterized(xProvider
, uno::UNO_QUERY
);
112 if (xParameterized
.is())
114 uno::Reference
< ucb::XContentProvider
> xInstance
;
117 xInstance
= xParameterized
->registerInstance(rTemplate
,
120 //@@@ if this call replaces an old instance, the commit-or-
121 // rollback code below will not work
123 catch (lang::IllegalArgumentException
const &) {}
126 xProvider
= xInstance
;
129 bool bSuccess
= false;
130 if (rManager
.is() && xProvider
.is())
133 rManager
->registerContentProvider(xProvider
, rTemplate
, true);
136 catch (ucb::DuplicateProviderException
const &)
138 if (xParameterized
.is())
141 xParameterized
->deregisterInstance(rTemplate
,
144 catch (lang::IllegalArgumentException
const &) {}
148 if (xParameterized
.is())
151 xParameterized
->deregisterInstance(rTemplate
,
154 catch (lang::IllegalArgumentException
const &) {}
155 catch (uno::RuntimeException
const &) {}
159 if (bSuccess
&& pInfo
)
161 pInfo
->m_xProvider
= xOriginalProvider
;
162 pInfo
->m_aArguments
= aProviderArguments
;
163 pInfo
->m_aTemplate
= rTemplate
;
168 //============================================================================
172 //============================================================================
176 uno::Reference
< ucb::XContentProviderManager
> const & rManager
,
177 ContentProviderRegistrationInfo
const & rInfo
)
178 throw (uno::RuntimeException
)
180 uno::Reference
< ucb::XContentProvider
>
181 xProvider(rInfo
.m_xProvider
);
182 uno::Reference
< ucb::XParameterizedContentProvider
>
183 xParameterized(xProvider
, uno::UNO_QUERY
);
184 if (xParameterized
.is())
186 uno::Reference
< ucb::XContentProvider
> xInstance
;
190 = xParameterized
->deregisterInstance(rInfo
.m_aTemplate
,
193 catch (lang::IllegalArgumentException
const &) {}
196 xProvider
= xInstance
;
200 rManager
->deregisterContentProvider(xProvider
, rInfo
.m_aTemplate
);
201 //@@@ if this fails, a roll-back of deregisterInstance() is