List of usage examples for java.util MissingResourceException MissingResourceException
public MissingResourceException(String s, String className, String key)
From source file:org.apache.fop.render.ps.AbstractPostScriptTestCase.java
/** * Renders a test file./*from www . java2s . c o m*/ * @param ua the user agent (with override set!) * @param resourceName the resource name for the FO file * @param suffix a suffix for the output filename * @return the output file * @throws Exception if an error occurs */ protected File renderFile(FOUserAgent ua, String resourceName, String suffix) throws Exception { File outputFile = new File("build/test-results/" + resourceName + suffix + ".ps"); File outputDir = outputFile.getParentFile(); FileUtils.forceMkdir(outputDir); // Prepare input file InputStream in = getClass().getResourceAsStream(resourceName); if (in == null) { throw new MissingResourceException(resourceName + " not found in resources", getClass().getName(), null); } try { Source src = new StreamSource(in); // Create PostScript OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, ua, out); SAXResult res = new SAXResult(fop.getDefaultHandler()); Transformer transformer = tFactory.newTransformer(); transformer.transform(src, res); } finally { IOUtils.closeQuietly(out); } } finally { IOUtils.closeQuietly(in); } return outputFile; }
From source file:org.apache.fop.render.AbstractRenderingTest.java
/** * Renders a test file./*from w ww . ja va2s . c o m*/ * @param ua the user agent (with override set!) * @param resourceName the resource name for the FO file * @param suffix a suffix for the output filename * @param outputFormat MIME type of the requested output format * @return the output file * @throws Exception if an error occurs */ protected File renderFile(FOUserAgent ua, String resourceName, String suffix, String outputFormat) throws Exception { String extension = MIME_MAP.get(outputFormat); assert extension != null; File outputFile = new File("build/test-results/" + resourceName + suffix + extension); File outputDir = outputFile.getParentFile(); FileUtils.forceMkdir(outputDir); // Prepare input file InputStream in = getClass().getResourceAsStream(resourceName); if (in == null) { throw new MissingResourceException(resourceName + " not found in resources", getClass().getName(), null); } try { Source src = new StreamSource(in); // Create output file OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { Fop fop = fopFactory.newFop(outputFormat, ua, out); SAXResult res = new SAXResult(fop.getDefaultHandler()); Transformer transformer = tFactory.newTransformer(); transformer.transform(src, res); } finally { IOUtils.closeQuietly(out); } } finally { IOUtils.closeQuietly(in); } return outputFile; }
From source file:org.pz.platypus.Platypus.java
/** * Get the actual name of the plugin, based on its lookup value in config file. * * Check whether the plug-in is in the default PLATYPUS_HOME\plugins directory. * if not, check whether the configuration file gives the plug-ins location. * * @param pluginJarLookupName name of the plugin file (a JAR file) in the PLATYPUS_HOME\plugins * @param gdd the GDD/*from w ww.ja v a 2 s. co m*/ * @return the jar file name */ private static String findPluginJar(final String pluginJarLookupName, final GDD gdd) { if (!new File(pluginJarLookupName).exists()) { String searchName = "pi.out." + gdd.getOutputPluginPrefix() + ".location"; String pluginJar = gdd.getConfigFile().lookup(searchName); if (pluginJar == null || !new File(pluginJar).exists()) { gdd.logSevere(lits.getLit("ERROR.INVALID_PLUGIN_URL") + ": " + searchName); throw new MissingResourceException(null, null, null); } return (pluginJar); } else { return (pluginJarLookupName); } }
From source file:dk.statsbiblioteket.util.i18n.BundleCache.java
/** * Create a bundle from the resource specified by {@code localeBundleName} * and cache it. Return a reference to the newly created bundle. * * @param localeBundleName the full resource name as returned by * {@link #getLocaleBundleName} * @return the newly created and cached bundle *///from www.ja v a2 s . com private ResourceBundle createBundle(String localeBundleName) { if (log.isDebugEnabled()) { log.debug("Loading '" + localeBundleName + "'"); } InputStream resourceStream = ClassLoader.getSystemResourceAsStream(localeBundleName); if (resourceStream == null) { throw new MissingResourceException("No such resource '" + localeBundleName + "'", localeBundleName, ""); } try { // The Java 1.6 way is much nicer: //ResourceBundle bundle = //new PropertyResourceBundle(new InputStreamReader(resourceStream)); ResourceBundle bundle = new PropertyResourceBundle(new EscapeUTF8Stream(resourceStream)); cache.put(localeBundleName, bundle); return bundle; } catch (IOException e) { throw new MissingResourceException("Error reading resource '" + localeBundleName + "'", localeBundleName, ""); } }
From source file:org.jkcsoft.java.systems.components.AppConfigHelper.java
public String getConfigProperty(String propKeySlashes, String defValue) throws Exception { if (Strings.isEmpty(propKeySlashes)) throw new Exception("Null or empty key argument"); // trim forward and leading '/' String propKey = propKeySlashes; if (propKey.charAt(0) == '/') propKey = propKey.substring(1);/* w w w . ja v a2 s . c o m*/ if (propKey.charAt(propKey.length() - 1) == '/') propKey = propKey.substring(0, propKey.length() - 2); propKey = propKey.replace('/', '.'); String retVal = defValue; try { if (bundle != null) { retVal = bundle.getString(propKey); if (retVal == null || Strings.isEmpty(retVal)) { throw new MissingResourceException("", "", propKey); } log.info("Found property ==> " + propKey + "=" + retVal); } } catch (MissingResourceException e) { if (defValue == null) { log.error("Initialization property not found for key '" + propKey + "' with no default value", e); throw e; } } if (retVal == null) { if (defValue != null) { retVal = defValue; log.info("Initialization property not found '" + propKey + "'; using default '" + defValue + "'"); } else { throw new Exception( "Initialization property not found for key '" + propKey + "' with no default value"); } } return retVal; }
From source file:org.eclipse.jubula.tools.internal.i18n.CompSystemI18n.java
/** * Searches for the value of the given key in all bundles.<br> * throws MissingResourceException if the key was not found. * @param key the key/* w w w . j av a 2 s . c o m*/ * @return the value for the given key */ private static String getStringInternal(String key) { if (key == null) { return StringUtils.EMPTY; } String value = I18N_MAP.get(key); if (value != null) { return value; } Iterator<ResourceBundle> bundleIter = PLUGIN_BUNDLES.iterator(); while (bundleIter.hasNext()) { ResourceBundle bundle = bundleIter.next(); try { value = bundle.getString(key); I18N_MAP.put(key, value); return value; } catch (MissingResourceException ex) { // ok here, we search in multiple bundles } } I18N_MAP.put(key, key); throw new MissingResourceException("No entry found for key: " + key, //$NON-NLS-1$ CompSystemI18n.class.getName(), key); }
From source file:Main.java
public static String getResourceUrlString(String resourceFileName, Class runningClass) { URL url = runningClass.getClassLoader().getResource(resourceFileName); if (url == null) throw new MissingResourceException("Resource not found: " + resourceFileName, runningClass.getName(), resourceFileName);/*ww w.j ava 2 s .com*/ return url.toExternalForm(); }
From source file:org.eclipse.jubula.tools.i18n.CompSystemI18n.java
/** * Searches for the value of the given key in all bundles.<br> * throws MissingResourceException if the key was not found. * @param key the key// w ww . ja v a 2 s . c o m * @return the value for the given key */ private static String getStringInternal(String key) { if (key == null) { return StringUtils.EMPTY; } String value = (String) I18N_MAP.get(key); if (value != null) { return value; } Iterator bundleIter = PLUGIN_BUNDLES.iterator(); while (bundleIter.hasNext()) { ResourceBundle bundle = (ResourceBundle) bundleIter.next(); try { value = bundle.getString(key); I18N_MAP.put(key, value); return value; } catch (MissingResourceException ex) { // ok here, we search in multiple bundles } } I18N_MAP.put(key, key); throw new MissingResourceException("No entry found for key: " + key, //$NON-NLS-1$ CompSystemI18n.class.getName(), key); }
From source file:Main.java
/** * Get an URL to a schema file. This implementation finds the schema file using the ClassLoader * that loaded the argument class./* www . j ava 2s . c o m*/ * * @param resourceFileName * @param runningClass * @return */ public static String getResourceUrlString(String resourceFileName, Class<?> runningClass) { String rtn = null; URL url = runningClass.getClassLoader().getResource(resourceFileName); if (url == null) throw new MissingResourceException("Resource not found: " + resourceFileName, runningClass.getName(), resourceFileName); rtn = url.toString(); return rtn; }
From source file:org.omegat.gui.scripting.ScriptItem.java
public ResourceBundle getResourceBundle() { if (m_res != null) { return m_res; }/*from ww w . ja va 2 s.co m*/ // Create empty resource for confirmation return new ResourceBundle() { final String MISSING_BUNDLE_MESSAGE = "ResourceBundle (.properties file for localization) is missing."; @Override protected Object handleGetObject(String key) { throw new MissingResourceException(MISSING_BUNDLE_MESSAGE, null, key); } @Override public Enumeration<String> getKeys() { throw new MissingResourceException(MISSING_BUNDLE_MESSAGE, null, null); } }; }