FileDocCategorySizeDatePackage
AlternateDocBase.javaAPI DocGlassfish v2 API9479Fri May 04 22:31:54 BST 2007org.apache.catalina.core

AlternateDocBase

public class AlternateDocBase extends Object

Fields Summary
private String
pattern
private UrlPatternType
patternType
private int
patternSlashCount
private String
docBase
private String
basePath
private String
patternSuffix
private String
wildcardPath
private org.apache.naming.resources.ProxyDirContext
resources
private DirContext
webappResources
Constructors Summary
Methods Summary
public static org.apache.catalina.core.AlternateDocBasefindMatch(java.lang.String path, java.util.ArrayList alternateDocBases)
Attempts to match the given request path against one of the given alternate doc bases.

return
The alternate doc base whose url pattern matches the given path, or null if no matching alternate doc base could be found


        if (alternateDocBases == null) {
            return null;
        }

        AlternateDocBase match = null;
        AlternateDocBase wildcardMatch = null;
        AlternateDocBase extensionMatch = null;
        int maxSlashCountMatch = 0;

        int pathSlashCount = getSlashCount(path);

        for (int i=0; i<alternateDocBases.size(); i++) {

            AlternateDocBase alternateDocBase = alternateDocBases.get(i);
            String pattern = alternateDocBase.getUrlPattern();
            int patternSlashCount = alternateDocBase.getUrlPatternSlashCount();
            AlternateDocBase.UrlPatternType type =
                alternateDocBase.getUrlPatternType();
            String wildcardPath = alternateDocBase.getUrlPatternWildcardPath();

            if (type == UrlPatternType.EXACT && path.equals(pattern)) {
                // Exact match found
                match = alternateDocBase;
                break;
            } else if (type == UrlPatternType.WILDCARD
                    && pathSlashCount >= patternSlashCount
                    && patternSlashCount > maxSlashCountMatch
                    && path.startsWith(wildcardPath)) {
                // We've found a longer wildcard match
                wildcardMatch = alternateDocBase;
                maxSlashCountMatch = patternSlashCount;
            } else if (type == UrlPatternType.EXTENSION
                    && path.endsWith(alternateDocBase.getUrlPatternSuffix())) {
                extensionMatch = alternateDocBase;
            }
        }

        if (match == null) {
            if (wildcardMatch != null) {
                match = wildcardMatch;
            } else {
                match = extensionMatch;
            }
        }

        return match;
    
public java.lang.StringgetBasePath()
Gets the absolute doc base path of this AlternateDocBase.

return
The absolute doc base path of this AlternativeDocBase

        return basePath;
    
public java.lang.StringgetDocBase()
Gets the (possibly relative) doc base path of this AlternateDocBase.

return
The (possibly relative) doc base path of this AlternativeDocBase

        return docBase;
    
public org.apache.naming.resources.ProxyDirContextgetResources()
Gets the proxied resources of this AlternateDocBase.

return
The proxied resources of this AlternateDocBase

        return resources;
    
private static intgetSlashCount(java.lang.String s)
Determines the number for forward slashes in the given string.

param
s The string whose forward slashes to count
return
The number of forward slashes


        int count = 0;

        if (s != null) {
            int index = s.indexOf('/");
            while (index >= 0) {
                count++;
                index = s.indexOf('/", index+1);
            }
        }

        return count;
    
public java.lang.StringgetUrlPattern()
Gets the url pattern of this AlternateDocBase.

return
The url pattern of this AlternativeDocBase

        return pattern;
    
public intgetUrlPatternSlashCount()
Gets the number of slashes in the url pattern of this AlternateDocBase.

return
Number of slashes in the url pattern of this AlternateDocBase.

        return patternSlashCount;
    
public java.lang.StringgetUrlPatternSuffix()
Gets the extension suffix of the url pattern of this AlternateDocBase.

return
The extension suffix of the url pattern of this AlternateDocBase, or null if the url pattern is not of type 'extension'

        return this.patternSuffix;
    
public org.apache.catalina.core.AlternateDocBase$UrlPatternTypegetUrlPatternType()
Gets the url pattern type (exact, wildcard, extension) of this AlternateDocBase.

return
The url pattern type (exact, wildcard, extension) of this AlternativeDocBase

        return patternType;
    
public java.lang.StringgetUrlPatternWildcardPath()
Gets the wildcard path of this AlternateDocBase (this is the path specified by the wildcard pattern, minus the trailing '*').

return
The wildcard path of this AlternateDocBase, or null if the pattern associated with this AlternateDocBase is not a wildcard pattern

        return this.wildcardPath;
    
public javax.naming.directory.DirContextgetWebappResources()
Gets the non-proxied resources of this AlternateDocBase.

return
The non-proxied resources of this AlternateDocBase

        return webappResources;
    
public voidsetBasePath(java.lang.String basePath)
Sets the absolute doc base path of this AlternateDocBase.

param
basePath The absolute doc base path of this AlternateDocBase

        this.basePath = basePath;
    
public voidsetDocBase(java.lang.String docBase)
Sets the (possibly relative) doc base path of this AlternateDocBase.

param
docBase The (possibly relative) doc base path of this AlternateDocBase

        this.docBase = docBase;
    
public voidsetResources(org.apache.naming.resources.ProxyDirContext resources)
Sets the proxied resources of this AlternateDocBase.

param
resources The proxied resources of this AlternateDocBase

        this.resources = resources;
    
public voidsetUrlPattern(java.lang.String urlPattern)
Sets the url pattern of this AlternateDocBase.

param
urlPattern The url pattern of this AlternateDocBase

        this.pattern = urlPattern;

        this.patternSlashCount = getSlashCount(urlPattern);
        if (urlPattern.endsWith("/*")) {
            this.patternType = UrlPatternType.WILDCARD;
            this.wildcardPath = urlPattern.substring(
                0, urlPattern.length()-1);
        } else if (urlPattern.startsWith("*.")) {
            this.patternType = UrlPatternType.EXTENSION;
            this.patternSuffix = urlPattern.substring(1);
        } else {
            this.patternType = UrlPatternType.EXACT;
        }
    
public voidsetWebappResources(javax.naming.directory.DirContext webappResources)
Sets the non-proxied resources of this AlternateDocBase.

param
resources The non-proxied resources of this AlternateDocBase

        this.webappResources = webappResources;