Fields Summary |
---|
protected File | srcFileThe archive file which should be scanned. |
private Resource | srcThe archive resource which should be scanned. |
private Resource | lastScannedResourceto record the last scanned zip file with its modification date |
private TreeMap | fileEntriesrecord list of all file zip entries |
private TreeMap | dirEntriesrecord list of all directory zip entries |
private TreeMap | matchFileEntriesrecord list of matching file zip entries |
private TreeMap | matchDirEntriesrecord list of matching directory zip entries |
private String | encodingencoding of file names. |
Methods Summary |
---|
protected abstract void | fillMapsFromArchive(Resource archive, java.lang.String encoding, java.util.Map fileEntries, java.util.Map matchFileEntries, java.util.Map dirEntries, java.util.Map matchDirEntries)Fills the file and directory maps with resources read from the archive.
|
public java.lang.String[] | getIncludedDirectories()Returns the names of the directories which matched at least one of the
include patterns and none of the exclude patterns.
The names are relative to the base directory.
if (src == null) {
return super.getIncludedDirectories();
}
scanme();
Set s = matchDirEntries.keySet();
return (String[]) (s.toArray(new String[s.size()]));
|
public int | getIncludedDirsCount()Override parent implementation.
if (src == null) {
return super.getIncludedDirsCount();
}
scanme();
return matchDirEntries.size();
|
public java.lang.String[] | getIncludedFiles()Returns the names of the files which matched at least one of the
include patterns and none of the exclude patterns.
The names are relative to the base directory.
if (src == null) {
return super.getIncludedFiles();
}
scanme();
Set s = matchFileEntries.keySet();
return (String[]) (s.toArray(new String[s.size()]));
|
public int | getIncludedFilesCount()Override parent implementation.
if (src == null) {
return super.getIncludedFilesCount();
}
scanme();
return matchFileEntries.size();
|
public Resource | getResource(java.lang.String name)Get the named Resource.
if (src == null) {
return super.getResource(name);
}
if (name.equals("")) {
// special case in ZIPs, we do not want this thing included
return new Resource("", true, Long.MAX_VALUE, true);
}
// first check if the archive needs to be scanned again
scanme();
if (fileEntries.containsKey(name)) {
return (Resource) fileEntries.get(name);
}
name = trimSeparator(name);
if (dirEntries.containsKey(name)) {
return (Resource) dirEntries.get(name);
}
return new Resource(name);
|
java.util.Iterator | getResourceDirectories()Get the set of Resources that represent directories.
if (src == null) {
return new FileResourceIterator(getBasedir(), getIncludedDirectories());
}
scanme();
return matchDirEntries.values().iterator();
|
java.util.Iterator | getResourceFiles()Get the set of Resources that represent files.
if (src == null) {
return new FileResourceIterator(getBasedir(), getIncludedFiles());
}
scanme();
return matchFileEntries.values().iterator();
|
public void | init()Initialize DirectoryScanner data structures.
if (includes == null) {
// No includes supplied, so set it to 'matches all'
includes = new String[1];
includes[0] = "**";
}
if (excludes == null) {
excludes = new String[0];
}
|
public boolean | match(java.lang.String path)Matches a jar entry against the includes/excludes list,
normalizing the path separator.
String vpath = path.replace('/", File.separatorChar).
replace('\\", File.separatorChar);
return isIncluded(vpath) && !isExcluded(vpath);
|
public void | scan()Don't scan when we have no zipfile.
if (src == null) {
return;
}
super.scan();
|
private void | scanme()if the datetime of the archive did not change since
lastScannedResource was initialized returns immediately else if
the archive has not been scanned yet, then all the zip entries
are put into the appropriate tables.
//do not use a FileResource b/c it pulls File info from the filesystem:
Resource thisresource = new Resource(src.getName(),
src.isExists(),
src.getLastModified());
// spare scanning again and again
if (lastScannedResource != null
&& lastScannedResource.getName().equals(thisresource.getName())
&& lastScannedResource.getLastModified()
== thisresource.getLastModified()) {
return;
}
init();
fileEntries.clear();
dirEntries.clear();
matchFileEntries.clear();
matchDirEntries.clear();
fillMapsFromArchive(src, encoding, fileEntries, matchFileEntries,
dirEntries, matchDirEntries);
// record data about the last scanned resource
lastScannedResource = thisresource;
|
public void | setEncoding(java.lang.String encoding)Sets encoding of file names.
this.encoding = encoding;
|
public void | setSrc(java.io.File srcFile)Sets the srcFile for scanning. This is the jar or zip file that
is scanned for matching entries.
setSrc(new FileResource(srcFile));
|
public void | setSrc(Resource src)Sets the src for scanning. This is the jar or zip file that
is scanned for matching entries.
this.src = src;
if (src instanceof FileResource) {
srcFile = ((FileResource) src).getFile();
}
|
protected static final java.lang.String | trimSeparator(java.lang.String s)Remove trailing slash if present.
return s.endsWith("/") ? s.substring(0, s.length() - 1) : s;
|