/** * Returns the ClassLoader to use when looking up resources under the top level package. By default, this is the * context class loader. * * @return the ClassLoader used to lookup resources */ protected ClassLoader getClassLoader() { return ClassUtils.getContextClassLoader(); }
public static InputStream getResourceAsStream(String resource) { InputStream stream = getContextClassLoader() .getResourceAsStream(resource); if (stream == null) { // fallback stream = ClassUtils.class.getClassLoader().getResourceAsStream(resource); } return stream; }
/** * Gets the ClassLoader associated with the current thread. Returns the class loader associated with * the specified default object if no context loader is associated with the current thread. * * @param defaultObject The default object to use to determine the class loader * (if none associated with current thread.) * @return ClassLoader */ protected static ClassLoader getCurrentLoader(Object defaultObject) { ClassLoader loader = getContextClassLoader(); if(loader == null) { loader = defaultObject.getClass().getClassLoader(); } return loader; }
public Collection<URL> getMetaInfConfigurationResources(ExternalContext context) throws IOException { ClassLoader contextClassLoader = ClassUtils.getContextClassLoader(); Enumeration<URL> metaInfConfigUrls = null; List<URL> configUrls = new ArrayList<URL>(); try { // NOTE that there could be multiple config files (in different jar files) metaInfConfigUrls = contextClassLoader.getResources(META_INF_CONFIG_FILE); } catch (IOException e) { throw new FacesException("Could not open " + MyFacesResourceHandlerUrlProvider.META_INF_CONFIG_FILE, e); } if (metaInfConfigUrls != null && metaInfConfigUrls.hasMoreElements()) { while (metaInfConfigUrls.hasMoreElements()) { URL url = metaInfConfigUrls.nextElement(); if (url != null) { configUrls.add(url); } } } return configUrls; }
.getBundle(bundleName, locale, ClassUtils.getContextClassLoader());