|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.xwork.util.ResourceScanner
public class ResourceScanner
Scans for resource that resides within classpath and jar file.
Typical usage would be :- To scan for all resources (apple.txt) that lies in the root of a classpath or in the root of the jar file.
// to scan for a resource (apple.txt) that lies in the root of a classpath or in
// the root of the jar file.
ResourceScanner resourceScanner = new ResourceScanner(
new String[] { "" }, // an empty string indicate that the scanning should start at the 'root'
MyMain.class
);
List ourResources = resourceScanner.scanForResources(
new ResourceScanner.Filter() {
public boolean accept(URL resource) {
if (resource.getFile().endsWith("apple.txt")) {
return true;
}
return false;
}
});
To scan for all resources that lies under the '/com/opensymphony/xwork/util' directory in
the classpath, we could do
List ourResources = new ResourceScanner(
new String[] { "com/opensymphony/xwork/util/" }, // Note that it DOES NOT start with a '/' and MUST ends with '/'
MyMain.class).scanForResources();
Nested Class Summary | |
---|---|
static interface |
ResourceScanner.Filter
|
Constructor Summary | |
---|---|
ResourceScanner(String[] roots,
Class callingClass)
Create an instance of ResourceScanner , taking
in arguments
root - An array of String, defining the root we should start scanning
for resources.
callingClass - The class invoking methods on
ResourceScanner
|
Method Summary | |
---|---|
protected URL[] |
getResources(String resourceName,
Class callingClass)
Returns an array of URL corresponding to resourceName . |
List |
loadResourcesFromClassPath(File rootFile,
ResourceScanner.Filter filter,
List resources)
|
List |
loadResourcesFromJarFile(String jarFilePath,
String root,
File jarFile,
ResourceScanner.Filter filter,
List resources)
|
protected List |
loadRootResourcesFromJarFile(String jarFilePath,
File jarFile,
ResourceScanner.Filter filter,
List resources)
Find resources (a List of URL ) from a jar file that lies in the
root of the jar file, applying ResourceScanner.Filter on each
resources found. |
List |
scanForResources()
Start scanning for the resources, assuming that all the resources under roots
specified in the constructor is what we need. |
List |
scanForResources(ResourceScanner.Filter filter)
Start scanning for the resources under roots as specified in the constructor
applying filter (ResourceScanner.Filter )
to the resources that we've found. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResourceScanner(String[] roots, Class callingClass)
ResourceScanner
, taking
in arguments
root
- An array of String, defining the root we should start scanning
for resources.callingClass
- The class invoking methods on
ResourceScanner
roots
- An array of String, defining the root we should start scanning for resources.callingClass
- The class invoking methods on ResourceScanner
Method Detail |
---|
public List scanForResources() throws IOException, URISyntaxException
roots
specified in the constructor is what we need.
List
of URL
.
IOException
URISyntaxException
public List scanForResources(ResourceScanner.Filter filter) throws IOException, URISyntaxException
roots
as specified in the constructor
applying filter
(ResourceScanner.Filter
)
to the resources that we've found.
filter
-
List
of URL
IOException
URISyntaxException
protected List loadRootResourcesFromJarFile(String jarFilePath, File jarFile, ResourceScanner.Filter filter, List resources) throws IOException
List
of URL
) from a jar file that lies in the
root of the jar file, applying ResourceScanner.Filter
on each
resources found.
jarFilePath
- jarFile
- filter
- resources
-
List
of URL
.
IOException
public List loadResourcesFromJarFile(String jarFilePath, String root, File jarFile, ResourceScanner.Filter filter, List resources) throws IOException
IOException
public List loadResourcesFromClassPath(File rootFile, ResourceScanner.Filter filter, List resources) throws URISyntaxException, MalformedURLException
URISyntaxException
MalformedURLException
protected URL[] getResources(String resourceName, Class callingClass) throws IOException
URL
corresponding to resourceName
.
Search for URL
s using ClassLoader
in the following precedence :-
callingClass
's class loader
resourceName
- callingClass
-
IOException
|
WebWork Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |