ResourceFinder finder = new ResourceFinder("META-INF/services/"); List<Class<? extends Plugin>> impls = finder.findAllImplementations(Plugin.class);
ResourceFinder finder = new ResourceFinder("META-INF/"); Map<String, Class<? extends URLStreamHandler>> handlers = finder.mapAllImplementations(URLStreamHandler.class); Class<? extends URLStreamHandler> fooHandler = handlers.get("foo");
ResourceFinder finder = new ResourceFinder("META-INF/"); Map<String,Properties> plugins = finder.mapAllProperties(Plugin.class.getName()); Properties redDefinition = plugins.get("red");
ResourceFinder finder = new ResourceFinder(classPathLocation, getClassLoaderInterface()); try { Map<String, URL> matches = finder.getResourcesMap(""); if (matches != null) { Test<URL> resourceTest = getResourceTest(resultPath, actionName);
Map<String, URL> resourcesMap = getResourcesMap(uri); for (Map.Entry<String, URL> entry : resourcesMap.entrySet()) { String name = entry.getKey(); URL url = entry.getValue(); String value = readContents(url); strings.put(name, value);
Map<String, URL> map = getResourcesMap(uri); for (Map.Entry<String, URL> entry : map.entrySet()) { String string = entry.getKey(); URL url = entry.getValue(); Properties properties = loadProperties(url); propertiesMap.put(string, properties);
URL url = new File("some.jar").toURI().toURL(); ResourceFinder finder = new ResourceFinder("META-INF/services/", url);
/** * Gets a list of subpckages from jars or dirs */ public Set<String> findPackages(String uri) throws IOException { String basePath = path + uri; Set<String> resources = new HashSet<String>(); if (!basePath.endsWith("/")) { basePath += "/"; } Enumeration<URL> urls = getResources(basePath); while (urls.hasMoreElements()) { URL location = urls.nextElement(); try { if ("jar".equals(location.getProtocol())) { readJarDirectoryEntries(location, basePath, resources); } else if ("file".equals(location.getProtocol())) { readSubDirectories(new File(location.toURI()), uri, resources); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Got exception search for subpackages for #0", e, uri); } } } return convertPathsToPackages(resources); }
protected Set<ApplicationResource> findResources(String path) throws IOException { Set<ApplicationResource> resources = new HashSet<>(); LOG.trace("Using ResourceFinder to find matches for {}", path); Pattern pattern = WildcardUtil.compileWildcardPattern(path); Map<String, URL> matches = finder.getResourcesMap(""); for (Map.Entry<String, URL> entry : matches.entrySet()) { if (pattern.matcher(entry.getKey()).matches()) { resources.add(new StrutsApplicationResource(entry.getValue())); } } LOG.trace("Found resources {} for path {}", resources, path); return resources; }
private URL getResource(String fullUri) { if (urls == null){ return classLoaderInterface.getResource(fullUri); } return findResource(fullUri, urls); }
/** * Executes findAllStrings assuming the strings are * the names of a classes that should be loaded and returned. * <p/> * Any URL or class that cannot be loaded will cause an exception to be thrown. * * @param uri * @return * @throws IOException * @throws ClassNotFoundException */ public List<Class> findAllClasses(String uri) throws IOException, ClassNotFoundException { List<Class> classes = new ArrayList<Class>(); List<String> strings = findAllStrings(uri); for (String className : strings) { Class clazz = classLoaderInterface.loadClass(className); classes.add(clazz); } return classes; }
/** * Executes findAvailableStrings assuming the strings are * the names of a classes that should be loaded and returned. * <p/> * Any class that cannot be loaded will be skipped and placed in the * 'resourcesNotLoaded' collection. * * @param uri * @return * @throws IOException if classLoader.getResources throws an exception */ public List<Class> findAvailableClasses(String uri) throws IOException { resourcesNotLoaded.clear(); List<Class> classes = new ArrayList<Class>(); List<String> strings = findAvailableStrings(uri); for (String className : strings) { try { Class clazz = classLoaderInterface.loadClass(className); classes.add(clazz); } catch (Exception notAvailable) { resourcesNotLoaded.add(className); } } return classes; }
ResourceFinder finder = new ResourceFinder(classPathLocation, getClassLoaderInterface()); try { Map<String, URL> matches = finder.getResourcesMap(""); if (matches != null) { Test<URL> resourceTest = getResourceTest(resultPath, actionName);
resourcesNotLoaded.clear(); Map<String, String> strings = new HashMap<String, String>(); Map<String, URL> resourcesMap = getResourcesMap(uri); for (Map.Entry<String, URL> entry : resourcesMap.entrySet()) { String name = entry.getKey(); URL url = entry.getValue(); try { String value = readContents(url); strings.put(name, value); } catch (IOException notAvailable) {
resourcesNotLoaded.clear(); Map<String, Properties> propertiesMap = new HashMap<String, Properties>(); Map<String, URL> map = getResourcesMap(uri); for (Map.Entry<String, URL> entry : map.entrySet()) { String string = entry.getKey(); URL url = entry.getValue(); try { Properties properties = loadProperties(url); propertiesMap.put(string, properties); } catch (Exception notAvailable) {
public StrutsWildcardServletApplicationContext(ServletContext context) { super(context); Set<URL> urls = new HashSet<>(); for (Object path : context.getResourcePaths("/")) { try { String realPath = context.getRealPath(String.valueOf(path)); if (realPath != null) { URL url = new File(realPath).toURI().toURL(); urls.add(url); } } catch (MalformedURLException e) { throw new ConfigurationException(e); } } try { Enumeration<URL> resources = getClass().getClassLoader().getResources("/"); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); urls.add(resource); } } catch (IOException e) { throw new ConfigurationException(e); } finder = new ResourceFinder(urls.toArray(new URL[urls.size()])); }
/** * Gets a list of subpckages from jars or dirs */ public Map<URL, Set<String>> findPackagesMap(String uri) throws IOException { String basePath = path + uri; if (!basePath.endsWith("/")) { basePath += "/"; } Enumeration<URL> urls = getResources(basePath); Map<URL, Set<String>> result = new HashMap<URL, Set<String>>(); while (urls.hasMoreElements()) { URL location = urls.nextElement(); try { if ("jar".equals(location.getProtocol())) { Set<String> resources = new HashSet<String>(); readJarDirectoryEntries(location, basePath, resources); result.put(location, convertPathsToPackages(resources)); } else if ("file".equals(location.getProtocol())) { Set<String> resources = new HashSet<String>(); readSubDirectories(new File(location.toURI()), uri, resources); result.put(location, convertPathsToPackages(resources)); } } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Got exception finding subpackages for #0", e, uri); } } } return result; }
private Enumeration<URL> getResources(String fulluri) throws IOException { if (urls == null) { return classLoaderInterface.getResources(fulluri); } Vector<URL> resources = new Vector(); for (URL url : urls) { URL resource = findResource(fulluri, url); if (resource != null){ resources.add(resource); } } return resources.elements(); }
List<String> strings = findAllStrings(interfase.getName()); for (String className : strings) { Class impl = classLoaderInterface.loadClass(className);
resourcesNotLoaded.clear(); List<Class> implementations = new ArrayList<Class>(); List<String> strings = findAvailableStrings(interfase.getName()); for (String className : strings) { try {