in core/src/main/java/org/apache/struts2/util/WildcardHelper.java [166:289]
public boolean match(Map<String, String> map, String data, int[] expr) {
if (map == null) {
throw new NullPointerException("No map provided");
}
if (data == null) {
throw new NullPointerException("No data provided");
}
if (expr == null) {
throw new NullPointerException("No pattern expression provided");
}
char[] buff = data.toCharArray();
// Allocate the result buffer
char[] rslt = new char[expr.length + buff.length];
// The previous and current position of the expression character
// (MATCH_*)
int charpos = 0;
// The position in the expression, input, translation and result arrays
int exprpos = 0;
int buffpos = 0;
int rsltpos = 0;
int offset = -1;
// The matching count
int mcount = 0;
// We want the complete data be in {0}
map.put(Integer.toString(mcount), data);
// First check for MATCH_BEGIN
boolean matchBegin = false;
if (expr[charpos] == MATCH_BEGIN) {
matchBegin = true;
exprpos = ++charpos;
}
// Search the fist expression character (except MATCH_BEGIN - already
// skipped)
while (expr[charpos] >= 0) {
charpos++;
}
// The expression charater (MATCH_*)
int exprchr = expr[charpos];
while (true) {
// Check if the data in the expression array before the current
// expression character matches the data in the input buffer
if (matchBegin) {
if (!matchArray(expr, exprpos, charpos, buff, buffpos)) {
return (false);
}
matchBegin = false;
} else {
offset = indexOfArray(expr, exprpos, charpos, buff, buffpos);
if (offset < 0) {
return (false);
}
}
// Advance buffpos
buffpos += (charpos - exprpos);
// Check for END's
if (exprchr == MATCH_END) {
// Don't care about rest of input buffer
return (true);
} else if (exprchr == MATCH_THEEND) {
// Check that we reach buffer's end
return (buffpos == buff.length);
}
// Search the next expression character
exprpos = ++charpos;
while (expr[charpos] >= 0) {
charpos++;
}
int prevchr = exprchr;
exprchr = expr[charpos];
// We have here prevchr == * or **.
offset =
(prevchr == MATCH_FILE)
? indexOfArray(expr, exprpos, charpos, buff, buffpos)
: lastIndexOfArray(expr, exprpos, charpos, buff, buffpos);
if (offset < 0) {
return (false);
}
// Copy the data from the source buffer into the result buffer
// to substitute the expression character
if (prevchr == MATCH_PATH) {
while (buffpos < offset) {
rslt[rsltpos++] = buff[buffpos++];
}
} else {
// Matching file, don't copy '/'
while (buffpos < offset) {
if (buff[buffpos] == '/') {
return (false);
}
rslt[rsltpos++] = buff[buffpos++];
}
}
map.put(Integer.toString(++mcount), new String(rslt, 0, rsltpos));
rsltpos = 0;
}
}