shale-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Reddin (JIRA)" <j...@apache.org>
Subject [jira] Commented: (SHALE-485) ResourceBundle lookup failure in MockApplication12
Date Wed, 12 Mar 2008 15:14:13 GMT

    [ https://issues.apache.org/struts/browse/SHALE-485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43503#action_43503
] 

Greg Reddin commented on SHALE-485:
-----------------------------------

Thank you for raising this. This very well might be why I couldn't get the 1.0 branch to build
a few weeks ago. The Validator tests were failing because it was not able to load the resource
bundle. I will try to find time in the next week or so to investigate your solution and see
if I can get it to work. In the meantime if you'd like to post a patch using svn diff that
would be greatly appreciated.

Thanks,
Greg



> ResourceBundle lookup failure in MockApplication12
> --------------------------------------------------
>
>                 Key: SHALE-485
>                 URL: https://issues.apache.org/struts/browse/SHALE-485
>             Project: Shale
>          Issue Type: Bug
>          Components: Test
>    Affects Versions: 1.0.4
>         Environment: Java 5, JSF 1.2, i686 GNU/Linux
>            Reporter: Tim Kroeger
>
> MockApplication12.getResourceBundle(FacesContext context, String name) is intended to
lookup the resource bundle's base name prior to requesting the resource via ResourceBundle.getBundle(name,
locale). In the current implementation it tries to lookup the name of the resource registered
with the application, which is wrong. Consider a resource bundle added via
> 	ResourceBundle bundle = ResourceBundle.getBundle("foo.bar.resource", new Locale("de",
"DE"));
> 	((MockApplication12) application).addResourceBundle("fooBarResource", bundle);
> and e.g. a validator you want to test which composes a new localized FacesMessage by
doing
> 	context.getApplication().getResourceBundle(context, "fooBarResource").getString("message");
> which simulates what would happen in an application where you configured your resource
bundles via faces-config.xml.
> This will throw a MissingResourceException since
>     public ResourceBundle getResourceBundle(FacesContext context, String name) {
>         if ((context == null) || (name == null)) {
>             throw new NullPointerException();
>         }
>         Locale locale = null;
>         UIViewRoot viewRoot = context.getViewRoot();
>         if (viewRoot != null) {
>             locale = viewRoot.getLocale();
>         }
>         if (locale == null) {
>             locale = Locale.getDefault();
>         }
>         return ResourceBundle.getBundle(name, locale);
>     }
> tries to lookup "fooBarResource" with it's classLoader. Instead of that, one should either
do something like:
>     public ResourceBundle getResourceBundle(FacesContext context, String name) {
>         if ((context == null) || (name == null)) {
>             throw new NullPointerException();
>         }
>         if (!bundles.containsKey(name)) {
>             return null;
>         }
>         Locale locale = null;
>         UIViewRoot viewRoot = context.getViewRoot();
>         if (viewRoot != null) {
>             locale = viewRoot.getLocale();
>         }
>         if (locale == null) {
>             locale = Locale.getDefault();
>         }
>         return bundles.get(name);
>     }
> which completely drops any locale context but at least returns a resource bundle, that
was added with the corresponding key
> OR
> one could go ahead and implement a solution, where only the mapping 'name -> baseName'
is stored in a map instead of mappings to ResourceBundles, so MockApplication12.getResourceBundle
can lookup the baseName via the provided name parameter as key to the bundles Map property
and then utilize ResourceBundle.getBundle() to lookup the bundle with the desired locale.
That at least is, what Sun does in it's com.sun.faces.application.ApplicationAssociate which
is used by com.sun.faces.application.ApplicationImpl.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message