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 String getTemplatePath(final String template) { final boolean renderAsHtml = (ClassLoaderUtils.getResource(EMAIL_TEMPLATES + "html/" + template, this.getClass()) != null); final String prefix = (renderAsHtml) ? "html/" : "text/"; return EMAIL_TEMPLATES + prefix + template; }
public <T> Class<T> loadClass(final String className) throws ClassNotFoundException { //noinspection unchecked return ClassLoaderUtils.loadClass(className, getClass()); } }
installedLocales = new ArrayList<Locale>(); URL url = null; final Enumeration localeDescriptors = ClassLoaderUtils.getResources(LANGUAGE_DESCRIPTOR_FILENAME, this.getClass()); while (localeDescriptors.hasMoreElements()) { try {
/** * Prints the classloader hierarchy from a given classloader - useful for debugging. */ public static void printClassLoader(ClassLoader cl) { System.out.println("ClassLoaderUtils.printClassLoader(cl = " + cl + ")"); if (cl != null) { printClassLoader(cl.getParent()); } } }
final Enumeration localeDescriptors = ClassLoaderUtils.getResources(LANGUAGE_DESCRIPTOR_FILENAME, this.getClass()); while (localeDescriptors.hasMoreElements())
/** * Prints the current classloader hierarchy - useful for debugging. */ public static void printClassLoader() { System.out.println("ClassLoaderUtils.printClassLoader"); printClassLoader(Thread.currentThread().getContextClassLoader()); }
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"); } } }
/** * Load a class with a given name. * <p> * It will try to load the class in the following order: * <ul> * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * <li>Using the basic {@link Class#forName(java.lang.String) } * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()} * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() } * </ul> * * @param className The name of the class to load * @param callingClass The Class object of the calling object * @throws ClassNotFoundException If the class cannot be found anywhere. */ public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException { return loadClass(className, callingClass.getClassLoader()); }
/** * This is a convenience method to load a resource as a stream. * <p> * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return url != null ? url.openStream() : null; } catch (IOException e) { return null; } } }
/** * 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); } }
/** * Load a class with a given name. * <p> * It will try to load the class in the following order: * <ul> * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * <li>Using the basic {@link Class#forName(java.lang.String) } * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()} * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() } * </ul> * * @param className The name of the class to load * @param callingClass The Class object of the calling object * @throws ClassNotFoundException If the class cannot be found anywhere. */ public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException { return loadClass(className, callingClass.getClassLoader()); }
public static File getTestResource(String path) throws URISyntaxException { return new File(ClassLoaderUtils.getResource(path, TestUtils.class).toURI()); } }
@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 Object instantiateClass(String name, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class clazz = ClassLoaderUtils.loadClass(name, ClassHelper.class); return instantiateClass(clazz, constructorArgs); } }
public String getEntityEngineXmlPath() { try { return ClassLoaderUtils.getResource(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, getClass()).toExternalForm(); } catch (final Exception e) { log.error("Could not load " + EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME + " path " + e.getMessage(), e); return "Could not load " + EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME + " path. Exception " + e.getMessage(); } }
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); } }
public static Object instantiateClass(String name, Object[] constructorArgs) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { Class clazz = ClassLoaderUtils.loadClass(name, ClassHelper.class); return instantiateClass(clazz, constructorArgs); } }
/** * This is a convenience method to load a resource as a stream. * * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return url != null ? url.openStream() : null; } catch (IOException e) { return null; } }
/** * 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); } }