List of usage examples for java.util MissingResourceException MissingResourceException
public MissingResourceException(String s, String className, String key)
From source file:org.apache.axis.i18n.ProjectResourceBundle.java
/** * Construct a new ProjectResourceBundle * /*from w w w . jav a2 s .c o m*/ * @param projectName The name of the project to which the class belongs. * It must be a proper prefix of the caller's package. * * @param caller The calling class. * This is used to get the package name to further construct * the basename as well as to get the proper ClassLoader. * * @param resourceName The name of the resource without the * ".properties" extension * * @param locale The locale * * @param extendsBundle If non-null, then this ExtendMessages will * default to extendsBundle. * * @throws MissingResourceException if projectName is not a prefix of * the caller's package name, or if the resource could not be * found/loaded. */ public static ProjectResourceBundle getBundle(String projectName, String packageName, String resourceName, Locale locale, ClassLoader loader, ResourceBundle extendsBundle) throws MissingResourceException { if (log.isDebugEnabled()) { log.debug("getBundle(" + projectName + "," + packageName + "," + resourceName + "," + String.valueOf(locale) + ",...)"); } Context context = new Context(); context.setLocale(locale); context.setLoader(loader); context.setProjectName(projectName); context.setResourceName(resourceName); context.setParentBundle(extendsBundle); packageName = context.validate(packageName); ProjectResourceBundle bundle = null; try { bundle = getBundle(context, packageName); } catch (RuntimeException e) { log.debug("Exception: ", e); throw e; } if (bundle == null) { throw new MissingResourceException("Cannot find resource '" + packageName + '.' + resourceName + "'", resourceName, ""); } return bundle; }
From source file:org.apache.openjpa.lib.conf.ProductDerivations.java
/** * Load the given given resource, or return false if it is not a resource * this provider understands. The given class loader may be null. * * @param anchor optional named anchor within a multiple-configuration * resource/*from ww w . ja v a 2 s . c o m*/ */ public static ConfigurationProvider load(String resource, String anchor, ClassLoader loader) { if (StringUtils.isEmpty(resource)) return null; if (loader == null) loader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()); ConfigurationProvider provider = null; StringBuilder errs = null; // most specific to least Throwable err = null; for (int i = _derivations.length - 1; i >= 0; i--) { try { provider = _derivations[i].load(resource, anchor, loader); if (provider != null) return provider; } catch (Throwable t) { err = t; errs = (errs == null) ? new StringBuilder() : errs.append("\n"); errs.append(_derivations[i].getClass().getName() + ":" + t); } } reportErrors(errs, resource, err); String rsrc = resource + "#" + anchor; MissingResourceException ex = new MissingResourceException(rsrc, ProductDerivations.class.getName(), rsrc); ex.initCause(err); throw ex; }
From source file:wicket.Localizer.java
/** * Get the localized string using all of the supplied parameters. This * method is left public to allow developers full control over string * resource loading. However, it is recommended that one of the other * convenience methods in the class are used as they handle all of the work * related to obtaining the current user locale and style information. * /*from ww w . ja v a2 s. c o m*/ * @param key * The key to obtain the resource for * @param component * The component to get the resource for (optional) * @param model * The model to use for substitutions in the strings (optional) * @param locale * The locale to get the resource for (optional) * @param style * The style to get the resource for (optional) (see * {@link wicket.Session}) * @param defaultValue * The default value (optional) * @return The string resource * @throws MissingResourceException * If resource not found and configuration dictates that * exception should be thrown */ public String getString(final String key, final Component component, final IModel model, final Locale locale, final String style, final String defaultValue) throws MissingResourceException { final List searchStack; final String path; if (component != null) { // The reason why need to create that stack is because we need to // walk it downwards starting with Page down to the Component searchStack = getComponentStack(component); path = Strings.replaceAll(component.getPageRelativePath(), ":", ".").toString(); } else { searchStack = null; path = null; } // Iterate over all registered string resource loaders until the // property has been found String string = visitResourceLoaders(key, path, searchStack, locale, style); // If a property value has been found, than replace the placeholder // and we are done if (string != null) { return substitutePropertyExpressions(component, string, model); } // Resource not found, so handle missing resources based on application // configuration final IResourceSettings resourceSettings = application.getResourceSettings(); if (resourceSettings.getUseDefaultOnMissingResource() && (defaultValue != null)) { return defaultValue; } if (resourceSettings.getThrowExceptionOnMissingResource()) { AppendingStringBuffer message = new AppendingStringBuffer("Unable to find resource: " + key); if (component != null) { message.append(" for component: "); message.append(component.getPageRelativePath()); message.append(" [class=").append(component.getClass().getName()).append("]"); } throw new MissingResourceException(message.toString(), (component != null ? component.getClass().getName() : ""), key); } else { return "[Warning: String resource for '" + key + "' not found]"; } }
From source file:com.flexive.faces.beans.MessageBean.java
/** * Returns the resource translation in the given locale. * * @param key resource key/*from w ww. j a v a 2s . com*/ * @param locale the requested locale * @return the resource translation * @since 3.2.0 */ public String getResource(String key, Locale locale) { if (!initialized) { initialize(); } final FxSharedUtils.MessageKey messageKey = new FxSharedUtils.MessageKey(locale, key); String cachedMessage = cachedMessages.get(messageKey); if (cachedMessage != null) { return cachedMessage; } for (FxSharedUtils.BundleReference bundleReference : resourceBundles) { try { final ResourceBundle bundle = getResources(bundleReference, locale); String message = bundle.getString(key); cachedMessage = cachedMessages.putIfAbsent(messageKey, message); return cachedMessage != null ? cachedMessage : message; } catch (MissingResourceException e) { // continue with next bundle } } if (!locale.equals(Locale.ENGLISH)) { //try to find the locale in english as last resort //this is a fix for using PropertyResourceBundles which can only handle one locale (have to use them thanks to JBoss 5...) for (FxSharedUtils.BundleReference bundleReference : resourceBundles) { try { final ResourceBundle bundle = getResources(bundleReference, Locale.ENGLISH); String message = bundle.getString(key); cachedMessage = cachedMessages.putIfAbsent(messageKey, message); return cachedMessage != null ? cachedMessage : message; } catch (MissingResourceException e) { // continue with next bundle } } } throw new MissingResourceException("Resource not found", "MessageBean", key); }
From source file:org.wso2.carbon.utils.i18n.ResourceBundle.java
protected void loadProperties(String basename, ClassLoader loader, Locale locale, Locale defaultLocale) { // Check the cache first String loaderName = ""; if (loader != null) { loaderName = ":" + loader.hashCode(); }//from ww w. j a v a 2 s .c o m String cacheKey = basename + ":" + locale + ":" + defaultLocale + loaderName; Properties p = (Properties) propertyCache.get(cacheKey); basePropertyFileName = basename + PROPERTY_EXT; if (p == null) { // The properties were not found in the cache. Search the given locale first p = new Properties(); if (locale != null) { p = loadProperties(basename, loader, locale, p); } // Search the default locale if (defaultLocale != null) { p = loadProperties(basename, loader, defaultLocale, p); } // Search for the basename p = merge(p, loadProperties(basePropertyFileName, loader)); if (p == null) { throw new MissingResourceException("Cannot find resource for base name " + basePropertyFileName, basePropertyFileName, ""); } // Cache the properties propertyCache.put(cacheKey, p); } resourceProperties = p; }
From source file:org.apache.openjpa.lib.conf.ProductDerivations.java
/** * Load given file, or return false if it is not a file this provider * understands./*from w ww. j a va 2s. co m*/ * * @param anchor optional named anchor within a multiple-configuration file */ public static ConfigurationProvider load(File file, String anchor, ClassLoader loader) { if (file == null) return null; if (loader == null) loader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()); ConfigurationProvider provider = null; StringBuilder errs = null; Throwable err = null; // most specific to least for (int i = _derivations.length - 1; i >= 0; i--) { try { provider = _derivations[i].load(file, anchor); if (provider != null) return provider; } catch (Throwable t) { err = t; errs = (errs == null) ? new StringBuilder() : errs.append("\n"); errs.append(_derivations[i].getClass().getName() + ":" + t); } } String aPath = AccessController.doPrivileged(J2DoPrivHelper.getAbsolutePathAction(file)); reportErrors(errs, aPath, err); String rsrc = aPath + "#" + anchor; MissingResourceException ex = new MissingResourceException(rsrc, ProductDerivations.class.getName(), rsrc); ex.initCause(err); throw ex; }
From source file:org.pentaho.di.i18n.GlobalMessageUtil.java
@VisibleForTesting static String calculateString(final String packageName, final Locale locale, final String key, final Object[] parameters, final Class<?> resourceClass, final String bundleName, final boolean fallbackOnRoot) throws MissingResourceException { try {/* w w w . j a v a 2 s . co m*/ ResourceBundle bundle = getBundle(locale, packageName + "." + bundleName, resourceClass, fallbackOnRoot); String unformattedString = bundle.getString(key); String string = MessageFormat.format(unformattedString, parameters); return string; } catch (IllegalArgumentException e) { final StringBuilder msg = new StringBuilder(); msg.append("Format problem with key=[").append(key).append("], locale=[").append(locale) .append("], package=").append(packageName).append(" : ").append(e.toString()); log.error(msg.toString()); log.error(Const.getStackTracker(e)); throw new MissingResourceException(msg.toString(), packageName, key); } }
From source file:org.pz.platypus.Platypus.java
/** * Load the default literals file, which is a property file. * * @param baseFilename base of the Literals filename. ".properties" extension will be appended * @throws MissingResourceException if an error occurs while file is read and loaded. *//* w ww . j a v a 2 s . c o m*/ static public void setupLiterals(final String baseFilename) throws MissingResourceException { try { lits = new Literals(baseFilename); } catch (MissingResourceException mre) { throw new MissingResourceException(null, null, null); } }
From source file:org.apache.openjpa.persistence.PersistenceProductDerivation.java
/** * Looks through the resources at <code>rsrc</code> for a configuration * file that matches <code>name</code> (or an unnamed one if * <code>name</code> is <code>null</code>), and loads the XML in the * resource into a new {@link PersistenceUnitInfo}. Then, applies the * overrides in <code>m</code>. * * @return {@link Boolean#TRUE} if the resource was loaded, null if it * does not exist, or {@link Boolean#FALSE} if it is not for OpenJPA *///from ww w . j a v a2 s .co m private Boolean load(ConfigurationProviderImpl cp, String rsrc, String name, Map m, ClassLoader loader, boolean explicit) throws IOException { if (loader == null) loader = (ClassLoader) AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction()); List<URL> urls = getResourceURLs(rsrc, loader); if (urls == null || urls.size() == 0) return null; ConfigurationParser parser = new ConfigurationParser(m); PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, loader); if (pinfo == null) { if (!explicit) return Boolean.FALSE; throw new MissingResourceException( _loc.get("missing-xml-config", rsrc, String.valueOf(name)).getMessage(), getClass().getName(), rsrc); } else if (!isOpenJPAPersistenceProvider(pinfo, loader)) { if (!explicit) { warnUnknownProvider(pinfo); return Boolean.FALSE; } throw new MissingResourceException( _loc.get("unknown-provider", rsrc, name, pinfo.getPersistenceProviderClassName()).getMessage(), getClass().getName(), rsrc); } cp.addProperties(pinfo.toOpenJPAProperties()); cp.setSource(pinfo.getPersistenceXmlFileUrl().toString()); return Boolean.TRUE; }
From source file:org.apache.openjpa.lib.conf.ProductDerivations.java
/** * Thrown proper exception for given errors. *///w w w. j ava 2 s .c o m private static void reportErrors(StringBuilder errs, String resource, Throwable nested) { if (errs == null) return; MissingResourceException ex = new MissingResourceException(errs.toString(), ProductDerivations.class.getName(), resource); ex.initCause(nested); throw ex; }