1 16 package org.apache.myfaces.util.bundle; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import javax.faces.context.FacesContext; 22 import javax.faces.el.VariableResolver; 23 import java.util.MissingResourceException ; 24 import java.util.ResourceBundle ; 25 26 31 public class BundleUtils 32 { 33 private static final Log log = LogFactory.getLog(BundleUtils.class); 34 35 private BundleUtils() 36 { 37 } 39 40 public static ResourceBundle findResourceBundle(FacesContext facesContext, 41 String bundleName) 42 { 43 45 VariableResolver vr = facesContext.getApplication().getVariableResolver(); 47 ResourceBundle bundle = (ResourceBundle )vr.resolveVariable(facesContext, bundleName); 48 49 return bundle; 50 } 51 52 public static String getString(FacesContext facesContext, 53 String bundleName, String key) 54 { 55 ResourceBundle bundle = findResourceBundle(facesContext, bundleName); 56 if (bundle != null) 57 { 58 try 59 { 60 return bundle.getString(key); 61 } 62 catch (MissingResourceException e) 63 { 64 log.warn("Resource string '" + key + "' in bundle '" + bundleName + "' could not be found."); 65 return key; 66 } 67 } 68 else 69 { 70 return key; 71 } 72 } 73 74 } 75 | Popular Tags |