24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <com/sun/star/lang/EventObject.hpp>
28 #include <com/sun/star/lang/Locale.hpp>
29 #include <com/sun/star/lang/XLocalizable.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/uno/Exception.hpp>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <com/sun/star/uno/XInterface.hpp>
37 #include <com/sun/star/util/XFlushListener.hpp>
38 #include <com/sun/star/util/XFlushable.hpp>
39 #include <com/sun/star/util/XRefreshListener.hpp>
40 #include <com/sun/star/util/XRefreshable.hpp>
46 #include <osl/mutex.hxx>
48 #include <rtl/ref.hxx>
49 #include <rtl/ustring.hxx>
63 constexpr OUStringLiteral accessServiceName =
64 u"com.sun.star.configuration.ConfigurationAccess";
65 constexpr OUStringLiteral updateAccessServiceName =
66 u"com.sun.star.configuration.ConfigurationUpdateAccess";
69 throw css::uno::Exception(
70 (
"com.sun.star.configuration.ConfigurationProvider expects a single,"
71 " non-empty, string nodepath argument"),
76 cppu::WeakComponentImplHelper<
77 css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
78 css::util::XRefreshable, css::util::XFlushable,
79 css::lang::XLocalizable >
87 const css::uno::Reference< css::uno::XComponentContext >& context):
95 const css::uno::Reference< css::uno::XComponentContext >& context,
96 OUString
const & locale):
101 assert(context.is());
110 virtual void SAL_CALL disposing()
override { flushModifications(); }
116 :
"com.sun.star.comp.configuration.ConfigurationProvider";
122 virtual css::uno::Sequence< OUString > SAL_CALL
127 : css::uno::Sequence<OUString> {
"com.sun.star.configuration.ConfigurationProvider" };
130 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
createInstance(
131 OUString
const & aServiceSpecifier)
override;
133 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
134 createInstanceWithArguments(
135 OUString
const & ServiceSpecifier,
136 css::uno::Sequence< css::uno::Any >
const & Arguments)
override;
138 virtual css::uno::Sequence< OUString > SAL_CALL
139 getAvailableServiceNames()
override;
141 virtual void SAL_CALL refresh()
override;
143 virtual void SAL_CALL addRefreshListener(
144 css::uno::Reference< css::util::XRefreshListener >
const & l)
override;
146 virtual void SAL_CALL removeRefreshListener(
147 css::uno::Reference< css::util::XRefreshListener >
const & l)
override;
149 virtual void SAL_CALL flush()
override;
151 virtual void SAL_CALL addFlushListener(
152 css::uno::Reference< css::util::XFlushListener >
const & l)
override;
154 virtual void SAL_CALL removeFlushListener(
155 css::uno::Reference< css::util::XFlushListener >
const & l)
override;
157 virtual void SAL_CALL
setLocale(css::lang::Locale
const & eLocale)
override;
159 virtual css::lang::Locale SAL_CALL
getLocale()
override;
161 void flushModifications()
const;
163 css::uno::Reference< css::uno::XComponentContext >
context_;
169 css::uno::Reference< css::uno::XInterface > Service::createInstance(
170 OUString
const & aServiceSpecifier)
172 return createInstanceWithArguments(
173 aServiceSpecifier, css::uno::Sequence< css::uno::Any >());
176 css::uno::Reference< css::uno::XInterface >
177 Service::createInstanceWithArguments(
178 OUString
const & ServiceSpecifier,
179 css::uno::Sequence< css::uno::Any >
const & Arguments)
183 for (sal_Int32 i = 0;
i < Arguments.getLength(); ++
i) {
184 css::beans::NamedValue v1;
185 css::beans::PropertyValue v2;
188 if (Arguments[i] >>= v1) {
191 }
else if (Arguments[i] >>= v2) {
194 }
else if (Arguments.getLength() == 1 && (Arguments[
i] >>= nodepath)) {
197 if (nodepath.isEmpty()) {
202 throw css::uno::Exception(
203 (
"com.sun.star.configuration.ConfigurationProvider expects"
204 " NamedValue or PropertyValue arguments"),
209 if (name.equalsIgnoreAsciiCase(
"nodepath")) {
210 if (!nodepath.isEmpty() || !(value >>= nodepath) ||
215 }
else if (name.equalsIgnoreAsciiCase(
"locale")) {
216 if (!locale.isEmpty() || !(value >>= locale) ||
219 throw css::uno::Exception(
220 (
"com.sun.star.configuration.ConfigurationProvider expects"
221 " at most one, non-empty, string Locale argument"),
226 if (nodepath.isEmpty()) {
231 if (nodepath[0] !=
'/') {
232 nodepath =
"/" + nodepath;
234 if (locale.isEmpty()) {
237 if (locale.isEmpty()) {
242 if (ServiceSpecifier == accessServiceName) {
244 }
else if (ServiceSpecifier == updateAccessServiceName) {
247 throw css::uno::Exception(
248 (
"com.sun.star.configuration.ConfigurationProvider does not support"
249 " service " + ServiceSpecifier),
250 static_cast< cppu::OWeakObject * >(
this));
252 osl::MutexGuard guard(*
lock_);
255 new RootAccess(components, nodepath, locale, update));
256 if (root->isValue()) {
257 throw css::uno::Exception(
258 (
"com.sun.star.configuration.ConfigurationProvider: there is a leaf"
259 " value at nodepath " + nodepath),
260 static_cast< cppu::OWeakObject * >(
this));
262 components.addRootAccess(root);
266 css::uno::Sequence< OUString > Service::getAvailableServiceNames()
268 return { accessServiceName, updateAccessServiceName };
271 void Service::refresh() {
275 if (cont !=
nullptr) {
276 css::lang::EventObject ev(static_cast< cppu::OWeakObject * >(
this));
277 cont->
notifyEach(&css::util::XRefreshListener::refreshed, ev);
281 void Service::addRefreshListener(
282 css::uno::Reference< css::util::XRefreshListener >
const & l)
284 rBHelper.addListener(
288 void Service::removeRefreshListener(
289 css::uno::Reference< css::util::XRefreshListener >
const & l)
291 rBHelper.removeListener(
295 void Service::flush() {
296 flushModifications();
299 if (cont !=
nullptr) {
300 css::lang::EventObject ev(static_cast< cppu::OWeakObject * >(
this));
301 cont->
notifyEach(&css::util::XFlushListener::flushed, ev);
305 void Service::addFlushListener(
306 css::uno::Reference< css::util::XFlushListener >
const & l)
311 void Service::removeFlushListener(
312 css::uno::Reference< css::util::XFlushListener >
const & l)
314 rBHelper.removeListener(
318 void Service::setLocale(css::lang::Locale
const & eLocale)
320 osl::MutexGuard guard(*
lock_);
324 css::lang::Locale Service::getLocale() {
325 osl::MutexGuard guard(*
lock_);
326 css::lang::Locale loc;
333 void Service::flushModifications()
const {
336 osl::MutexGuard guard(*
lock_);
339 components->flushModifications();
342 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
343 com_sun_star_comp_configuration_ConfigurationProvider_get_implementation(
344 css::uno::XComponentContext* Context, css::uno::Sequence<css::uno::Any>
const& Arguments)
346 if (!Arguments.hasElements()) {
347 auto p = css::configuration::theDefaultProvider::get(Context);
352 for (sal_Int32 i = 0;
i < Arguments.getLength(); ++
i) {
353 css::beans::NamedValue v1;
354 css::beans::PropertyValue v2;
357 if (Arguments[i] >>= v1) {
360 }
else if (Arguments[i] >>= v2) {
364 throw css::uno::Exception(
365 (
"com.sun.star.configuration.ConfigurationProvider factory"
366 " expects NamedValue or PropertyValue arguments"),
371 if (name.equalsIgnoreAsciiCase(
"locale")) {
372 if (!locale.isEmpty() || !(value >>= locale) ||
375 throw css::uno::Exception(
376 (
"com.sun.star.configuration.ConfigurationProvider"
377 " factory expects at most one, non-empty, string"
381 }
else if (!name.equalsIgnoreAsciiCase(
"enableasync")) {
382 throw css::uno::Exception(
383 (
"com.sun.star.configuration.ConfigurationProvider factory:"
384 " unknown argument " + name),
388 return cppu::acquire(
new Service(Context, locale));
395 css::uno::Reference< css::uno::XComponentContext >
const & context)
static OUString convertToBcp47(LanguageType nLangID)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
css::uno::Reference< css::uno::XComponentContext > context_
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
css::uno::Reference< css::uno::XInterface > createDefault(css::uno::Reference< css::uno::XComponentContext > const &context)
const LanguageTag & getLocale()
std::vector< uno::Reference< sheet::XSpreadsheetDocument > > Components
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
std::shared_ptr< osl::Mutex > lock_
std::shared_ptr< osl::Mutex > const & lock()
static Components & getSingleton(css::uno::Reference< css::uno::XComponentContext > const &context)
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
void setLocale(const LanguageTag &languageTag)