use of org.apache.naming.NamingEntry in project tomcat70 by apache.
the class BaseDirContext method list.
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
if (!aliases.isEmpty()) {
AliasResult result = findAlias(name);
if (result.dirContext != null) {
return result.dirContext.list(result.aliasName);
}
}
// Next do a standard lookup
List<NamingEntry> bindings = doListBindings(name);
// Check the alternate locations
List<NamingEntry> altBindings = null;
String resourceName = "/META-INF/resources" + name;
for (DirContext altDirContext : altDirContexts) {
if (altDirContext instanceof BaseDirContext) {
altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName);
}
if (altBindings != null) {
if (bindings == null) {
bindings = altBindings;
} else {
bindings.addAll(altBindings);
}
}
}
if (bindings != null) {
return new NamingContextEnumeration(bindings.iterator());
}
// Really not found
throw new NameNotFoundException(sm.getString("resources.notFound", name));
}
use of org.apache.naming.NamingEntry in project tomcat70 by apache.
the class WARDirContext method list.
/**
* List children as objects.
*/
protected ArrayList<NamingEntry> list(Entry entry) {
ArrayList<NamingEntry> entries = new ArrayList<NamingEntry>();
Entry[] children = entry.getChildren();
NamingEntry namingEntry = null;
for (int i = 0; i < children.length; i++) {
ZipEntry current = children[i].getEntry();
Object object = null;
if (current.isDirectory()) {
object = new WARDirContext(base, children[i]);
} else {
object = new WARResource(current);
}
namingEntry = new NamingEntry(children[i].getName(), object, NamingEntry.ENTRY);
entries.add(namingEntry);
}
return entries;
}
use of org.apache.naming.NamingEntry in project tomcat70 by apache.
the class FileDirContext method list.
/**
* List the resources which are members of a collection.
*
* @param file Collection
* @return Vector containing NamingEntry objects
*/
protected List<NamingEntry> list(File file) {
List<NamingEntry> entries = new ArrayList<NamingEntry>();
if (!file.isDirectory())
return entries;
String[] names = file.list();
if (names == null) {
/* Some IO error occurred such as bad file permissions.
Prevent a NPE with Arrays.sort(names) */
log.warn(sm.getString("fileResources.listingNull", file.getAbsolutePath()));
return entries;
}
// Sort alphabetically
Arrays.sort(names);
NamingEntry entry = null;
for (int i = 0; i < names.length; i++) {
File currentFile = new File(file, names[i]);
Object object = null;
if (currentFile.isDirectory()) {
FileDirContext tempContext = new FileDirContext(env);
tempContext.setDocBase(currentFile.getPath());
tempContext.setAllowLinking(getAllowLinking());
object = tempContext;
} else {
object = new FileResource(currentFile);
}
entry = new NamingEntry(names[i], object, NamingEntry.ENTRY);
entries.add(entry);
}
return entries;
}
use of org.apache.naming.NamingEntry in project tomcat70 by apache.
the class BaseDirContext method listBindings.
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
@Override
public final NamingEnumeration<Binding> listBindings(String name) throws NamingException {
if (!aliases.isEmpty()) {
AliasResult result = findAlias(name);
if (result.dirContext != null) {
return result.dirContext.listBindings(result.aliasName);
}
}
// Next do a standard lookup
List<NamingEntry> bindings = doListBindings(name);
// Check the alternate locations
List<NamingEntry> altBindings = null;
String resourceName = "/META-INF/resources" + name;
for (DirContext altDirContext : altDirContexts) {
if (altDirContext instanceof BaseDirContext) {
altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName);
}
if (altBindings != null) {
if (bindings == null) {
bindings = altBindings;
} else {
bindings.addAll(altBindings);
}
}
}
if (bindings != null) {
return new NamingContextBindingsEnumeration(bindings.iterator(), this);
}
// Really not found
throw new NameNotFoundException(sm.getString("resources.notFound", name));
}
use of org.apache.naming.NamingEntry in project tomcat70 by apache.
the class VirtualDirContext method list.
@Override
protected List<NamingEntry> list(File file) {
List<NamingEntry> entries = super.list(file);
if (mappedResourcePaths != null && !mappedResourcePaths.isEmpty()) {
Set<String> entryNames = new HashSet<String>(entries.size());
for (NamingEntry entry : entries) {
entryNames.add(entry.name);
}
// Add appropriate entries from the extra resource paths
String absPath = file.getAbsolutePath();
if (absPath.startsWith(getDocBase() + File.separator)) {
String relPath = absPath.substring(getDocBase().length());
String fsRelPath = relPath.replace(File.separatorChar, '/');
for (Map.Entry<String, List<String>> mapping : mappedResourcePaths.entrySet()) {
String path = mapping.getKey();
List<String> dirList = mapping.getValue();
String res = null;
if (fsRelPath.equals(path)) {
res = "";
} else if (fsRelPath.startsWith(path + "/")) {
res = relPath.substring(path.length());
}
if (res != null) {
for (String resourcesDir : dirList) {
File f = new File(resourcesDir, res);
f = validate(f, res, true, resourcesDir);
if (f != null && f.isDirectory()) {
List<NamingEntry> virtEntries = super.list(f);
for (NamingEntry entry : virtEntries) {
// filter duplicate
if (!entryNames.contains(entry.name)) {
entryNames.add(entry.name);
entries.add(entry);
}
}
}
}
}
}
}
}
return entries;
}
Aggregations