How To Read Resource Bundle Under "administation" Folder Using Java

Hello,

Is there a way (using Java) to read resource bundles under the administration folder if I only know the path or id of the bundle? Please see the screenshot below, these are the resource bundles that I want to get the contents of.

Thanks!

You should be able to use the following

org.hippoecm.hst.resourcebundle.ResourceBundleUtils#getBundle(String basename, Locale locale, boolean fallbackToJavaResourceBundle)

Hi Jasper,

Thank you for the response. I did try it, but for some reason it wasnā€™t working. On debugging it appears that it doesnā€™t have the request context and so it is unable to lookup the document. I am able to get to the document node by querying it this way:

getSession()
.getRootNode()
.getNode("content/documents/administration/configuration")
.getNode("url.configurations")

Here, ā€œurl.configurationsā€ is the id of the resource bundle. Now, Iā€™m trying to figure out how to get the content (and properties) from the node.

I figured out how to get the HippoDocument from the node. The only issue I have now is how to get the RequestContext from a J2EE Filter.

Assuming that (a) you have some reason to execute your servlet filter before the HstFilter is executed and (b) it is fine to read only ā€˜liveā€™ content of the resource bundle, you can possibly try this:

            final ResourceBundleRegistry resourceBundleRegistry =
                    HstServices.getComponentManager().getComponent(ResourceBundleRegistry.class.getName());

            if (resourceBundleRegistry != null) {
                if (locale == null) {
                    bundle = resourceBundleRegistry.getBundle(basename);
                } else {
                    bundle = resourceBundleRegistry.getBundle(basename, locale);
                }
            }

where locale is the local you want to use from the bundle and basename is the resource bundle id.

Regards,

Woonsan

1 Like

Oh wow, awesome. Let me try that :slight_smile:

Fantastic! Works really well!