public synchronized void update() {
if (file.lastModified() != lastModified ||
repositories == null ||
resources == null) {
lastModified = file.lastModified();
ZipFile zipfile = null;
try {
zipfile = getZipFile();
Enumeration en = zipfile.entries();
HashMap newRepositories = new HashMap();
HashMap newResources = new HashMap();
while (en.hasMoreElements()) {
ZipEntry entry = (ZipEntry) en.nextElement();
String eName = entry.getName();
if (!eName.regionMatches(0, entryPath, 0, entryPath.length())) {
// names don't match - not a child of ours
continue;
}
String[] entrypath = StringUtils.split(eName, "/");
if (depth > 0 && !shortName.equals(entrypath[depth-1])) {
// catch case where our name is Foo and other's is FooBar
continue;
}
// create new repositories and resources for all entries with a
// path depth of this.depth + 1
if (entrypath.length == depth + 1 && !entry.isDirectory()) {
// create a new child resource
ZipResource resource = new ZipResource(entry.getName(), this);
newResources.put(resource.getShortName(), resource);
} else if (entrypath.length > depth) {
// create a new child repository
if (!newRepositories.containsKey(entrypath[depth])) {
ZipEntry child = composeChildEntry(entrypath[depth]);
ZipRepository rep = new ZipRepository(file, this, child);
newRepositories.put(entrypath[depth], rep);
}
}
}
repositories = (Repository[]) newRepositories.values()
.toArray(new Repository[newRepositories.size()]);
resources = newResources;
} catch (Exception ex) {
ex.printStackTrace();
repositories = emptyRepositories;
if (resources == null) {
resources = new HashMap();
} else {
resources.clear();
}
} finally {
try {
// unlocks the zip file in the underlying filesystem
zipfile.close();
} catch (Exception ex) {}
}
}
}