diff --git a/mozilla/intl/strres/public/nsIStringBundle.h b/mozilla/intl/strres/public/nsIStringBundle.h index caa12f9c818..364a82e8194 100644 --- a/mozilla/intl/strres/public/nsIStringBundle.h +++ b/mozilla/intl/strres/public/nsIStringBundle.h @@ -22,6 +22,7 @@ #include "nsILocale.h" #include "nsIURL.h" #include "nsString.h" +#include "nsIEnumerator.h" // {D85A17C0-AA7C-11d2-9B8C-00805F8A16D9} #define NS_ISTRINGBUNDLESERVICE_IID \ @@ -45,6 +46,7 @@ class nsIStringBundle : public nsISupports public: NS_IMETHOD GetStringFromID(PRInt32 aID, nsString& aResult) = 0; NS_IMETHOD GetStringFromName(const nsString& aName, nsString& aResult) = 0; + NS_IMETHOD GetEnumeration(nsIBidirectionalEnumerator** elements) = 0; }; class nsIStringBundleService : public nsISupports diff --git a/mozilla/intl/strres/src/nsStringBundle.cpp b/mozilla/intl/strres/src/nsStringBundle.cpp index ddc4dbf4be2..ecf882684bf 100644 --- a/mozilla/intl/strres/src/nsStringBundle.cpp +++ b/mozilla/intl/strres/src/nsStringBundle.cpp @@ -55,6 +55,7 @@ public: NS_IMETHOD GetStringFromID(PRInt32 aID, nsString& aResult); NS_IMETHOD GetStringFromName(const nsString& aName, nsString& aResult); + NS_IMETHOD GetEnumeration(nsIBidirectionalEnumerator** elements); nsIPersistentProperties* mProps; }; @@ -127,6 +128,17 @@ nsStringBundle::GetStringFromName(const nsString& aName, nsString& aResult) return ret; } +NS_IMETHODIMP +nsStringBundle::GetEnumeration(nsIBidirectionalEnumerator** elements) +{ + if (!elements) + return NS_ERROR_INVALID_POINTER; + + nsresult ret = mProps->EnumerateProperties(elements); + + return ret; +} + class nsStringBundleService : public nsIStringBundleService { public: diff --git a/mozilla/intl/strres/tests/StringBundleTest.cpp b/mozilla/intl/strres/tests/StringBundleTest.cpp index 57c8bb4da17..e62a2cedd8c 100644 --- a/mozilla/intl/strres/tests/StringBundleTest.cpp +++ b/mozilla/intl/strres/tests/StringBundleTest.cpp @@ -121,5 +121,51 @@ main(int argc, char *argv[]) value = v.ToNewCString(); cout << "123=\"" << value << "\"" << endl; + nsIBidirectionalEnumerator* propEnum = nsnull; + ret = bundle->GetEnumeration(&propEnum); + if (NS_FAILED(ret)) { + printf("cannot get enumeration\n"); + return 1; + } + ret = propEnum->First(); + if (NS_FAILED(ret)) + { + printf("enumerator is empty\n"); + return 1; + } + + cout << endl << "Key" << "\t" << "Value" << endl; + cout << "---" << "\t" << "-----" << endl; + while (NS_SUCCEEDED(ret)) + { + nsIPropertyElement* propElem = nsnull; + ret = propEnum->CurrentItem((nsISupports**)&propElem); + if (NS_FAILED(ret)) { + printf("failed to get current item\n"); + return 1; + } + nsString* key = nsnull; + nsString* val = nsnull; + ret = propElem->GetKey(&key); + if (NS_FAILED(ret)) { + printf("failed to get current element's key\n"); + return 1; + } + ret = propElem->GetValue(&val); + if (NS_FAILED(ret)) { + printf("failed to get current element's value\n"); + return 1; + } + char* keyCStr = key->ToNewCString(); + char* valCStr = val->ToNewCString(); + if (keyCStr && valCStr) + cout << keyCStr << "\t" << valCStr << endl; + delete[] keyCStr; + delete[] valCStr; + delete key; + delete val; + ret = propEnum->Next(); + } + return 0; }