summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-07-25 18:54:38 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-07-25 19:10:19 +0200
commitcf7c9599e776eba8e14614cecb528d3da5778190 (patch)
treeb71a0f46f1975e298197eac6d70a186b3048ada2 /comphelper
parent3605cb216faab6659f4bf90e76d9387df3ac08f6 (diff)
Make comphelper/configuration.hxx work for localized properties
See aebf5bf22304c73e121b16dc0b51f909c5f34c28 "fdo#52232 ConfigurationSet wrapper unusable for localized properties" for a discussion of the problems with the original design. 1 Redesigned configmgr's localized property access to understand ['*<locale>'] paths that select the best existing value match for the requested <locale>. Adapted ConfigurationWrapper::getLocalizedPropertyValue accordingly. 2 Redesigned ConfigurationChanges to fix the locale at instantiation time. That takes care of ConfigurationWrapper::setLocalizedPropertyValue, ConfigurationWrapper::getGroupReadWrite, and ConfigurationWrapper::getSetReadWrite. (This required an additional constructor parameter for the ReadWriteAccess service, to specify a locale at instantiation time.) 3 Redesigned ReadOnlyAccess to be a service that fixes the locale at instantiation time. That allows to take care of ConfigurationWrapper::getGroupReadOnly and ConfigurationWrapper::getSetReadOnly. Change-Id: I2ae7342b278b6f4222a0189a1deb2a53e204059f
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/configuration.hxx2
-rw-r--r--comphelper/source/misc/configuration.cxx109
2 files changed, 61 insertions, 50 deletions
diff --git a/comphelper/inc/comphelper/configuration.hxx b/comphelper/inc/comphelper/configuration.hxx
index 1cf4a263654c..d70b3901b550 100644
--- a/comphelper/inc/comphelper/configuration.hxx
+++ b/comphelper/inc/comphelper/configuration.hxx
@@ -148,8 +148,6 @@ public:
boost::shared_ptr< ConfigurationChanges > createChanges() const;
private:
- rtl::OUString extendLocalizedPath(rtl::OUString const & path) const;
-
com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
context_;
diff --git a/comphelper/source/misc/configuration.cxx b/comphelper/source/misc/configuration.cxx
index 383e35f78657..01ec08fd515a 100644
--- a/comphelper/source/misc/configuration.cxx
+++ b/comphelper/source/misc/configuration.cxx
@@ -64,6 +64,51 @@ struct TheConfigurationWrapper:
TheConfigurationWrapper >
{};
+OUString getDefaultLocale(
+ css::uno::Reference< css::uno::XComponentContext > const & context)
+{
+ css::lang::Locale locale(
+ css::uno::Reference< css::lang::XLocalizable >(
+ css::configuration::theDefaultProvider::get(context),
+ css::uno::UNO_QUERY_THROW)->
+ getLocale());
+ OUStringBuffer buf;
+ SAL_WARN_IF(
+ locale.Language.indexOf('-') != -1, "comphelper",
+ "Locale language \"" << locale.Language << "\" contains \"-\"");
+ buf.append(locale.Language);
+ SAL_WARN_IF(
+ locale.Country.isEmpty() && !locale.Variant.isEmpty(), "comphelper",
+ "Locale has empty country but non-empty variant \"" << locale.Variant
+ << '"');
+ if (!locale.Country.isEmpty()) {
+ buf.append('-');
+ SAL_WARN_IF(
+ locale.Country.indexOf('-') != -1, "comphelper",
+ "Locale language \"" << locale.Country << "\" contains \"-\"");
+ buf.append(locale.Country);
+ if (!locale.Variant.isEmpty()) {
+ buf.append('-');
+ buf.append(locale.Variant);
+ }
+ }
+ return buf.makeStringAndClear();
+}
+
+OUString extendLocalizedPath(OUString const & path, OUString const & locale) {
+ rtl::OUStringBuffer buf(path);
+ buf.append("/['*");
+ SAL_WARN_IF(
+ locale.match("*"), "comphelper",
+ "Locale \"" << locale << "\" starts with \"-\"");
+ assert(locale.indexOf('&') == -1);
+ assert(locale.indexOf('"') == -1);
+ assert(locale.indexOf('\'') == -1);
+ buf.append(locale);
+ buf.append("']");
+ return buf.makeStringAndClear();
+}
+
}
boost::shared_ptr< comphelper::ConfigurationChanges >
@@ -82,7 +127,9 @@ void comphelper::ConfigurationChanges::commit() const {
comphelper::ConfigurationChanges::ConfigurationChanges(
css::uno::Reference< css::uno::XComponentContext > const & context):
- access_(css::configuration::ReadWriteAccess::create(context))
+ access_(
+ css::configuration::ReadWriteAccess::create(
+ context, getDefaultLocale(context)))
{}
void comphelper::ConfigurationChanges::setPropertyValue(
@@ -114,7 +161,8 @@ comphelper::detail::ConfigurationWrapper::get(
comphelper::detail::ConfigurationWrapper::ConfigurationWrapper(
css::uno::Reference< css::uno::XComponentContext > const & context):
- context_(context), access_(css::configuration::ReadOnlyAccess::get(context))
+ context_(context),
+ access_(css::configuration::ReadOnlyAccess::create(context, "*"))
{}
comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() {}
@@ -137,7 +185,8 @@ css::uno::Any
comphelper::detail::ConfigurationWrapper::getLocalizedPropertyValue(
rtl::OUString const & path) const
{
- return access_->getByHierarchicalName(extendLocalizedPath(path));
+ return access_->getByHierarchicalName(
+ extendLocalizedPath(path, getDefaultLocale(context_)));
}
void comphelper::detail::ConfigurationWrapper::setLocalizedPropertyValue(
@@ -145,7 +194,7 @@ void comphelper::detail::ConfigurationWrapper::setLocalizedPropertyValue(
rtl::OUString const & path, com::sun::star::uno::Any const & value) const
{
assert(batch.get() != 0);
- batch->setPropertyValue(extendLocalizedPath(path), value);
+ batch->setPropertyValue(path, value);
}
css::uno::Reference< css::container::XHierarchicalNameAccess >
@@ -153,7 +202,10 @@ comphelper::detail::ConfigurationWrapper::getGroupReadOnly(
rtl::OUString const & path) const
{
return css::uno::Reference< css::container::XHierarchicalNameAccess >(
- access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
+ (css::configuration::ReadOnlyAccess::create(
+ context_, getDefaultLocale(context_))->
+ getByHierarchicalName(path)),
+ css::uno::UNO_QUERY_THROW);
}
css::uno::Reference< css::container::XHierarchicalNameReplace >
@@ -170,7 +222,10 @@ comphelper::detail::ConfigurationWrapper::getSetReadOnly(
rtl::OUString const & path) const
{
return css::uno::Reference< css::container::XNameAccess >(
- access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
+ (css::configuration::ReadOnlyAccess::create(
+ context_, getDefaultLocale(context_))->
+ getByHierarchicalName(path)),
+ css::uno::UNO_QUERY_THROW);
}
css::uno::Reference< css::container::XNameContainer >
@@ -188,46 +243,4 @@ comphelper::detail::ConfigurationWrapper::createChanges() const {
new ConfigurationChanges(context_));
}
-rtl::OUString comphelper::detail::ConfigurationWrapper::extendLocalizedPath(
- rtl::OUString const & path) const
-{
- rtl::OUStringBuffer buf(path);
- buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("/['"));
- css::lang::Locale locale(
- css::uno::Reference< css::lang::XLocalizable >(
- css::configuration::theDefaultProvider::get(context_),
- css::uno::UNO_QUERY_THROW)->
- getLocale());
- SAL_WARN_IF(
- locale.Language.indexOf('-') != -1, "comphelper",
- "Locale language \"" << locale.Language << "\" contains \"-\"");
- assert(locale.Language.indexOf('&') == -1);
- assert(locale.Language.indexOf('"') == -1);
- assert(locale.Language.indexOf('\'') == -1);
- buf.append(locale.Language);
- SAL_WARN_IF(
- locale.Country.isEmpty() && !locale.Variant.isEmpty(), "comphelper",
- "Locale has empty country but non-empty variant \"" << locale.Variant
- << '"');
- if (!locale.Country.isEmpty()) {
- buf.append('-');
- SAL_WARN_IF(
- locale.Country.indexOf('-') != -1, "comphelper",
- "Locale language \"" << locale.Country << "\" contains \"-\"");
- assert(locale.Country.indexOf('&') == -1);
- assert(locale.Country.indexOf('"') == -1);
- assert(locale.Country.indexOf('\'') == -1);
- buf.append(locale.Country);
- if (!locale.Variant.isEmpty()) {
- buf.append('-');
- assert(locale.Variant.indexOf('&') == -1);
- assert(locale.Variant.indexOf('"') == -1);
- assert(locale.Variant.indexOf('\'') == -1);
- buf.append(locale.Variant);
- }
- }
- buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("']"));
- return buf.makeStringAndClear();
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */