Return-Path: Delivered-To: apmail-shale-issues-archive@locus.apache.org Received: (qmail 65115 invoked from network); 4 Apr 2008 17:20:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Apr 2008 17:20:36 -0000 Received: (qmail 92346 invoked by uid 500); 4 Apr 2008 17:20:33 -0000 Delivered-To: apmail-shale-issues-archive@shale.apache.org Received: (qmail 92293 invoked by uid 500); 4 Apr 2008 17:20:33 -0000 Mailing-List: contact issues-help@shale.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@shale.apache.org Delivered-To: mailing list issues@shale.apache.org Received: (qmail 92195 invoked by uid 99); 4 Apr 2008 17:20:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 10:20:33 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 17:19:59 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id B7F17234C0B8 for ; Fri, 4 Apr 2008 10:17:58 -0700 (PDT) Message-ID: <1677321716.1207329478748.JavaMail.jira@brutus> Date: Fri, 4 Apr 2008 10:17:58 -0700 (PDT) From: "Gary VanMatre (JIRA)" To: issues@shale.apache.org Subject: [jira] Commented: (SHALE-485) ResourceBundle lookup failure in MockApplication12 In-Reply-To: <628304320.1205317569294.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/struts/browse/SHALE-485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43583#action_43583 ] Gary VanMatre commented on SHALE-485: ------------------------------------- What effect does explicitly setting the locale of the view root in the setUp have on this problem? protected void setUp() throws Exception { super.setUp(); facesContext.getViewRoot().setLocale(new Locale("de", "DE")); } > 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.