[jira] Created: (SHALE-485) ResourceBundle lookup failure in MockApplication12

2008-03-12 Thread Tim Kroeger (JIRA)
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.



[jira] Commented: (SHALE-485) ResourceBundle lookup failure in MockApplication12

2008-03-12 Thread Tim Kroeger (JIRA)

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

Tim Kroeger commented on SHALE-485:
---

That means, MockApplication12.addResourceBundle() should add the name and 
baseName, not the name and the resource bundle since it is dependent on the 
locale possibly at request time. -> addResourceBundle(String name, String 
baseName) {}

> 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.



[jira] Commented: (SHALE-485) ResourceBundle lookup failure in MockApplication12

2008-03-14 Thread Tim Kroeger (JIRA)

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

Tim Kroeger commented on SHALE-485:
---

Index: 
/home/tkroeger/projects/work_shale/shale-framework/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java
===
--- 
/home/tkroeger/projects/work_shale/shale-framework/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java
   (revision 636687)
+++ 
/home/tkroeger/projects/work_shale/shale-framework/shale-test/src/main/java/org/apache/shale/test/mock/MockApplication12.java
   (working copy)
@@ -115,10 +115,10 @@
  * this application.
  *
  * @param name Name under which to add this resource bundle
- * @param bundle ResourceBundle to add
+ * @param baseName base name of ResourceBundle to add
  */
-public void addResourceBundle(String name, ResourceBundle bundle) {
-bundles.put(name, bundle);
+public void addResourceBundle(String name, String baseName) {
+bundles.put(name, baseName);
 }
 
 
@@ -123,8 +123,8 @@
 
 
 /**
- * Return a Map of the resource bundles configured
- * for this application, keyed by name.
+ * Return a Map of the resource bundle base names
+ * configured for this application, keyed by name.
  */
 public Map getResourceBundles() {
 return bundles;
@@ -250,6 +250,9 @@
 if ((context == null) || (name == null)) {
 throw new NullPointerException();
 }
+if (!bundles.containsKey(name)) {
+   return null;
+}
 Locale locale = null;
 UIViewRoot viewRoot = context.getViewRoot();
 if (viewRoot != null) {
@@ -258,7 +261,16 @@
 if (locale == null) {
 locale = Locale.getDefault();
 }
-return ResourceBundle.getBundle(name, locale);
+String baseName = (String) bundles.get(name);
+ResourceBundle result = null;
+
+if (null != baseName) {
+result = ResourceBundle.getBundle(baseName,
+  locale,
+  Thread.currentThread().
+  getContextClassLoader());
+}
+return result;
 
 }
 


> 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.get

[jira] Commented: (SHALE-485) ResourceBundle lookup failure in MockApplication12

2008-03-14 Thread Tim Kroeger (JIRA)

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

Tim Kroeger commented on SHALE-485:
---

Greg,

this patch fixes the problems I encountered with additional resource bundles. 
It does NOT fix the failing validator tests you mentioned. These problems don't 
seem to be related as far as I could tell, since the failing 
converter/validator tests have something to do with the message bundle lookup 
(and its fallbacks), not simple resource bundles.

> 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.



[jira] Updated: (SHALE-485) ResourceBundle lookup failure in MockApplication12

2008-03-20 Thread Tim Kroeger (JIRA)

 [ 
https://issues.apache.org/struts/browse/SHALE-485?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tim Kroeger updated SHALE-485:
--

Flags: [Patch, Important]

> 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.



[jira] Updated: (SHALE-485) ResourceBundle lookup failure in MockApplication12

2008-04-04 Thread Tim Kroeger (JIRA)

 [ 
https://issues.apache.org/struts/browse/SHALE-485?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tim Kroeger updated SHALE-485:
--

Affects Version/s: 1.1.0-SNAPSHOT
   1.0.6-SNAPSHOT
   1.0.5-SNAPSHOT

> 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, 1.0.5-SNAPSHOT, 1.0.6-SNAPSHOT, 1.1.0-SNAPSHOT
> 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.