diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-07-25 18:54:38 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-07-25 19:10:19 +0200 |
commit | cf7c9599e776eba8e14614cecb528d3da5778190 (patch) | |
tree | b71a0f46f1975e298197eac6d70a186b3048ada2 /configmgr/source/childaccess.cxx | |
parent | 3605cb216faab6659f4bf90e76d9387df3ac08f6 (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 'configmgr/source/childaccess.cxx')
-rw-r--r-- | configmgr/source/childaccess.cxx | 76 |
1 files changed, 5 insertions, 71 deletions
diff --git a/configmgr/source/childaccess.cxx b/configmgr/source/childaccess.cxx index 3b5a8e289420..99c4d2df587c 100644 --- a/configmgr/source/childaccess.cxx +++ b/configmgr/source/childaccess.cxx @@ -259,17 +259,6 @@ void ChildAccess::setProperty( localModifications->add(getRelativePath()); } -namespace -{ - rtl::OUString lcl_StripSegment(const rtl::OUString &rLocale) - { - sal_Int32 i = !rLocale.isEmpty() ? rLocale.getLength() - 1 : 0; - while (i > 0 && rLocale[i] != '-' && rLocale[i] != '_') - --i; - return rLocale.copy(0, i); - } -} - css::uno::Any ChildAccess::asValue() { if (changedValue_.get() != 0) { return *changedValue_; @@ -280,66 +269,11 @@ css::uno::Any ChildAccess::asValue() { getComponents()); case Node::KIND_LOCALIZED_PROPERTY: { - rtl::OUString sLocale(getRootAccess()->getLocale()); - if (!Components::allLocales(sLocale)) - { - rtl::Reference< ChildAccess > child; - // Find best match using an adaption of RFC 4647 lookup matching - // rules, removing "-" or "_" delimited segments from the end - while (1) - { - child = getChild(sLocale); - if (child.is()) - break; - rtl::OUString sTmpLocale = lcl_StripSegment(sLocale); - if (sTmpLocale.isEmpty()) - break; - sLocale = sTmpLocale; - } - - //Resolves: fdo#33638 Look for the first entry with the same - //first segment as the requested language tag, before falling - //back to en-US, etc. - typedef std::vector< rtl::Reference< ChildAccess > > ChildVector; - if (!child.is()) - { - const ChildVector &rAllChildren = getAllChildren(); - for (ChildVector::const_iterator aI = rAllChildren.begin(), - aEnd = rAllChildren.end(); aI != aEnd; ++aI) - { - rtl::OUString sLanguage = lcl_StripSegment((*aI)->getNameInternal()); - if (sLocale == sLanguage) - { - child = *aI; - break; - } - } - } - - // defaults are the "en-US" locale, the "en" locale, the empty - // string locale, the first child (if any), or a nil value (even - // though it may be illegal for the given property), in that - // order: - if (!child.is()) - { - child = getChild( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en-US"))); - if (!child.is()) - { - child = getChild( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"))); - if (!child.is()) - { - child = getChild(rtl::OUString()); - if (!child.is()) - { - ChildVector all(getAllChildren()); - if (!all.empty()) - child = all.front(); - } - } - } - } + OUString locale(getRootAccess()->getLocale()); + if (!Components::allLocales(locale)) { + rtl::Reference< ChildAccess > child(getChild("*" + locale)); + // As a last resort, return a nil value even though it may be + // illegal for the given property: return child.is() ? child->asValue() : css::uno::Any(); } } |