private IndexMetadata() { try { props = ResourceUtil.getProperties(getClass()); } catch (IOException e) { log.error("Property file read error", e); } }
/** * Generic resource URL fetcher * * @param <T> the type of the resource * @param clazz the basis to search for the resource first. * @param search * The name of the resource (without a leading /) to find * @return The requested resource * @throws IOException * if there is a problem reading the file * @throws MissingResourceException * if the resource can not be found */ public static <T> InputStream getResourceAsStream(Class<T> clazz, String search) throws IOException, MissingResourceException { return ResourceUtil.getResource(clazz, search).openStream(); }
public LogConfig() throws SecurityException, IOException { LogManager.getLogManager().readConfiguration(ResourceUtil.getResourceAsStream("CWLogging.properties")); } }
/** * Generic resource URL fetcher. One way or the other we'll find it! Either * as a relative or an absolute reference. * * @param search * The name of the resource (without a leading /) to find * @return The requested resource * @throws MissingResourceException * if the resource can not be found */ public static URL getResource(String search) throws MissingResourceException { return getResource(CallContext.getCallingClass(), search); }
private void loadProperties() { try { myProperties = ResourceUtil.getProperties(getClass()); } catch (IOException e) { log.error("AnalyzerFactory property load from file failed", e); } }
/** * Generic resource URL fetcher * * @param search * The name of the resource (without a leading /) to find * @return The requested resource * @throws IOException * if there is a problem reading the file * @throws MissingResourceException * if the resource can not be found */ public static InputStream getResourceAsStream(String search) throws IOException, MissingResourceException { return getResourceAsStream(CallContext.getCallingClass(), search); }
/** * Get a list of the supported translations */ private void loadSupportedTranslations() { if (translations == null) { try { URL index = ResourceUtil.getResource(Translations.class, "translations.txt"); translations = NetUtil.listByIndexFile(NetUtil.toURI(index)); } catch (IOException ex) { translations = new String[0]; } } }
/** * This is a utility class, thus it's constructor is private. */ private WebWarning() { try { PropertyMap props = ResourceUtil.getProperties(getClass().getName()); shown = Boolean.valueOf(props.get(SHOWN_KEY, Boolean.valueOf(DEFAULT_SHOWN).toString())).booleanValue(); } catch (IOException e) { shown = DEFAULT_SHOWN; } }
/** * @param versification the name of the versification maps to the expected .properties file * @throws IOException error reading the mapping files * @throws ConfigException error parsing the contents of the file */ public FileVersificationMapping(Versification versification) throws IOException, ConfigException { //TODO(CJB): deal with Missing Resource Exceptions InputStream s = ResourceUtil.getResourceAsStream(getClass(), versification.getName() + ".properties"); BufferedReader lineReader = new BufferedReader(new InputStreamReader(s)); String line; while ((line = lineReader.readLine()) != null) { if (line.length() == 0 || line.charAt(0) == '#') { continue; } int firstEqual = line.indexOf('='); if (firstEqual == -1) { this.addProperty(line, null); } else { this.addProperty(line.substring(0, firstEqual), line.substring(firstEqual + 1)); } } }
/** * Get a list of the available readings sets * * @return all the installed reading sets */ public String[] getInstalledReadingsSets() { try { URL index = ResourceUtil.getResource(ReadingsBookDriver.class, "readings.txt"); return NetUtil.listByIndexFile(NetUtil.toURI(index), new ReadingsFilter()); } catch (IOException ex) { return new String[0]; } }
/** * Get and load a properties file from the writable area or if that fails * from the classpath (where a default ought to be stored) * * @param subject * The name of the desired resource (without any extension) * @return The found and loaded properties file * @throws IOException * if the resource can not be loaded */ public static PropertyMap getProperties(String subject) throws IOException { return getProperties(CallContext.getCallingClass(), subject); }
/** * Get and load an XML file from the classpath and a few other places into a * JDOM Document object. * * @param subject * The name of the desired resource (without any extension) * @return The requested resource * @throws IOException * if there is a problem reading the file * @throws JDOMException * If the resource is not valid XML */ public static Document getDocument(String subject) throws JDOMException, IOException { String resource = subject + FileUtil.EXTENSION_XML; InputStream in = ResourceUtil.getResourceAsStream(resource); log.debug("Loading {}.xml from classpath: [OK]", subject); // With JDom 1.x this passed true SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING); return builder.build(in); }
@Override public SAXEventProvider convert(SAXEventProvider xmlsep) throws TransformerException { try { URL xslurl = ResourceUtil.getResource(style); TransformingSAXEventProvider tsep = new TransformingSAXEventProvider(NetUtil.toURI(xslurl), xmlsep); // We used to do: // tsep.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); // however for various reasons, now we don't but nothing seems to be // broken ... return tsep; } catch (MissingResourceException ex) { throw new TransformerException(ex); } }
/** * Get and load a properties file from the writable area or if that fails * from the classpath (where a default ought to be stored) * * @param <T> the type of the resource * @param clazz * The name of the desired resource * @return The found and loaded properties file * @throws IOException * if the resource can not be loaded */ public static <T> PropertyMap getProperties(Class<T> clazz) throws IOException { return getProperties(clazz, ClassUtil.getShortClassName(clazz)); }
/** * Get and load a properties file from the writable area or if that fails * from the classpath (where a default ought to be stored) * * @param <T> the type of the resource * @param clazz * The name of the desired resource * @param subject * The name of the desired resource (without any extension) * @return The found and loaded properties file * @throws IOException * if the resource can not be loaded */ private static <T> PropertyMap getProperties(Class<T> clazz, String subject) throws IOException { try { String lookup = subject + FileUtil.EXTENSION_PROPERTIES; InputStream in = getResourceAsStream(clazz, lookup); PropertyMap prop = new PropertyMap(); prop.load(in); return prop; } catch (MissingResourceException e) { return new PropertyMap(); } } }
/** * Get an array of the available style names for a given subject. Different * subjects are available for different contexts. For example - for * insertion into a web page we might want to use a set that had complex * HTML, or IE/NS specific HTML, where as a JFC HTMLDocument needs simpler * HTML - and special tags like the starting <HTML> tags. * <p> * If the protocol of the URL of the current directory is not file then we * can't use File.list to get the contents of the directory. This will * happen if this is being run as an applet. When we start doing that then * we will need to think up something smarter here. Until then we just * return a zero length array. * * @return An array of available style names */ public String[] getStyles() { try { URL index = ResourceUtil.getResource(NetUtil.INDEX_FILE); return NetUtil.listByIndexFile(NetUtil.toURI(index), new XSLTFilter()); } catch (IOException ex) { return new String[0]; } }
try { loadSupportedTranslations(); PropertyMap props = ResourceUtil.getProperties(getClass()); translation = props.get(TRANSLATION_KEY); if (translation == null || translation.length() == 0) {
/** * Get and load a plugin file by looking it up as a resource. * * @param <T> the implementor's type * @param clazz * The name of the desired resource * @return The found and loaded plugin file * @throws IOException * if the resource can not be loaded * @throws MissingResourceException * if the resource can not be found */ public static <T> PropertyMap getPlugin(Class<T> clazz) throws IOException { String subject = ClassUtil.getShortClassName(clazz); try { String lookup = subject + PluginUtil.EXTENSION_PLUGIN; InputStream in = ResourceUtil.getResourceAsStream(clazz, lookup); PropertyMap prop = new PropertyMap(); prop.load(in); return prop; } catch (MissingResourceException e) { return new PropertyMap(); } }
/** * An example of how to do a search and then get text for each range of * verses. * * @throws BookException * @throws SAXException */ void searchAndShow() throws BookException, SAXException { Book bible = Books.installed().getBook(BIBLE_NAME); // Search for words like Melchezedik Key key = bible.find("melchesidec~"); // Here is an example of how to iterate over the ranges and get the text // for each. // The key's iterator would have iterated over verses. // The following shows how to use a stylesheet of your own choosing String path = "org/crosswire/jsword/xml/html5.xsl"; URL xslurl = ResourceUtil.getResource(path); // Make ranges break on chapter Iterator<VerseRange> rangeIter = ((Passage) key).rangeIterator(RestrictionType.CHAPTER); // boundaries. while (rangeIter.hasNext()) { Key range = rangeIter.next(); BookData data = new BookData(bible, range); SAXEventProvider osissep = data.getSAXEventProvider(); SAXEventProvider htmlsep = new TransformingSAXEventProvider(NetUtil.toURI(xslurl), osissep); String text = XMLUtil.writeToString(htmlsep); System.out.println("The html text of " + range.getName() + " is " + text); } }