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>
49#include <rtl/ustring.hxx>
64constexpr OUStringLiteral accessServiceName =
65 u"com.sun.star.configuration.ConfigurationAccess";
66constexpr OUStringLiteral updateAccessServiceName =
67 u"com.sun.star.configuration.ConfigurationUpdateAccess";
70 throw css::uno::Exception(
71 (
"com.sun.star.configuration.ConfigurationProvider expects a single,"
72 " non-empty, string nodepath argument"),
77 cppu::WeakComponentImplHelper<
78 css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
79 css::util::XRefreshable, css::util::XFlushable,
80 css::lang::XLocalizable >
88 const css::uno::Reference< css::uno::XComponentContext >& context):
96 const css::uno::Reference< css::uno::XComponentContext >& context,
102 assert(context.is());
109 virtual ~Service()
override {}
111 virtual void SAL_CALL disposing()
override { flushModifications(); }
117 :
"com.sun.star.comp.configuration.ConfigurationProvider";
123 virtual css::uno::Sequence< OUString > SAL_CALL
128 : css::uno::Sequence<OUString> {
"com.sun.star.configuration.ConfigurationProvider" };
131 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
createInstance(
132 OUString
const & aServiceSpecifier)
override;
134 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
135 createInstanceWithArguments(
136 OUString
const & ServiceSpecifier,
137 css::uno::Sequence< css::uno::Any >
const & Arguments)
override;
139 virtual css::uno::Sequence< OUString > SAL_CALL
140 getAvailableServiceNames()
override;
142 virtual void SAL_CALL refresh()
override;
144 virtual void SAL_CALL addRefreshListener(
145 css::uno::Reference< css::util::XRefreshListener >
const & l)
override;
147 virtual void SAL_CALL removeRefreshListener(
148 css::uno::Reference< css::util::XRefreshListener >
const & l)
override;
150 virtual void SAL_CALL flush()
override;
152 virtual void SAL_CALL addFlushListener(
153 css::uno::Reference< css::util::XFlushListener >
const & l)
override;
155 virtual void SAL_CALL removeFlushListener(
156 css::uno::Reference< css::util::XFlushListener >
const & l)
override;
158 virtual void SAL_CALL
setLocale(css::lang::Locale
const & eLocale)
override;
160 virtual css::lang::Locale SAL_CALL
getLocale()
override;
162 void flushModifications()
const;
164 css::uno::Reference< css::uno::XComponentContext >
context_;
170css::uno::Reference< css::uno::XInterface > Service::createInstance(
171 OUString
const & aServiceSpecifier)
173 return createInstanceWithArguments(
174 aServiceSpecifier, css::uno::Sequence< css::uno::Any >());
177css::uno::Reference< css::uno::XInterface >
178Service::createInstanceWithArguments(
179 OUString
const & ServiceSpecifier,
180 css::uno::Sequence< css::uno::Any >
const & Arguments)
184 for (sal_Int32 i = 0;
i < Arguments.getLength(); ++
i) {
185 css::beans::NamedValue v1;
186 css::beans::PropertyValue v2;
189 if (Arguments[i] >>= v1) {
192 }
else if (Arguments[i] >>= v2) {
195 }
else if (Arguments.getLength() == 1 && (Arguments[i] >>= nodepath)) {
198 if (nodepath.isEmpty()) {
203 throw css::uno::Exception(
204 (
"com.sun.star.configuration.ConfigurationProvider expects"
205 " NamedValue or PropertyValue arguments"),
210 if (
name.equalsIgnoreAsciiCase(
"nodepath")) {
211 if (!nodepath.isEmpty() || !(value >>= nodepath) ||
216 }
else if (
name.equalsIgnoreAsciiCase(
"locale")) {
217 if (!locale.isEmpty() || !(value >>= locale) ||
220 throw css::uno::Exception(
221 (
"com.sun.star.configuration.ConfigurationProvider expects"
222 " at most one, non-empty, string Locale argument"),
227 if (nodepath.isEmpty()) {
232 if (nodepath[0] !=
'/') {
233 nodepath =
"/" + nodepath;
235 if (locale.isEmpty()) {
238 if (locale.isEmpty()) {
243 if (ServiceSpecifier == accessServiceName) {
245 }
else if (ServiceSpecifier == updateAccessServiceName) {
248 throw css::uno::Exception(
249 (
"com.sun.star.configuration.ConfigurationProvider does not support"
250 " service " + ServiceSpecifier),
253 osl::MutexGuard guard(*
lock_);
256 new RootAccess(components, nodepath, locale, update));
257 if (root->isValue()) {
258 throw css::uno::Exception(
259 (
"com.sun.star.configuration.ConfigurationProvider: there is a leaf"
260 " value at nodepath " + nodepath),
263 components.addRootAccess(root);
267css::uno::Sequence< OUString > Service::getAvailableServiceNames()
269 return { accessServiceName, updateAccessServiceName };
272void Service::refresh() {
276 if (cont !=
nullptr) {
278 cont->
notifyEach(&css::util::XRefreshListener::refreshed, ev);
282void Service::addRefreshListener(
283 css::uno::Reference< css::util::XRefreshListener >
const & l)
285 rBHelper.addListener(
289void Service::removeRefreshListener(
290 css::uno::Reference< css::util::XRefreshListener >
const & l)
292 rBHelper.removeListener(
296void Service::flush() {
297 flushModifications();
300 if (cont !=
nullptr) {
302 cont->
notifyEach(&css::util::XFlushListener::flushed, ev);
306void Service::addFlushListener(
307 css::uno::Reference< css::util::XFlushListener >
const & l)
312void Service::removeFlushListener(
313 css::uno::Reference< css::util::XFlushListener >
const & l)
315 rBHelper.removeListener(
319void Service::setLocale(css::lang::Locale
const & eLocale)
321 osl::MutexGuard guard(*
lock_);
325css::lang::Locale Service::getLocale() {
326 osl::MutexGuard guard(*
lock_);
327 css::lang::Locale loc;
334void Service::flushModifications()
const {
337 osl::MutexGuard guard(*
lock_);
340 components->flushModifications();
343extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
344com_sun_star_comp_configuration_ConfigurationProvider_get_implementation(
345 css::uno::XComponentContext* Context, css::uno::Sequence<css::uno::Any>
const& Arguments)
347 if (!Arguments.hasElements()) {
348 auto p = css::configuration::theDefaultProvider::get(Context);
353 for (sal_Int32 i = 0;
i < Arguments.getLength(); ++
i) {
354 css::beans::NamedValue v1;
355 css::beans::PropertyValue v2;
358 if (Arguments[i] >>= v1) {
361 }
else if (Arguments[i] >>= v2) {
365 throw css::uno::Exception(
366 (
"com.sun.star.configuration.ConfigurationProvider factory"
367 " expects NamedValue or PropertyValue arguments"),
372 if (
name.equalsIgnoreAsciiCase(
"locale")) {
373 if (!locale.isEmpty() || !(value >>= locale) ||
376 throw css::uno::Exception(
377 (
"com.sun.star.configuration.ConfigurationProvider"
378 " factory expects at most one, non-empty, string"
382 }
else if (!
name.equalsIgnoreAsciiCase(
"enableasync")) {
383 throw css::uno::Exception(
384 (
"com.sun.star.configuration.ConfigurationProvider factory:"
385 " unknown argument " +
name),
389 return cppu::acquire(
new Service(Context, locale));
396 css::uno::Reference< css::uno::XComponentContext >
const & context)
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static OUString convertToBcp47(LanguageType nLangID)
static Components & getSingleton(css::uno::Reference< css::uno::XComponentContext > const &context)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
css::uno::Reference< css::uno::XComponentContext > context_
std::shared_ptr< osl::Mutex > lock_
const LanguageTag & getLocale()
void setLocale(const LanguageTag &languageTag)
css::uno::Reference< css::uno::XInterface > createDefault(css::uno::Reference< css::uno::XComponentContext > const &context)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
std::shared_ptr< osl::Mutex > const & lock()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::vector< uno::Reference< sheet::XSpreadsheetDocument > > Components