org.securityfilter.filter
Class URLPattern

java.lang.Object
  extended byorg.securityfilter.filter.URLPattern
All Implemented Interfaces:
Comparable

public class URLPattern
extends Object
implements Comparable

URLPattern - Contains matchable URL pattern and the associated SecurityConstraint and WebResourceCollection objects for the pattern. Also supports sorting according to the Servlet Spec v2.3.

Version:
$Revision: 1.1 $ $Date: 2004/07/03 20:53:45 $
Author:
Max Cooper (max@maxcooper.com)

Field Summary
protected  org.apache.oro.text.regex.Pattern compiledPattern
           
protected  SecurityConstraint constraint
           
protected  String convertedPattern
           
static int DEFAULT_TYPE
          Pattern type for EXTENSION_TYPE mappings.
static int EXACT_TYPE
          Pattern type for patterns that do not meet the specifications for the other pattern types.
static int EXTENSION_TYPE
          Pattern type for EXTENSION_TYPE mappings.
protected  int order
           
static int PATH_TYPE
          Pattern type for PATH_TYPE mappings.
protected  int pathLength
           
protected  String pattern
           
protected  int patternType
           
protected  WebResourceCollection resourceCollection
           
 
Constructor Summary
URLPattern(String pattern, SecurityConstraint constraint, WebResourceCollection resourceCollection, int order, org.apache.oro.text.regex.PatternCompiler compiler)
          Construct a new URLPattern object.
 
Method Summary
 int compareTo(Object obj)
          Compares this URLPattern to obj to support sorting.
 boolean equals(Object obj)
          Test if this pattern is equivalent to another pattern.
 org.apache.oro.text.regex.Pattern getCompiledPattern()
          Get the compiled version of this pattern.
 int getOrder()
          Get the order value for this pattern (the order in which it appeared in the config file).
 int getPathLength()
          Get the path length of the pattern.
 String getPattern()
          Get the url pattern to match.
 int getPatternType()
          Get the pattern type.
 SecurityConstraint getSecurityConstraint()
          Get the SecurityConstraint object associated with this pattern.
 WebResourceCollection getWebResourceCollection()
          Get the WebResourceCollection associated with this pattern.
protected  void initCompiledPattern(org.apache.oro.text.regex.PatternCompiler compiler)
          Initialize the compiledPattern protected member.
protected  void initConvertedPattern()
          Initialize the convertedPattern protected member.
protected  void initPathLength()
          Initialize the pathLength protected member.
protected  void initPatternType()
          Initialize the patternType protected member.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXACT_TYPE

public static final int EXACT_TYPE
Pattern type for patterns that do not meet the specifications for the other pattern types.

See Also:
Constant Field Values

PATH_TYPE

public static final int PATH_TYPE
Pattern type for PATH_TYPE mappings. Starts with '/' and ends with '/*'.

See Also:
Constant Field Values

EXTENSION_TYPE

public static final int EXTENSION_TYPE
Pattern type for EXTENSION_TYPE mappings. Starts with '*.'

See Also:
Constant Field Values

DEFAULT_TYPE

public static final int DEFAULT_TYPE
Pattern type for EXTENSION_TYPE mappings. Starts with '*.'

See Also:
Constant Field Values

pattern

protected String pattern

convertedPattern

protected String convertedPattern

compiledPattern

protected org.apache.oro.text.regex.Pattern compiledPattern

constraint

protected SecurityConstraint constraint

resourceCollection

protected WebResourceCollection resourceCollection

order

protected int order

patternType

protected int patternType

pathLength

protected int pathLength
Constructor Detail

URLPattern

public URLPattern(String pattern,
                  SecurityConstraint constraint,
                  WebResourceCollection resourceCollection,
                  int order,
                  org.apache.oro.text.regex.PatternCompiler compiler)
           throws Exception
Construct a new URLPattern object.

Parameters:
pattern - the url pattern to match
constraint - the SecurityConstraint associated with this pattern
resourceCollection - the WebResourceCollection associated with this pattern
order - the order in which this pattern occurred in the configuration file
compiler - a PatternCompiler to use to compile this url pattern
See Also:
URLPatternFactory
Method Detail

getPattern

public String getPattern()
Get the url pattern to match.


getCompiledPattern

public org.apache.oro.text.regex.Pattern getCompiledPattern()
Get the compiled version of this pattern.

Returns:
compiled version of this pattern

getPatternType

public int getPatternType()
Get the pattern type. The pattern type will be determined on the first call to this method.

Returns:
EXACT, PATH, or EXTENSION

getPathLength

public int getPathLength()
Get the path length of the pattern. This is only valid when getPatternType() = PATH.

Examples:

Returns:
path length of this pattern

getSecurityConstraint

public SecurityConstraint getSecurityConstraint()
Get the SecurityConstraint object associated with this pattern.


getOrder

public int getOrder()
Get the order value for this pattern (the order in which it appeared in the config file).


getWebResourceCollection

public WebResourceCollection getWebResourceCollection()
Get the WebResourceCollection associated with this pattern.


initPatternType

protected void initPatternType()
Initialize the patternType protected member.


initPathLength

protected void initPathLength()
Initialize the pathLength protected member.


initConvertedPattern

protected void initConvertedPattern()
Initialize the convertedPattern protected member.


initCompiledPattern

protected void initCompiledPattern(org.apache.oro.text.regex.PatternCompiler compiler)
                            throws Exception
Initialize the compiledPattern protected member.

Parameters:
compiler -
Throws:
Exception

equals

public boolean equals(Object obj)
Test if this pattern is equivalent to another pattern. This is implemented so that consistency with the compareTo method results can be maintained.

Parameters:
obj - the value to test equivalence with
Returns:
true if the passed object is an equivalent URLPattern, false if it is not a URLPattern or if it is not equivalent.

compareTo

public int compareTo(Object obj)
              throws ClassCastException
Compares this URLPattern to obj to support sorting.

The sort order is dictated by the servlet spec. The ordering by type is: EXACT_TYPE PATH_TYPE EXTENTION_TYPE DEFAULT_TYPE Ordering among PATH_TYPE patterns is determined by path length, with the longer path coming first. If the path lengths are the same, or both patterns are of the same type other than PATH_TYPE, ordering is determined by the order in which the pattern appeared in the config file. Thanks to Chris Nokleberg for contributing code for this method.

Specified by:
compareTo in interface Comparable
Parameters:
obj - another URLPattern to compare to
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
ClassCastException - thrown if obj is not a URLPattern instance