org.mortbay.http

Class PathMap

public class PathMap extends HashMap implements Externalizable

URI path map to Object. This mapping implements the path specification recommended in the 2.2 Servlet API. Path specifications can be of the following forms:
 /foo/bar           - an exact path specification.
 /foo/*             - a prefix path specification (must end '/*').
 *.ext              - a suffix path specification.
 /                  - the default path specification.       
 
Matching is performed in the following order
  • Exact match.
  • Longest prefix match.
  • Longest suffix match.
  • default. Multiple path specifications can be mapped by providing a list of specifications. The list is separated by the characters specified in the "org.mortbay.http.PathMap.separators" System property, which defaults to :

    Note that this is a very different mapping to that provided by PathMap in Jetty2.

    This class is not synchronized for get's. If concurrent modifications are possible then it should be synchronized at a higher level.

    Version: $Id: PathMap.java,v 1.25 2005/08/13 00:01:24 gregwilkins Exp $

    Author: Greg Wilkins (gregw)

  • Constructor Summary
    PathMap()
    Construct empty PathMap.
    PathMap(boolean nodefault)
    Construct empty PathMap.
    PathMap(int capacity)
    Construct empty PathMap.
    PathMap(Map m)
    Construct from dictionary PathMap.
    Method Summary
    voidclear()
    EntrygetMatch(String path)
    Get the entry mapped by the best specification.
    ListgetMatches(String path)
    Get all entries matched by the path.
    Objectmatch(String path)
    Get object matched by the path.
    static booleanmatch(String pathSpec, String path)
    static booleanmatch(String pathSpec, String path, boolean noDefault)
    static StringpathInfo(String pathSpec, String path)
    Return the portion of a path that is after a path spec.
    static StringpathMatch(String pathSpec, String path)
    Return the portion of a path that matches a path spec.
    Objectput(Object pathSpec, Object object)
    Add a single path match to the PathMap.
    voidreadExternal(ObjectInput in)
    static StringrelativePath(String base, String pathSpec, String path)
    Relative path.
    Objectremove(Object pathSpec)
    static voidsetPathSpecSeparators(String s)
    Set the path spec separator.
    voidwriteExternal(ObjectOutput out)

    Constructor Detail

    PathMap

    public PathMap()
    Construct empty PathMap.

    PathMap

    public PathMap(boolean nodefault)
    Construct empty PathMap.

    PathMap

    public PathMap(int capacity)
    Construct empty PathMap.

    PathMap

    public PathMap(Map m)
    Construct from dictionary PathMap.

    Method Detail

    clear

    public void clear()

    getMatch

    public Entry getMatch(String path)
    Get the entry mapped by the best specification.

    Parameters: path the path.

    Returns: Map.Entry of the best matched or null.

    getMatches

    public List getMatches(String path)
    Get all entries matched by the path. Best match first.

    Parameters: path Path to match

    Returns: List of Map.Entry instances key=pathSpec

    match

    public Object match(String path)
    Get object matched by the path.

    Parameters: path the path.

    Returns: Best matched object or null.

    match

    public static boolean match(String pathSpec, String path)

    Returns: true if match.

    match

    public static boolean match(String pathSpec, String path, boolean noDefault)

    Returns: true if match.

    pathInfo

    public static String pathInfo(String pathSpec, String path)
    Return the portion of a path that is after a path spec.

    Returns: The path info string

    pathMatch

    public static String pathMatch(String pathSpec, String path)
    Return the portion of a path that matches a path spec.

    Returns: null if no match at all.

    put

    public Object put(Object pathSpec, Object object)
    Add a single path match to the PathMap.

    Parameters: pathSpec The path specification, or comma separated list of path specifications. object The object the path maps to

    readExternal

    public void readExternal(ObjectInput in)

    relativePath

    public static String relativePath(String base, String pathSpec, String path)
    Relative path.

    Parameters: base The base the path is relative to. pathSpec The spec of the path segment to ignore. path the additional path

    Returns: base plus path with pathspec removed

    remove

    public Object remove(Object pathSpec)

    setPathSpecSeparators

    public static void setPathSpecSeparators(String s)
    Set the path spec separator. Multiple path specification may be included in a single string if they are separated by the characters set in this string. The default value is ":," or whatever has been set by the system property org.mortbay.http.PathMap.separators

    Parameters: s separators

    writeExternal

    public void writeExternal(ObjectOutput out)
    Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.