Package org.eclipse.sisu.space
Class ResourceEnumeration
- java.lang.Object
-
- org.eclipse.sisu.space.ResourceEnumeration
-
- All Implemented Interfaces:
java.util.Enumeration<java.net.URL>
final class ResourceEnumeration extends java.lang.Object implements java.util.Enumeration<java.net.URL>
Enumeration
of resources found by scanning JARs and directories.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ResourceEnumeration.NestedJarConnection
CustomURLConnection
that can access JARs nested inside an arbitrary resource.(package private) static class
ResourceEnumeration.NestedJarHandler
CustomURLStreamHandler
that can stream JARs nested inside an arbitrary resource.
-
Field Summary
Fields Modifier and Type Field Description private java.net.URL
currentURL
private java.util.Iterator<java.lang.String>
entryNames
private GlobberStrategy
globber
private java.lang.Object
globPattern
private int
index
private boolean
isFolder
private java.lang.String
nextEntryName
private static java.util.Iterator<java.lang.String>
NO_ENTRIES
private boolean
recurse
private java.lang.String
subPath
private java.net.URL[]
urls
-
Constructor Summary
Constructors Constructor Description ResourceEnumeration(java.lang.String subPath, java.lang.String glob, boolean recurse, java.net.URL[] urls)
Creates anEnumeration
that scans the given URLs for resources matching the globbed pattern.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.net.URL
findResource(java.lang.String name)
Returns aURL
pointing to the named resource underneath the current search URL.boolean
hasMoreElements()
private boolean
matchesRequest(java.lang.String entryName)
Compares the given entry name against the normalized search path and compiled glob pattern.java.net.URL
nextElement()
(package private) static java.lang.String
normalizeSearchPath(java.lang.String path)
Normalizes the initial search path by removing any duplicate or initial slashes.private java.util.Iterator<java.lang.String>
scan(java.net.URL url)
Returns the appropriateIterator
to iterate over the contents of the given URL.
-
-
-
Field Detail
-
NO_ENTRIES
private static final java.util.Iterator<java.lang.String> NO_ENTRIES
-
urls
private final java.net.URL[] urls
-
subPath
private final java.lang.String subPath
-
globber
private final GlobberStrategy globber
-
globPattern
private final java.lang.Object globPattern
-
recurse
private final boolean recurse
-
index
private int index
-
currentURL
private java.net.URL currentURL
-
isFolder
private boolean isFolder
-
entryNames
private java.util.Iterator<java.lang.String> entryNames
-
nextEntryName
private java.lang.String nextEntryName
-
-
Constructor Detail
-
ResourceEnumeration
ResourceEnumeration(java.lang.String subPath, java.lang.String glob, boolean recurse, java.net.URL[] urls)
Creates anEnumeration
that scans the given URLs for resources matching the globbed pattern.- Parameters:
subPath
- An optional path to begin the search fromglob
- The globbed basename patternrecurse
- Whentrue
search paths below the initial search point; otherwise don'turls
- The URLs containing resources
-
-
Method Detail
-
hasMoreElements
public boolean hasMoreElements()
- Specified by:
hasMoreElements
in interfacejava.util.Enumeration<java.net.URL>
-
nextElement
public java.net.URL nextElement()
- Specified by:
nextElement
in interfacejava.util.Enumeration<java.net.URL>
-
normalizeSearchPath
static java.lang.String normalizeSearchPath(java.lang.String path)
Normalizes the initial search path by removing any duplicate or initial slashes.- Parameters:
path
- The path to normalize- Returns:
- Normalized search path
-
scan
private java.util.Iterator<java.lang.String> scan(java.net.URL url)
Returns the appropriateIterator
to iterate over the contents of the given URL.- Parameters:
url
- The containing URL- Returns:
- Iterator that iterates over resources contained inside the given URL
-
findResource
private java.net.URL findResource(java.lang.String name) throws java.net.MalformedURLException
Returns aURL
pointing to the named resource underneath the current search URL.- Parameters:
name
- The resource name- Returns:
- URL for the resource
- Throws:
java.net.MalformedURLException
-
matchesRequest
private boolean matchesRequest(java.lang.String entryName)
Compares the given entry name against the normalized search path and compiled glob pattern.- Parameters:
entryName
- The entry name- Returns:
true
if the given name matches the search criteria; otherwisefalse
-
-