"Fossies" - the Fresh Open Source Software archive

Member "urlrewrite-3.2.0-src/api/org/tuckey/web/filters/urlrewrite/utils/WildcardHelper.html" of archive urlrewritefilter-3.2.0-src.zip:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. Alternatively you can here view or download the uninterpreted source code. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.



org.tuckey.web.filters.urlrewrite.utils
Class WildcardHelper

java.lang.Object
  extended by org.tuckey.web.filters.urlrewrite.utils.WildcardHelper

public class WildcardHelper
extends java.lang.Object

This class is an utility class that perform wilcard-patterns matching and isolation taken from Apache Cocoon.

Version:
$Revision: 1 $ $Date: 2006-08-01 21:40:28 +1200 (Tue, 01 Aug 2006) $

Field Summary
protected static int MATCH_BEGIN
          The int representing begin in the pattern int [].
protected static int MATCH_END
          The int value that terminates the pattern int [].
protected static int MATCH_FILE
          The int representing '*' in the pattern int [].
protected static int MATCH_PATH
          The int representing '**' in the pattern int [].
protected static int MATCH_THEEND
          The int representing end in pattern int [].
 
Constructor Summary
WildcardHelper()
           
 
Method Summary
 int[] compilePattern(java.lang.String data)
          Translate the given String into a int [] representing the pattern matchable by this class.
protected  int indexOfArray(int[] r, int rpos, int rend, char[] d, int dpos)
          Get the offset of a part of an int array within a char array.
protected  int lastIndexOfArray(int[] r, int rpos, int rend, char[] d, int dpos)
          Get the offset of a last occurance of an int array within a char array.
 boolean match(java.util.Map map, java.lang.String data, int[] expr)
          Match a pattern agains a string and isolates wildcard replacement into a Stack.
protected  boolean matchArray(int[] r, int rpos, int rend, char[] d, int dpos)
          Matches elements of array r from rpos to rend with array d, starting from dpos.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATCH_FILE

protected static final int MATCH_FILE
The int representing '*' in the pattern int [].

See Also:
Constant Field Values

MATCH_PATH

protected static final int MATCH_PATH
The int representing '**' in the pattern int [].

See Also:
Constant Field Values

MATCH_BEGIN

protected static final int MATCH_BEGIN
The int representing begin in the pattern int [].

See Also:
Constant Field Values

MATCH_THEEND

protected static final int MATCH_THEEND
The int representing end in pattern int [].

See Also:
Constant Field Values

MATCH_END

protected static final int MATCH_END
The int value that terminates the pattern int [].

See Also:
Constant Field Values
Constructor Detail

WildcardHelper

public WildcardHelper()
Method Detail

compilePattern

public int[] compilePattern(java.lang.String data)
Translate the given String into a int [] representing the pattern matchable by this class.
This function translates a String into an int array converting the special '*' and '\' characters.
Here is how the conversion algorithm works: When more than two '*' characters, not separated by another character, are found their value is considered as '**' (MATCH_PATH).
The array is always terminated by a special value (MATCH_END).
All MATCH* values are less than zero, while normal characters are equal or greater.

Parameters:
data - The string to translate.
Returns:
The encoded string as an int array, terminated by the MATCH_END value (don't consider the array length).
Throws:
java.lang.NullPointerException - If data is null.

match

public boolean match(java.util.Map map,
                     java.lang.String data,
                     int[] expr)
Match a pattern agains a string and isolates wildcard replacement into a Stack.

Parameters:
map - The map to store matched values
data - The string to match
expr - The compiled wildcard expression
Returns:
True if a match
Throws:
java.lang.NullPointerException - If any parameters are null

indexOfArray

protected int indexOfArray(int[] r,
                           int rpos,
                           int rend,
                           char[] d,
                           int dpos)
Get the offset of a part of an int array within a char array.
This method return the index in d of the first occurrence after dpos of that part of array specified by r, starting at rpos and terminating at rend.

Parameters:
r - The array containing the data that need to be matched in d.
rpos - The index of the first character in r to look for.
rend - The index of the last character in r to look for plus 1.
d - The array of char that should contain a part of r.
dpos - The starting offset in d for the matching.
Returns:
The offset in d of the part of r matched in d or -1 if that was not found.

lastIndexOfArray

protected int lastIndexOfArray(int[] r,
                               int rpos,
                               int rend,
                               char[] d,
                               int dpos)
Get the offset of a last occurance of an int array within a char array.
This method return the index in d of the last occurrence after dpos of that part of array specified by r, starting at rpos and terminating at rend.

Parameters:
r - The array containing the data that need to be matched in d.
rpos - The index of the first character in r to look for.
rend - The index of the last character in r to look for plus 1.
d - The array of char that should contain a part of r.
dpos - The starting offset in d for the matching.
Returns:
The offset in d of the last part of r matched in d or -1 if that was not found.

matchArray

protected boolean matchArray(int[] r,
                             int rpos,
                             int rend,
                             char[] d,
                             int dpos)
Matches elements of array r from rpos to rend with array d, starting from dpos.
This method return true if elements of array r from rpos to rend equals elements of array d starting from dpos to dpos+(rend-rpos).

Parameters:
r - The array containing the data that need to be matched in d.
rpos - The index of the first character in r to look for.
rend - The index of the last character in r to look for.
d - The array of char that should start from a part of r.
dpos - The starting offset in d for the matching.
Returns:
true if array d starts from portion of array r.