List of usage examples for java.util MissingResourceException getMessage
public String getMessage()
From source file:pt.ist.bennu.core.util.BundleUtil.java
public static String getFormattedStringFromResourceBundle(final String bundle, Locale locale, final String key, String... args) {/* www .j ava2s. c om*/ try { String message = getStringFromResourceBundle(bundle, locale, key); for (int i = 0; i < args.length; i++) { message = message.replaceAll("\\{" + i + "\\}", args[i] == null ? "" : args[i]); } return message; } catch (MissingResourceException e) { LOGGER.warn(e.getMessage()); return '!' + key + '!'; } }
From source file:Main.java
static String localize(Locale locale, String baseName, String messageId, Object... parameters) { //Log.v(LOG_TAG, String.format("locale=%s, baseName=%s, messageId=%s, parameters=%s", locale, baseName, messageId, Arrays.asList(parameters))); if (locale == null) { locale = Locale.getDefault(); }/* w ww . j a v a 2 s . c o m*/ try { ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale); String source = bundle.getString(messageId); return MessageFormat.format(source, parameters); } catch (MissingResourceException e) { return "message '" + messageId + "' could not be localized (" + e.getMessage() + ")"; } }
From source file:org.nuxeo.ecm.platform.routing.core.impl.jsongraph.JsonGraphRoute.java
public static String getI18nLabel(String label, Locale locale) { if (label == null) { label = ""; }/*from ww w . jav a 2 s. c o m*/ try { return I18NUtils.getMessageString("messages", label, null, locale); } catch (MissingResourceException e) { log.warn(e.getMessage()); return label; } }
From source file:dk.statsbiblioteket.util.i18n.BundleCache.java
/** * Get a resource bundle with for a given name and locale. * If it is not found the default unlocalized bundle will * be tried. If this is not found either a MissingResourceException * will be thrown./*from w ww . j a va2s. c om*/ * * Both the locale specific and fallback bundles will be cached * * @param bundleName name of the bundle. * @param locale locale for the bundle. * @return a bundle ready for use. */ public static synchronized ResourceBundle getBundle(String bundleName, Locale locale) { BundleCache self = getInstance(); String localeBundleName = getLocaleBundleName(bundleName, locale); ResourceBundle bundle = self.cache.get(localeBundleName); if (bundle != null) { if (self.log.isTraceEnabled()) { self.log.trace("Found '" + localeBundleName + "' in cache"); } return bundle; } // We do not have the bundle cached. Create it and cache it try { return self.createBundle(localeBundleName); } catch (MissingResourceException e) { self.log.debug(e.getMessage() + ". Falling back to '" + bundleName + "'."); // stack trace left out on purpose bundle = self.cache.get(bundleName + ".properties"); if (bundle != null) { return bundle; } return self.createBundle(bundleName + ".properties"); } }
From source file:org.jahia.loganalyzer.common.ResourceUtils.java
public static String getBundleString(String baseName, String bundleKey, ClassLoader classLoader, Locale locale) {/*w ww . j a v a 2 s .c o m*/ if (bundleKey == null) { return null; } if (classLoader == null) { classLoader = Thread.currentThread().getContextClassLoader(); } if (locale == null) { locale = Locale.getDefault(); } try { ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName, locale, classLoader); return resourceBundle.getString(bundleKey); } catch (MissingResourceException mre) { System.err.println( "!!! Missing bundle resource key or bundle : " + bundleKey + "!!! (" + mre.getMessage() + ")"); return "[MISSING RESOURCE BUNDLE KEY OR BUNDLE:" + bundleKey + "] (" + mre.getMessage() + ")"; } }
From source file:org.openadaptor.legacy.convertor.dataobjects.LegacyUtils.java
/** * Assign attributes for the legacy convertor compenent. * Consult legacy openadaptor documentation for details on * possible attributes.//from w ww .j a v a2 s. c om * @param attributeMap */ public static void setAttributes(Object legacyOpenadaptorObject, Map attributeMap) { Method method = getMethod(legacyOpenadaptorObject.getClass(), LEGACY_SET_ATTRIBUTE_METHOD_NAME, LEGACY_SET_ATTRIBUTE_METHOD_ARGS); for (Iterator iter = attributeMap.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); try { method.invoke(legacyOpenadaptorObject, new Object[] { (String) entry.getKey(), (String) entry.getValue() }); } //ToDo: Revisit this. catch (MissingResourceException se) { //Ignore the stub warning, it would break springcheck ant task for now log.warn(se); if (!ignoreStubExceptions()) { throw new RuntimeException(se.getMessage(), se); } } catch (InvocationTargetException ite) { Throwable cause = ite.getCause(); log.debug("InvocationTargetException cause: " + cause); if (cause instanceof MissingResourceException) { if (ignoreStubExceptions()) { log.warn("Ignoring StubException generated on setAttributes"); } else { log.error("Stub code invoked - " + cause.getMessage()); throw (MissingResourceException) cause; } } else { String msg = "Failed to setAttributes - " + cause; throw new RuntimeException(msg, cause); } } catch (Exception e) { String msg = "Failed to setAttributes. Exception was: " + e; log.warn(msg); throw new RuntimeException(msg, e); } } }
From source file:CachedConnectionServlet.java
public static final Connection getConnection(String baseName) { Connection conn = null;/* ww w .j a va2 s .co m*/ String driver = null; String url = null; String username = null; String password = null; try { ResourceBundle resb = ResourceBundle.getBundle(baseName); driver = resb.getString("database.driver"); url = resb.getString("database.url"); username = resb.getString("database.username"); password = resb.getString("database.password"); Class.forName(driver); } catch (MissingResourceException e) { System.err.println("Missing Resource: " + e.getMessage()); return conn; } catch (ClassNotFoundException e) { System.err.println("Class not found: " + e.getMessage()); return conn; } try { if (verbose) { System.out.println("baseName=" + baseName); System.out.println("driver=" + driver); System.out.println("url=" + url); System.out.println("username=" + username); System.out.println("password=" + password); } conn = DriverManager.getConnection(url, username, password); } catch (SQLException e) { System.err.println(e.getMessage()); System.err.println("in Database.getConnection"); System.err.println("on getConnection"); conn = null; } finally { return conn; } }
From source file:org.apache.manifoldcf.core.i18n.Messages.java
/** Obtain a resource bundle given a class, bundle name, and locale. *@return null if the resource bundle could not be found. *//*from w ww. ja v a 2 s . co m*/ public static ResourceBundle getResourceBundle(Class clazz, String bundleName, Locale locale) { ResourceBundle resources; ClassLoader classLoader = clazz.getClassLoader(); try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e) { complainMissingBundle("Missing resource bundle '" + bundleName + "' for locale '" + locale.toString() + "': " + e.getMessage() + "; trying " + locale.getLanguage(), e, bundleName, locale); // Try plain language next locale = new Locale(locale.getLanguage()); try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e2) { // Use English if we don't have a bundle for the current locale complainMissingBundle("Missing resource bundle '" + bundleName + "' for locale '" + locale.toString() + "': " + e2.getMessage() + "; trying en_US", e2, bundleName, locale); locale = Locale.US; try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e3) { complainMissingBundle("No backup en_US bundle found! " + e3.getMessage(), e3, bundleName, locale); locale = new Locale(locale.getLanguage()); try { resources = ResourceBundle.getBundle(bundleName, locale, classLoader); } catch (MissingResourceException e4) { complainMissingBundle("No backup en bundle found! " + e4.getMessage(), e4, bundleName, locale); return null; } } } } return resources; }
From source file:org.silverpeas.core.util.file.FileUtil.java
/** * Detects the mime-type of the specified file. * * The mime-type is first extracted from its content. If the detection fails or if the file cannot * be located by its specified name, then the mime-type is detected from the file extension. * * @param fileName the name of the file with its path. * @return the mime-type of the specified file. *//*from w w w . j ava2 s. c om*/ public static String getMimeType(final String fileName) { // Request caching in order to increase significantly the performance about file parsing String cacheKey = MIME_TYPE_CACHE_KEY_PREFIX + fileName; String cachedMimeType = getRequestCacheService().getCache().get(cacheKey, String.class); if (StringUtil.isDefined(cachedMimeType)) { return cachedMimeType; } String mimeType = null; final String fileExtension = FileRepositoryManager.getFileExtension(fileName).toLowerCase(); File file = new File(fileName); if (file.exists()) { try { mimeType = MetadataExtractor.get().detectMimeType(file); } catch (Exception ex) { SilverLogger.getLogger(FileUtil.class).warn( "File exists ({0}), but mime-type has been detected: {1}", file.getName(), ex.getMessage(), ex); } } if (!StringUtil.isDefined(mimeType) && MIME_TYPES_EXTENSIONS != null && !fileExtension.isEmpty()) { try { mimeType = MIME_TYPES_EXTENSIONS.getString(fileExtension); } catch (final MissingResourceException e) { SilverLogger.getLogger(FileUtil.class).warn("Unknown mime-type: {0}", e.getMessage(), e); } } if (!StringUtil.isDefined(mimeType)) { mimeType = MIME_TYPES.getContentType(fileName); } // if the mime type is application/xhml+xml or text/html whereas the file is a JSP or PHP script if (XHTML_MIME_TYPE.equalsIgnoreCase(mimeType) || HTML_MIME_TYPE.equalsIgnoreCase(mimeType)) { if (fileExtension.contains(JSP_EXTENSION)) { mimeType = JSP_MIME_TYPE; } else if (fileExtension.contains(PHP_EXTENSION)) { mimeType = PHP_MIME_TYPE; } // if the mime type refers a ZIP archive, checks if it is an archive of the java platform } else if (ARCHIVE_MIME_TYPE.equalsIgnoreCase(mimeType) || SHORT_ARCHIVE_MIME_TYPE.equalsIgnoreCase(mimeType)) { if (JAR_EXTENSION.equalsIgnoreCase(fileExtension) || WAR_EXTENSION.equalsIgnoreCase(fileExtension) || EAR_EXTENSION.equalsIgnoreCase(fileExtension)) { mimeType = JAVA_ARCHIVE_MIME_TYPE; } else if ("3D".equalsIgnoreCase(fileExtension)) { mimeType = SPINFIRE_MIME_TYPE; } } if (mimeType == null) { mimeType = DEFAULT_MIME_TYPE; } // The computed mime type is put into the request cache (performance) getRequestCacheService().getCache().put(cacheKey, mimeType); return mimeType; }
From source file:ar.com.fdvs.dj.core.DynamicJasperHelper.java
private final static void registerEntities(DynamicJasperDesign jd, DynamicReport dr, LayoutManager layoutManager) { ColumnRegistrationManager columnRegistrationManager = new ColumnRegistrationManager(jd, dr, layoutManager); columnRegistrationManager.registerEntities(dr.getColumns()); DJGroupRegistrationManager djGroupRegistrationManager = new DJGroupRegistrationManager(jd, dr, layoutManager);//from ww w .j ava2s .com djGroupRegistrationManager.registerEntities(dr.getColumnsGroups()); registerPercentageColumnsVariables(jd, dr, layoutManager); registerOtherFields(jd, dr.getFields()); Locale locale = dr.getReportLocale() == null ? Locale.getDefault() : dr.getReportLocale(); if (log.isDebugEnabled()) { log.debug("Requested Locale = " + dr.getReportLocale() + ", Locale to use: " + locale); } ResourceBundle messages = null; if (dr.getResourceBundle() != null) { try { messages = ResourceBundle.getBundle(dr.getResourceBundle(), locale); } catch (MissingResourceException e) { log.warn(e.getMessage() + ", usign default (dj-messages)"); } } if (messages == null) { try { messages = ResourceBundle.getBundle(DJ_RESOURCE_BUNDLE, locale); } catch (MissingResourceException e) { log.warn(e.getMessage() + ", usign default (dj-messages)"); try { messages = ResourceBundle.getBundle(DJ_RESOURCE_BUNDLE, Locale.ENGLISH); //this cannot fail because is included in the DJ jar } catch (MissingResourceException e2) { log.error("Default messajes not found: " + DJ_RESOURCE_BUNDLE + ", " + e2.getMessage(), e2); throw new DJException( "Default messajes file not found: " + DJ_RESOURCE_BUNDLE + "en.properties", e2); } } } jd.getParametersWithValues().put(JRDesignParameter.REPORT_RESOURCE_BUNDLE, messages); jd.getParametersWithValues().put(JRDesignParameter.REPORT_LOCALE, locale); // JRDesignParameter.REPORT_RESOURCE_BUNDLE // report. }