Class WildcardMatcherHelper

  extended by org.apache.wicket.application.WildcardMatcherHelper

public class WildcardMatcherHelper
extends Object

This class is an utility class that perform wildcard-patterns matching and isolation.

$Id: 420832 2006-07-11 13:11:02Z cziegeler $

Field Summary
static char ESC
          Escape character
static char PATHSEP
          Default path separator: "."
static char STAR
          any char
Constructor Summary
Method Summary
static Map<String,String> match(String pat, String str)
          Match a pattern against a string and isolates wildcard replacement into a Map.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final char ESC
Escape character

See Also:
Constant Field Values


public static final char PATHSEP
Default path separator: "."

See Also:
Constant Field Values


public static final char STAR
any char

See Also:
Constant Field Values
Constructor Detail


public WildcardMatcherHelper()
Method Detail


public static Map<String,String> match(String pat,
                                       String str)
Match a pattern against a string and isolates wildcard replacement into a Map.
Here is how the matching algorithm works:
When more than two '*' characters, not separated by another character, are found their value is considered as '**' and immediate succeeding '*' are skipped.
The '**' wildcard is greedy and thus the following sample cannot match:
STAR,STAR,PATHSEP,STAR,PATHSEP,STAR,STAR (why can't I express it literally?)
The first '**' in the pattern will suck up until the last '/' in string and thus will not match.
A more advance algorithm could certainly check whether there is an other literal later in the pattern to ev. match in string but I'll leave this exercise to someone else ATM if one needs such.

pat - The pattern string.
str - The string to math against the pattern
a Map containing the representation of the extracted pattern. The extracted patterns are keys in the Map from left to right beginning with "1" for the left most, "2" for the next, a.s.o. The key "0" is the string itself. If the return value is null, string does not match to the pattern .

Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.