List of usage examples for java.util ResourceBundle getString
public final String getString(String key)
From source file:be.fedict.eidviewer.lib.X509Utilities.java
public static List<String> getKeyUsageStrings(ResourceBundle bundle, boolean[] keyUsage) { List<String> uses = new ArrayList<String>(9); for (int i = 0; i < keyUsage.length; i++) if (keyUsage[i]) uses.add(bundle.getString(keyUsageStringNames.get(i))); return uses;/*from ww w .j a v a 2s . co m*/ }
From source file:org.tinymediamanager.scraper.entities.MediaGenres.java
/** * Iterates over all found languages and gets the "alternative name" of specified property * /*ww w . j av a 2 s . c om*/ * @param propName * the property * @return array of alternate names */ public static String[] loadAlternateNames(String propName) { ArrayList<String> alt = new ArrayList<>(); for (Locale loc : getLanguages()) { if (loc == null || loc.getLanguage().equals("en")) { // English not needed, since it's in default properties // and for invalid languages (like NB) it will be null continue; } ResourceBundle b = ApiResourceBundle.getResourceBundle(loc); try { alt.add(loc.getLanguage() + "-" + b.getString("Genres." + propName)); // just genres } catch (Exception e) { // not found or localized - ignore } } return alt.toArray(new String[alt.size()]); }
From source file:org.alfresco.extension.scripting.javascript.JavascriptHelper.java
public static String getMessage(String messageId, Object[] args) { Context cx = Context.getCurrentContext(); Locale locale = cx == null ? Locale.getDefault() : cx.getLocale(); // ResourceBundle does cacheing. ResourceBundle rb = ResourceBundle.getBundle("org.alfresco.extension.scripting.javascript.Messages", locale);//w w w .jav a2 s.c o m String formatString; try { formatString = rb.getString(messageId); } catch (java.util.MissingResourceException mre) { throw new RuntimeException("no message resource found for message property " + messageId); } if (args == null) { return formatString; } else { MessageFormat formatter = new MessageFormat(formatString); return formatter.format(args); } }
From source file:gov.nasa.ensemble.common.CommonPlugin.java
/** * Returns the string from the plugin's resource bundle, * or 'key' if not found./*from w ww . j a v a2 s . c om*/ */ public static String getResourceString(String key) { ResourceBundle bundle = CommonPlugin.getDefault().getResourceBundle(); try { return (bundle != null) ? bundle.getString(key) : key; } catch (MissingResourceException e) { return key; } }
From source file:com.projity.strings.Messages.java
public static Properties getProperties(ResourceBundle bundle) { Properties properties = new Properties(); for (Enumeration keys = bundle.getKeys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); properties.put(key, bundle.getString(key)); }/* w w w .ja va2s .com*/ return properties; }
From source file:org.jbpcc.admin.jsf.JsfUtil.java
private static String getStringSafely(ResourceBundle bundle, String key, String defaultValue) { String resource = null;/*from www . j a v a 2s.c o m*/ try { resource = bundle.getString(key); if (resource == null) { if (defaultValue != null) { resource = defaultValue; } else { resource = NO_RESOURCE_FOUND + key; } } } catch (MissingResourceException me) { resource = "???<" + key + ">???"; } return resource; }
From source file:com.edgenius.core.util.WebUtil.java
/** * @param agent //from w ww. j a v a2s . c o m * @return */ public static boolean isPublicSearchEngineRobot(String agent) { if (!agentListInit) { agentListInit = true; try { ResourceBundle ua = ResourceBundle.getBundle(USER_AGENET_BROWSER); Enumeration<String> em = ua.getKeys(); while (em.hasMoreElements()) { String regex = ua.getString(em.nextElement()); try { userAgentPatternList.add(Pattern.compile(regex)); } catch (Exception e) { log.error("Unable compile user agent pattern: " + regex); } } } catch (Throwable e) { log.error("Unable load user agent properties, use default instead"); } } if (userAgentPatternList.size() > 0) { // use User-Agent to detect if current request is from browser, search engine robot, web crawler etc. for (Pattern pattern : userAgentPatternList) { //so far, browser is small amount than robot, so for performance reason, use browser agent list //See our issue http://bug.edgenius.com/issues/34 //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993 try { if (pattern.matcher(agent).matches()) return false; } catch (StackOverflowError e) { AuditLogger.error("StackOverflow Error in WebUtil.isPublicSearchEngineRobot. Input[" + agent + "] Pattern [" + pattern.pattern() + "]"); } catch (Throwable e) { AuditLogger.error("Unexpected error in WebUtil.isPublicSearchEngineRobot. Input[" + agent + "] Pattern [" + pattern.pattern() + "]", e); } } } else { //default very rough check String user = agent.toLowerCase(); if (user.indexOf("crawl") != -1 || user.indexOf("spider") != -1 || user.indexOf("check") != -1 || user.indexOf("bot") != -1) { return true; } else if (user.indexOf("mozilla") != -1 // ||user.indexOf("") != -1 || user.indexOf("opera") != -1) { return false; } } return true; }
From source file:com.norconex.commons.lang.time.DurationUtil.java
private static String getString(Locale locale, long unitValue, final String key, boolean islong) { String k = key;//from w w w. j a v a 2 s .c om if (islong && unitValue > 1) { k += "s"; } String pkg = ClassUtils.getPackageName(DurationUtil.class); ResourceBundle time; if (locale != null && Locale.FRENCH.getLanguage().equals(locale.getLanguage())) { time = ResourceBundle.getBundle(pkg + ".time", Locale.FRENCH); } else { time = ResourceBundle.getBundle(pkg + ".time"); } if (islong) { return " " + unitValue + " " + time.getString("timeunit.long." + k); } return unitValue + time.getString("timeunit.short." + k); }
From source file:com.krawler.esp.utils.PropsLoader.java
public static Properties loadProperties(String name, ClassLoader loader) { if (name == null) throw new IllegalArgumentException("null input: name"); if (name.startsWith("/")) name = name.substring(1);/*w w w . java 2 s . com*/ if (name.endsWith(SUFFIX)) name = name.substring(0, name.length() - SUFFIX.length()); Properties result = null; InputStream in = null; try { if (loader == null) loader = ClassLoader.getSystemClassLoader(); if (LOAD_AS_RESOURCE_BUNDLE) { name = name.replace('/', '.'); // Throws MissingResourceException on lookup failures: final ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault(), loader); result = new Properties(); for (Enumeration keys = rb.getKeys(); keys.hasMoreElements();) { final String key = (String) keys.nextElement(); final String value = rb.getString(key); result.put(key, value); } } else { name = name.replace('.', '/'); if (!name.endsWith(SUFFIX)) name = name.concat(SUFFIX); // Returns null on lookup failures: in = loader.getResourceAsStream(name); if (in != null) { result = new Properties(); result.load(in); // Can throw IOException } } } catch (Exception e) { logger.warn(e.getMessage(), e); result = null; } finally { if (in != null) try { in.close(); } catch (Throwable ignore) { logger.warn(ignore.getMessage(), ignore); } } if (THROW_ON_LOAD_FAILURE && (result == null)) { throw new IllegalArgumentException("could not load [" + name + "]" + " as " + (LOAD_AS_RESOURCE_BUNDLE ? "a resource bundle" : "a classloader resource")); } return result; }
From source file:com.vaadin.integration.maven.wscdn.CvalChecker.java
static String getErrorMessage(String key, Object... pars) { Locale loc = Locale.getDefault(); ResourceBundle res = ResourceBundle.getBundle(CvalChecker.class.getName(), loc); String msg = res.getString(key); return new MessageFormat(msg, loc).format(pars); }