From 6bd994f4346d5e58eaab8f8c7232b04a9e6aca1d Mon Sep 17 00:00:00 2001 From: fgerlits Date: Thu, 23 Feb 2006 17:22:12 +0000 Subject: [PATCH] added "get key from inside a bundle contained in this bundle" functions --- .../LiveSupport/Core/LocalizedObject.h | 69 ++++++++++++++++++- .../src/modules/core/src/LocalizedObject.cxx | 10 +-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/livesupport/src/modules/core/include/LiveSupport/Core/LocalizedObject.h b/livesupport/src/modules/core/include/LiveSupport/Core/LocalizedObject.h index 42ca8771f..3f9287ed5 100644 --- a/livesupport/src/modules/core/include/LiveSupport/Core/LocalizedObject.h +++ b/livesupport/src/modules/core/include/LiveSupport/Core/LocalizedObject.h @@ -188,7 +188,23 @@ class LocalizedObject * the specified key */ Ptr::Ref - getBundle(const char * key) throw (std::invalid_argument); + getBundle(const char * key) throw (std::invalid_argument) + { + return getBundle(getBundle(), key); + } + + /** + * Get a resource bundle nested inside our bundle. + * + * @param bundle the resource bundle containing the key. + * @param key the name of the nested resource bundle to get. + * @exception std::invalid_argument if there is no bundle by + * the specified key + */ + Ptr::Ref + getBundle(Ptr::Ref bundle, + const char * key) + throw (std::invalid_argument); /** * Get a string from the resource bundle. @@ -200,6 +216,40 @@ class LocalizedObject */ virtual Ptr::Ref getResourceString(const char * key) + throw (std::invalid_argument) + { + return getResourceString(getBundle(), key); + } + + /** + * Get a string from the resource bundle. + * + * @param bundle the nested resource bundle containing the key. + * @param key the key identifying the requested string. + * @return the requested string + * @exception std::invalid_argument if there is no string for the + * specified key. + */ + virtual Ptr::Ref + getResourceString(const char * bundle, + const char * key) + throw (std::invalid_argument) + { + return getResourceString(getBundle(bundle), key); + } + + /** + * Get a string from the resource bundle. + * + * @param bundle the nested resource bundle containing the key. + * @param key the key identifying the requested string. + * @return the requested string + * @exception std::invalid_argument if there is no string for the + * specified key. + */ + virtual Ptr::Ref + getResourceString(Ptr::Ref bundle, + const char * key) throw (std::invalid_argument); /** @@ -389,6 +439,23 @@ class LocalizedObject return unicodeStringToUstring(getResourceString(key.c_str())); } + /** + * Get a string from a resource bundle nested inside this bundle, + * as a Glib ustring. + * + * @param bundle the name of the resource bundle to get. + * @param key the key identifying the requested string. + * @return the requested string + * @exception std::invalid_argument if there is no string for the + * specified key. + */ + Ptr::Ref + getResourceUstring(const char * bundle, + const char * key) + throw (std::invalid_argument) + { + return unicodeStringToUstring(getResourceString(bundle, key) ); + } }; /* ================================================= external data structures */ diff --git a/livesupport/src/modules/core/src/LocalizedObject.cxx b/livesupport/src/modules/core/src/LocalizedObject.cxx index eec6c2885..5f9e2a8ea 100644 --- a/livesupport/src/modules/core/src/LocalizedObject.cxx +++ b/livesupport/src/modules/core/src/LocalizedObject.cxx @@ -112,7 +112,8 @@ LocalizedObject :: getBundle(const xmlpp::Element & element) * Get a resource bundle by the specified key *----------------------------------------------------------------------------*/ Ptr::Ref -LocalizedObject :: getBundle(const char * key) +LocalizedObject :: getBundle(Ptr::Ref bundle, + const char * key) throw (std::invalid_argument) { UErrorCode status = U_ZERO_ERROR; @@ -132,13 +133,14 @@ LocalizedObject :: getBundle(const char * key) /*------------------------------------------------------------------------------ - * Get a string from a resource bundle un Glib ustring format + * Get a string from a resource bundle in the ICU string format *----------------------------------------------------------------------------*/ Ptr::Ref -LocalizedObject :: getResourceString(const char * key) +LocalizedObject :: getResourceString(Ptr::Ref bundle, + const char * key) throw (std::invalid_argument) { - Ptr::Ref rb = getBundle(key); + Ptr::Ref rb = getBundle(bundle, key); if (rb->getType() == URES_STRING) { UErrorCode status = U_ZERO_ERROR; Ptr::Ref str(new UnicodeString(rb->getString(status)));