public IndexLanguageToLocaleMapperImpl() { // initialize the properties from file mappings = new Properties(); try { mappings.load(ClassLoaderUtils.getResourceAsStream("index-language-map.properties", IndexLanguageToLocaleMapperImpl.class)); } catch (IOException e) { log.warn("Unable to load the index-language-map.properties file"); } }
private void init(String propFileLocation) { // initialize the properties from file props = new Properties(); try { props.load(ClassLoaderUtils.getResourceAsStream(propFileLocation, ExternalLinkUtilImpl.class)); } catch (IOException e) { log.warn("Unable to load the " + propFileLocation + " file"); } } }
/** * Get the contents of a classpath resource as a String. Returns <tt>null</tt> if * the resource cannot be found or an error occurs reading the resource. */ public static String getResourceContent(String resource) { InputStream is = ClassLoaderUtils.getResourceAsStream(resource, FileUtils.class); if (is == null) return null; try { return IOUtils.toString(is); } catch (IOException e) { log.error("IOException reading stream: " + e, e); return null; } finally { IOUtils.closeQuietly(is); } }
@Override protected Properties create() throws Exception { Properties defaultProperties = new Properties(); final InputStream in = ClassLoaderUtils.getResourceAsStream(APP_PROPERTIES_DEFAULTS, this.getClass()); try { defaultProperties.load(in); in.close(); } catch (final IOException e) { log.error("Could not load default properties from '" + APP_PROPERTIES_DEFAULTS + "'. Not using default properties"); } return defaultProperties; } };
public static WorkflowDescriptor getJiraWorkflow(String filename) throws InvalidWorkflowDescriptorException, IOException, SAXException { InputStream isBrokenWorkflow = ClassLoaderUtils.getResourceAsStream(filename, WorkflowDescriptor.class); try { return WorkflowLoader.load(isBrokenWorkflow, true); } finally { IOUtils.closeQuietly(isBrokenWorkflow); } }
/** * Get the contents of a classpath resource as a String. Returns <tt>null</tt> if * the resource cannot be found or an error occurs reading the resource. */ public static String getResourceContent(String resource) { InputStream is = ClassLoaderUtils.getResourceAsStream(resource, FileUtils.class); if (is == null) return null; try { return IOUtils.toString(is); } catch (IOException e) { log.error("IOException reading stream: " + e, e); return null; } finally { IOUtils.closeQuietly(is); } }
private Properties getIconProperties() { if (iconProperties == null) { iconProperties = new Properties(); InputStream in = ClassLoaderUtils.getResourceAsStream(ICON_IMAGES_PROPERTIES, this.getClass()); try { iconProperties.load(in); in.close(); } catch (IOException e) { log.error("Unable to load icon properties from '" + ICON_IMAGES_PROPERTIES + "'."); return null; } } return iconProperties; }
public static Properties getProperties(String resource, Class callingClass) { return getPropertiesFromStream(ClassLoaderUtils.getResourceAsStream(resource, callingClass)); }
public XsltSearchRequestTransformer(String upgradeXslFilename) { InputStream xslStream = ClassLoaderUtils.getResourceAsStream(upgradeXslFilename, this.getClass()); // load the transformer TransformerFactory factory = TransformerFactory.newInstance(); try { transformer = factory.newTransformer(new StreamSource(xslStream)); } catch (TransformerConfigurationException e) { log.error(e.getMessage(), e); throw new IllegalArgumentException("Could not parse XSLT " + upgradeXslFilename + " used for upgrading search requests"); } }
private static Properties loadProperties(String propertiesFileLocation) { Properties properties = new Properties(); if (propertiesFileLocation != null) { InputStream is = ClassLoaderUtils.getResourceAsStream(propertiesFileLocation, HelpUtil.class); if (is != null) { try { properties.load(is); } catch (IOException e) { LOG.debug("Error loading helpfile " + propertiesFileLocation, e); } finally { IOUtils.closeQuietly(is); } } } return properties; }
private void loadBuildVersions() { final Properties props = new Properties(); final InputStream in = ClassLoaderUtils.getResourceAsStream(BUILD_VERSIONS_PROPERTIES, DefaultBuildVersionRegistry.class); try { props.load(in); in.close(); // cant rely on the ordering of the keys from the properties file - must sort them ourselves using TreeMap for (Object o : props.keySet()) { final String key = (String) o; buildVersionProperties.put(key, props.getProperty(key)); } } catch (IOException e) { log.error("Unable to load build versions properties from '" + BUILD_VERSIONS_PROPERTIES + "'."); } } }
private Properties loadProperties() { Properties properties = new Properties(); InputStream is = ClassLoaderUtils.getResourceAsStream(resourceName, getClass()); if (is != null) { try { properties.load(is); } catch (IOException e) { LOG.error("Error loading '" + resourceName + "'.", e); } finally { IOUtils.closeQuietly(is); } } else { LOG.error("Unable to find '{}' on the classpath.", resourceName); } return properties; } }
protected void initVe(VelocityEngine velocityEngine) { try { Properties props = new Properties(); try { props.load(ClassLoaderUtils.getResourceAsStream("velocity.properties", getClass())); } catch (Exception e) { //log.warn("Could not configure DefaultVelocityManager from velocity.properties, manually configuring."); props.put("resource.loader", "class"); props.put("class.resource.loader.description", "Velocity Classpath Resource Loader"); props.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); } velocityEngine.init(props); } catch (Exception e) { log.error("Exception initialising Velocity: " + e, e); } } }
/** * Get the contents of a resource as a list, one line representing one list item. * <p /> * Note: lines starting with # are deemed to be comments and not included. */ public static List readResourcesAsList(String resource) { List result = new ArrayList(); InputStream is = ClassLoaderUtils.getResourceAsStream(resource, FileUtils.class); try { result.addAll(IOUtils.readLines(is)); } catch (IOException e) { log.error("IOException reading stream: " + e, e); return result; } finally { IOUtils.closeQuietly(is); } for (Iterator iterator = result.iterator(); iterator.hasNext(); ) { String s = (String) iterator.next(); if (isBlank(s) || trimToEmpty(s).startsWith("#")) iterator.remove(); } return result; }
private void initialise(final VelocityEngine velocityEngine) { try { final Properties velocityPropertiesFile = new Properties(); try { velocityPropertiesFile.load(ClassLoaderUtils.getResourceAsStream("velocity.properties", getClass())); } catch (final Exception e) { log.warn("Could not configure the Velocity Engine from the velocity.properties, manually configuring."); velocityPropertiesFile.put("resource.loader", "class"); velocityPropertiesFile.put("class.resource.loader.description", "Velocity Classpath Resource Loader"); velocityPropertiesFile.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); } enableDevMode(velocityPropertiesFile); velocityEngine.init(velocityPropertiesFile); } catch (final Exception e) { log.error("Exception initialising Velocity: " + e, e); } }
props.load(ClassLoaderUtils.getResourceAsStream("velocity.properties", getClass()));
/** * Get the contents of a resource as a list, one line representing one list item. * <p /> * Note: lines starting with # are deemed to be comments and not included. */ public static List readResourcesAsList(String resource) { List result = new ArrayList(); InputStream is = ClassLoaderUtils.getResourceAsStream(resource, FileUtils.class); try { result.addAll(IOUtils.readLines(is)); } catch (IOException e) { log.error("IOException reading stream: " + e, e); return result; } finally { IOUtils.closeQuietly(is); } for (Iterator iterator = result.iterator(); iterator.hasNext();) { String s = (String) iterator.next(); if (org.apache.commons.lang.StringUtils.isBlank(s) || org.apache.commons.lang.StringUtils.trimToEmpty(s).startsWith("#")) iterator.remove(); } return result; }
static Map<String, String> load(final String name) { // initialize the properties from file final Properties mappings = new Properties(); InputStream is = null; try { is = ClassLoaderUtils.getResourceAsStream(name, CalendarLanguageUtilImpl.class); mappings.load(is); } catch (final IOException e) { log.warn("Unable to load the calendar-language-util.properties file"); } finally { closeQuietly(is); } final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); // Java6: // for (final String key : mappings.stringPropertyNames()) // Java5: for (final String key : CollectionUtil.transform(mappings.keySet(), Functions.<Object, String> downcast(String.class))) { builder.put(key, mappings.getProperty(key)); } return builder.build(); } }
public DefaultPreferences() { backingPS = PropertySetManager.getInstance("memory", null); InputStream defaults = ClassLoaderUtils.getResourceAsStream("preferences-default.xml", this.getClass()); try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
/** * Reads a downgrade XML file to get a list of all the downgrades specified in this file. */ public static Map<Integer, DowngradeTask> loadDowngradeTasks() throws DowngradeException { final InputStream is = ClassLoaderUtils.getResourceAsStream(DOWNGRADE_FILENAME, DowngradeUtil.class); try { final Collection<String> classNames = new DowngradeTaskFileParser().parse(is); final Map<Integer, DowngradeTask> downgradeTaskMap = new HashMap<Integer, DowngradeTask>(classNames.size()); for (String className : classNames) { DowngradeTask downgradeTask = constructNewInstance(className); downgradeTaskMap.put(downgradeTask.getBuildNumber(), downgradeTask); } return downgradeTaskMap; } catch (Exception ex) { // Multiple things can go wrong parsing the XML including Runtime exceptions like NPE // But only if the downgrades.xml is invalid. log.error("Unable to parse the Downgrade config file " + DOWNGRADE_FILENAME + ".", ex); throw new DowngradeException("An unexpected error occurred while parsing the Downgrade config file."); } }