com.mortbay.HTTP
Class PathMap

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--com.mortbay.HTTP.PathMap

public class PathMap
extends java.util.Dictionary

URI Path map to object

Implements a best match of paths to objects

Notes
Paths ending with '$' must match the path absolutely,
Paths ending with '/' must match an exact path element,
Paths ending with '%' match either an absolute path or exact path element
Paths ending with '|' match either an absolute path or trailing '/'
Paths may include a * to separate prefix and suffix matches. Suffix matches have precedence.

All other paths only need to be a prefix to match.

Path suffixes are also supported. For example for /aaa/bbb/ccc.c the match priorities are:

Path PrefixMatch ExamplesMiss Examples
/aaa/bbb /aaa/bbb
/aaa/bbb/
/aaa/bbb/ccc
/aaa/bbbbbb
/aaa
/aaa/ccc
/aaa/bbb% /aaa/bbb
/aaa/bbb/
/aaa/bbb/ccc
/aaa
/aaa/ccc
/aaa/bbbbbb
/aaa/bbb/ /aaa/bbb/
/aaa/bbb/ccc
/aaa
/aaa/bbb
/aaa/bbbbbb
/aaa/ccc
/aaa/bbb| /aaa/bbb
/aaa/bbb/
/aaa
/aaa/ccc
/aaa/bbb/ccc
/aaa/bbbbbb
/aaa/bbb$ /aaa/bbb
/aaa
/aaa/ccc
/aaa/bbb/
/aaa/bbb/ccc
/aaa/bbbbbb
*.xxx .xxx
xxx.xxx

.xxxx
xxxx.xxxx
.xx
xx.xx
/yyy/*.zzz /yyy/.zzz
/yyy/xxx.zzz

.zzz
/aaa/xxx.zzz
/yyy/xxx.zzzz

Version:
$Id: PathMap.java,v 2.11 2000/11/07 15:34:38 gregwilkins Exp $
Author:
Greg Wilkins

Constructor Summary
PathMap()
          Construct empty PathMap
PathMap(java.util.Dictionary d)
          Construct from dictionary PathMap
 
Method Summary
 void add(java.util.Dictionary d)
          Add contents of dictionary to PathMap
 void clear()
           
 java.util.Enumeration elements()
           
 java.lang.Object get(java.lang.Object pathSpec)
          Get object by path specification
 java.lang.Object getLongestMatch(java.lang.String path)
          Deprecated. use match
 boolean isEmpty()
           
 java.util.Enumeration keys()
           
 java.lang.String longestMatch(java.lang.String path)
          Deprecated. use matchSpec
 java.lang.Object match(java.lang.String path)
          Get the object that is mapped by the longest path specification that matches the path
static java.lang.String match(java.lang.String pathSpec, java.lang.String path)
          Return the portion of a path that matches a path spec (with %$|/ etc.)
 java.lang.String matchSpec(java.lang.String path)
          Get the pathSpec that is mapped by the longest path specification that matches the path
static java.lang.String pathInfo(java.lang.String pathSpec, java.lang.String path)
          Return the portion of a path that is after a path spec (with %$|/ etc.)
 java.lang.Object put(java.lang.Object pathSpec, java.lang.Object object)
          Add a single path match to the PathMap
 java.lang.Object put(java.lang.String pathSpec, java.lang.Object object)
          Add a single path match to the PathMap
 java.lang.Object remove(java.lang.Object pathSpec)
           
 java.lang.Object remove(java.lang.String pathSpec)
           
 int size()
           
 java.lang.String toString()
           
static java.lang.String translate(java.lang.String oldPath, java.lang.String pathSpec, java.lang.String newPath)
          Return a translated address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PathMap

public PathMap()
Construct empty PathMap

PathMap

public PathMap(java.util.Dictionary d)
Construct from dictionary PathMap
Method Detail

add

public void add(java.util.Dictionary d)
Add contents of dictionary to PathMap

put

public java.lang.Object put(java.lang.String pathSpec,
                            java.lang.Object object)
Add a single path match to the PathMap
Parameters:
pathSpec - The path specification.
object - The object the path maps to

put

public java.lang.Object put(java.lang.Object pathSpec,
                            java.lang.Object object)
Add a single path match to the PathMap
Overrides:
put in class java.util.Dictionary
Parameters:
pathSpec - The path specification.
object - The object the path maps to

match

public java.lang.Object match(java.lang.String path)
Get the object that is mapped by the longest path specification that matches the path

matchSpec

public java.lang.String matchSpec(java.lang.String path)
Get the pathSpec that is mapped by the longest path specification that matches the path

elements

public java.util.Enumeration elements()
Overrides:
elements in class java.util.Dictionary

get

public java.lang.Object get(java.lang.Object pathSpec)
Get object by path specification
Overrides:
get in class java.util.Dictionary

longestMatch

public java.lang.String longestMatch(java.lang.String path)
Deprecated. use matchSpec

Get the longest matching path specification

getLongestMatch

public java.lang.Object getLongestMatch(java.lang.String path)
Deprecated. use match

Get the object that is mapped by the longest path specification that matches the path

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class java.util.Dictionary

keys

public java.util.Enumeration keys()
Overrides:
keys in class java.util.Dictionary

remove

public java.lang.Object remove(java.lang.Object pathSpec)
Overrides:
remove in class java.util.Dictionary

remove

public java.lang.Object remove(java.lang.String pathSpec)

size

public int size()
Overrides:
size in class java.util.Dictionary

clear

public void clear()

pathInfo

public static java.lang.String pathInfo(java.lang.String pathSpec,
                                        java.lang.String path)
                                 throws java.net.MalformedURLException
Return the portion of a path that is after a path spec (with %$|/ etc.)
Returns:
The path info string

match

public static java.lang.String match(java.lang.String pathSpec,
                                     java.lang.String path)
Return the portion of a path that matches a path spec (with %$|/ etc.)
Returns:
null if no match at all.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

translate

public static java.lang.String translate(java.lang.String oldPath,
                                         java.lang.String pathSpec,
                                         java.lang.String newPath)
Return a translated address. The part of the address that matches the path is replaced with the translation string.
Parameters:
oldPath - A URL path to be translated
pathSpec - The PathMap path string that matched (may include special %|$ etc characters).
newPath - The string to replace the path with.
Returns:
translated address.