List of usage examples for java.util MissingResourceException MissingResourceException
public MissingResourceException(String s, String className, String key)
From source file:com.autentia.common.util.FileSystemUtils.java
/** * Devuelve un <tt>InputStream</tt> apuntando al <tt>resource</tt> que se ha localizado en el CLASSPATH. * <p>/*from w w w .j ava 2 s.c o m*/ * Primero se busca en el CLASSPATH asociado al Thread, luego en el ClassLoader, y por ltimo en el ClassLoader de * esta clase. * * @param resource recurso que se quiere localizar en el CLASSPATH. * @return un <tt>InputStream</tt> apuntando al <tt>resource</tt> que se ha localizado en el CLASSPATH. * <tt>null</tt> si no se ha encontrado. */ public static String searchInClasspath(String resource) { URL url = Thread.currentThread().getContextClassLoader().getResource(resource); if (url == null) { url = ClassLoader.getSystemResource(resource); if (url == null) { url = FileSystemUtils.class.getClassLoader().getResource(resource); if (url == null) { throw new MissingResourceException("Cannot find resource '" + resource + "' in none classpath", FileSystemUtils.class.getName(), resource); } } } return url.getPath(); }
From source file:architecture.common.util.L10NUtils.java
/** * key ? ? ?? ?? ?? Localizer ? .//from www.j a va 2 s .c o m * * @param key * @param locale * @param classloader * @return * @throws MissingResourceException */ public static Localizer getLocalizer(String key, Locale locale, ClassLoader classloader) throws MissingResourceException { Locale localeToUse = locale; String keyToUse = key; ClassLoader cl = classloader; if (keyToUse == null) throw new NullPointerException("No key name provided"); if (localeToUse == null) localeToUse = Locale.getDefault(); if (cl != null) { Localizer localizer = L10NUtils.SINGLETON.getLocalizerBundle(key, locale, cl); if (localizer != null) return localizer; } cl = L10NUtils.class.getClassLoader(); if (cl == null) cl = ClassLoader.getSystemClassLoader(); if (cl == null) { if (log.isDebugEnabled()) log.debug("no system classs loader"); cl = Thread.currentThread().getContextClassLoader(); if (cl == null) { if (log.isDebugEnabled()) log.debug("no context class loader"); } else if (log.isDebugEnabled()) log.debug("Using context class loader"); } Localizer localizer = L10NUtils.SINGLETON.getLocalizerBundle(key, locale, cl); if (localizer == null) { ClassLoader clToUse = Thread.currentThread().getContextClassLoader(); localizer = L10NUtils.SINGLETON.getLocalizerBundle(key, locale, clToUse); if (localizer == null) throw new MissingResourceException((new StringBuilder()).append("Can't locate bundle for class '") .append(key).append("'").toString(), key, ""); } return localizer; }
From source file:gov.va.vinci.leo.descriptors.LeoRemoteAEDescriptor.java
/** * Set the name of this remote service, return a reference to the delegate type object in each implementation. * * @param name String name of the remote service * @return reference to the delegate type whose name is set *///from w ww . ja va 2s. c om @Override public LeoRemoteAEDescriptor setName(String name) { if (mRemoteDescriptor == null) { throw new MissingResourceException("Error, cannot set name: Missing Remote Descriptor", CustomResourceSpecifier.class.getCanonicalName(), "mRemoteDescriptor"); } if (StringUtils.isBlank(name)) { throw new IllegalArgumentException("Name to set cannot be blank!"); } name = name + "2112" + LeoUtils.getUUID(); if (this.name == null) { this.addParameterSetting("componentName", name); } else { this.name.setName(name); } return this; }
From source file:org.mili.core.resource.ResourceUtilImpl.java
@Override public String getString(Locale locale, String baseName, String key) { Validate.notNull(locale, "locale cannot be null!"); Validate.notEmpty(baseName, "basename cannot be empty!"); Validate.notEmpty(key, "key cannot be empty!"); Map<String, String> bundle = getBundle(locale, baseName, key); try {//from w w w.j ava 2 s .com String res = bundle.get(key); if (res == null) { throw new MissingResourceException("missing resource!", null, key); } return res; } catch (MissingResourceException e) { setUpMissingResourceHandler(locale, baseName, key); if (Boolean.getBoolean(PROP_LOGMISSINGRESOURCE)) { MissingResourceLogger.INSTANCE.log(locale, key); } if (Boolean.getBoolean(PROP_THROWEXCEPTIONONMISSINGRESOURCE)) { throw new MissingResourceException( "Missing resource for locale ! " + getInfo(locale, baseName, key), e.getClassName(), key); } else { if (Boolean.getBoolean(PROP_LOGMISSINGRESOURCEASWARNING)) { log.warn("Missing resource for locale! ", getInfo(locale, baseName, key)); } return createMissingResource(key); } } }
From source file:org.pentaho.reporting.libraries.base.util.ResourceBundleSupport.java
/** * Performs the lookup for the given key. If the key points to a link the link is resolved and that key is looked up * instead.//from w w w . ja v a 2 s . co m * * @param key the key for the string * @return the string for the given key */ protected String internalGetString(final String key) { if (key == null) { throw new NullPointerException(); } if (this.lookupPath.contains(key)) { throw new MissingResourceException("InfiniteLoop in resource lookup", getResourceBase(), this.lookupPath.toString()); } final String fromResBundle = this.resources.getString(key); if (fromResBundle.length() > 0 && fromResBundle.charAt(0) == '@') { if (fromResBundle.length() > 1 && fromResBundle.charAt(1) == '@') { // global forward ... final int idx = fromResBundle.indexOf('@', 2); if (idx == -1) { throw new MissingResourceException("Invalid format for global lookup key.", getResourceBase(), key); } try { final ResourceBundle res = ResourceBundle.getBundle(fromResBundle.substring(2, idx), locale, sourceClassLoader); return res.getString(fromResBundle.substring(idx + 1)); } catch (Exception e) { logger.error("Error during global lookup", e); throw new MissingResourceException("Error during global lookup", getResourceBase(), key); } } else { // local forward ... final String newKey = fromResBundle.substring(1); this.lookupPath.add(key); final String retval = internalGetString(newKey); this.cache.put(key, retval); return retval; } } else { this.cache.put(key, fromResBundle); return fromResBundle; } }
From source file:ResourceBundleSupport.java
/** * Performs the lookup for the given key. If the key points to a link the * link is resolved and that key is looked up instead. * * @param key the key for the string// w ww. j ava 2 s . c o m * @return the string for the given key */ protected String internalGetString(final String key) { if (this.lookupPath.contains(key)) { throw new MissingResourceException("InfiniteLoop in resource lookup", getResourceBase(), this.lookupPath.toString()); } final String fromResBundle = this.resources.getString(key); if (fromResBundle.startsWith("@@")) { // global forward ... final int idx = fromResBundle.indexOf('@', 2); if (idx == -1) { throw new MissingResourceException("Invalid format for global lookup key.", getResourceBase(), key); } try { final ResourceBundle res = ResourceBundleWrapper.getBundle(fromResBundle.substring(2, idx)); return res.getString(fromResBundle.substring(idx + 1)); } catch (Exception e) { System.out.println("Error during global lookup:" + e); throw new MissingResourceException("Error during global lookup", getResourceBase(), key); } } else if (fromResBundle.startsWith("@")) { // local forward ... final String newKey = fromResBundle.substring(1); this.lookupPath.add(key); final String retval = internalGetString(newKey); this.cache.put(key, retval); return retval; } else { this.cache.put(key, fromResBundle); return fromResBundle; } }
From source file:org.pz.platypus.Platypus.java
/** * Finds the config file, reads it in, and places an instance of it in GDD. * If the file can't be found, this method throws MissingResourceException, * which is caught in the main line. At that point, Platypus is shut down * (the error message having already been written to stderr). * * @param Clargs the command line args/*from w w w. j a v a2s . com*/ * @param Gdd the GDD * @throws MissingResourceException in the event the config file cannot be loaded */ static public void processConfigFile(CommandLineArgs Clargs, final GDD Gdd) throws MissingResourceException { final String filename = getConfigFilename(Clargs, Gdd); final PropertyFile configFile = new PropertyFile(filename, Gdd); if (configFile.load() != Status.OK) { //curr: throw unchecked exception at point of error, don't propagate upwards. Catch() already in main(). throw new MissingResourceException(null, null, null); //curr: make it a specialized unchecked exception. i.e., ConfigFileLoadException... } Gdd.setConfigFile(configFile); }
From source file:org.libreplan.business.common.LibrePlanClassValidator.java
private ResourceBundle getDefaultResourceBundle() { ResourceBundle rb;// w w w. ja v a 2s .com try { //use context class loader as a first citizen ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); if (contextClassLoader == null) { throw new MissingResourceException("No context classloader", null, VALIDATOR_MESSAGE); } rb = ResourceBundle.getBundle(VALIDATOR_MESSAGE, Locale.getDefault(), contextClassLoader); } catch (MissingResourceException e) { log.trace("ResourceBundle " + VALIDATOR_MESSAGE + " not found in thread context classloader"); //then use the Validator Framework classloader try { rb = ResourceBundle.getBundle(VALIDATOR_MESSAGE, Locale.getDefault(), this.getClass().getClassLoader()); } catch (MissingResourceException ee) { log.debug("ResourceBundle ValidatorMessages not found in Validator classloader. Delegate to " + DEFAULT_VALIDATOR_MESSAGE); //the user did not override the default ValidatorMessages rb = null; } } isUserProvidedResourceBundle = true; return rb; }
From source file:org.wso2.carbon.utils.i18n.ProjectResourceBundle.java
/** * Construct a new ProjectResourceBundle * * @param projectName The name of the project to which the class belongs. * It must be a proper prefix of the caller's package. * @param packageName The package name to further construct * the basename.// w ww . j av a 2 s.c o m * @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) { 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.wso2.carbon.utils.i18n.ResourceBundle.java
/** * <p>Gets a string message from the resource bundle for the given key. The * message may contain variables that will be substituted with the given * arguments. Variables have the format:</p> * <dir>//from w w w . j a v a2s . com * This message has two variables: {0} and {1} * </dir> * * @param key The resource key * @param array An array of objects to place in corresponding variables * @return The message */ public String getString(String key, Object[] array) { String msg = null; if (resourceProperties != null) { msg = resourceProperties.getProperty(key); } if (msg == null) { throw new MissingResourceException( "Cannot find resource key \"" + key + "\" in base name " + basePropertyFileName, basePropertyFileName, key); } msg = MessageFormat.format(msg, array); return msg; }