Methods Summary |
---|
public void | allocate(){@inheritDoc}
super.allocate();
virtualMappings = new Hashtable<String, File>();
tagfileMappings = new Hashtable<String, File>();
// looks into any META-INF dir found in classpath entries for tld files.
StringTokenizer tkn = new StringTokenizer(virtualClasspath, ";");
while (tkn.hasMoreTokens()) {
File file = new File(tkn.nextToken(), "META-INF");
if (!file.exists() || !file.isDirectory()) {
continue;
}
scanForTlds(file);
}
|
public javax.naming.directory.Attributes | getAttributes(java.lang.String name)
// handle "virtual" tlds
if (name.startsWith("/WEB-INF/") && name.endsWith(".tld")) {
String tldName = name.substring(name.lastIndexOf("/") + 1);
if (virtualMappings.containsKey(tldName)) {
return new FileResourceAttributes(virtualMappings.get(tldName));
}
} else if (name.startsWith("/META-INF/tags") && name.endsWith(".tag")
|| name.endsWith(".tagx")) {
// already loaded tag file
if (tagfileMappings.containsKey(name)) {
return new FileResourceAttributes(tagfileMappings.get(name));
}
// unknown tagfile, search for it in virtualClasspath
StringTokenizer tkn = new StringTokenizer(virtualClasspath, ";");
while (tkn.hasMoreTokens()) {
File file = new File(tkn.nextToken(), name);
if (file.exists()) {
tagfileMappings.put(name, file);
return new FileResourceAttributes(file);
}
}
}
return super.getAttributes(name);
|
private java.util.List | getVirtualNamingEntries()Returns a list of virtual naming entries.
List<NamingEntry> virtual = new ArrayList<NamingEntry>();
for (String name : virtualMappings.keySet()) {
File file = virtualMappings.get(name);
NamingEntry entry = new NamingEntry(name, new FileResource(file),
NamingEntry.ENTRY);
virtual.add(entry);
}
return virtual;
|
protected java.util.ArrayList | list(java.io.File file)
ArrayList entries = super.list(file);
// adds virtual tlds for WEB-INF listing
if ("WEB-INF".equals(file.getName())) {
entries.addAll(getVirtualNamingEntries());
}
return entries;
|
public java.lang.Object | lookup(java.lang.String name)
// handle "virtual" tlds
if (name.startsWith("/WEB-INF/") && name.endsWith(".tld")) {
String tldName = name.substring(name.lastIndexOf("/") + 1);
if (virtualMappings.containsKey(tldName)) {
return new FileResource(virtualMappings.get(tldName));
}
} else if (name.startsWith("/META-INF/tags") && name.endsWith(".tag")
|| name.endsWith(".tagx")) {
// already loaded tag file: we are sure that getAttributes() has
// already been called if we are here
File tagFile = tagfileMappings.get(name);
if (tagFile != null) {
return new FileResource(tagFile);
}
}
return super.lookup(name);
|
public void | release(){@inheritDoc}
super.release();
virtualMappings = null;
|
private void | scanForTlds(java.io.File dir)Scan a given dir for tld files. Any found tld will be added to the
virtualMappings.
File[] files = dir.listFiles();
for (int j = 0; j < files.length; j++) {
File file = files[j];
if (file.isDirectory()) {
scanForTlds(file);
} else if (file.getName().endsWith(".tld")) {
// just generate a random name using the current timestamp, name
// doesn't matter since it needs to be referenced by URI
String virtualTldName = "~" + System.currentTimeMillis() + "~"
+ file.getName();
virtualMappings.put(virtualTldName, file);
}
}
|
public void | setVirtualClasspath(java.lang.String path)virtualClasspath attribute that will be automatically set
from the Context virtualClasspath attribute
from the context xml file.
virtualClasspath = path;
|