Search in sources :

Example 6 with NamingEntry

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));
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) NamingContextEnumeration(org.apache.naming.NamingContextEnumeration) NamingEntry(org.apache.naming.NamingEntry) DirContext(javax.naming.directory.DirContext)

Example 7 with NamingEntry

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;
}
Also used : ZipEntry(java.util.zip.ZipEntry) NamingEntry(org.apache.naming.NamingEntry) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) NamingEntry(org.apache.naming.NamingEntry)

Example 8 with NamingEntry

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;
}
Also used : ArrayList(java.util.ArrayList) NamingEntry(org.apache.naming.NamingEntry) File(java.io.File)

Example 9 with NamingEntry

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));
}
Also used : NamingContextBindingsEnumeration(org.apache.naming.NamingContextBindingsEnumeration) NameNotFoundException(javax.naming.NameNotFoundException) NamingEntry(org.apache.naming.NamingEntry) DirContext(javax.naming.directory.DirContext)

Example 10 with NamingEntry

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;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) NamingEntry(org.apache.naming.NamingEntry) Map(java.util.Map) HashMap(java.util.HashMap) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

NamingEntry (org.apache.naming.NamingEntry)11 File (java.io.File)5 ArrayList (java.util.ArrayList)3 JarFile (java.util.jar.JarFile)3 ZipEntry (java.util.zip.ZipEntry)3 NameNotFoundException (javax.naming.NameNotFoundException)2 NamingException (javax.naming.NamingException)2 DirContext (javax.naming.directory.DirContext)2 NamingContextBindingsEnumeration (org.apache.naming.NamingContextBindingsEnumeration)2 NamingContextEnumeration (org.apache.naming.NamingContextEnumeration)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 CompositeName (javax.naming.CompositeName)1 Name (javax.naming.Name)1