in plugins/tiles/src/main/java/org/apache/tiles/core/util/WildcardHelper.java [178:315]
public List<String> match(String data, int[] expr) {
List<String> varsValues = null;
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;
// 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 null;
}
matchBegin = false;
} else {
offset = indexOfArray(expr, exprpos, charpos, buff, buffpos);
if (offset < 0) {
return null;
}
}
// Check for MATCH_BEGIN
if (matchBegin) {
if (offset != 0) {
return null;
}
matchBegin = false;
}
// Advance buffpos
buffpos += (charpos - exprpos);
// Check for END's
if (exprchr == MATCH_END) {
if (rsltpos > 0) {
varsValues = addAndCreateList(varsValues, new String(rslt,
0, rsltpos));
}
// Don't care about rest of input buffer
varsValues = addElementOnTop(varsValues, data);
return varsValues;
} else if (exprchr == MATCH_THEEND) {
if (rsltpos > 0) {
varsValues = addAndCreateList(varsValues, new String(rslt,
0, rsltpos));
}
// Check that we reach buffer's end
if (buffpos == buff.length) {
addElementOnTop(varsValues, data);
return varsValues;
}
return null;
}
// 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 null;
}
// 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 null;
}
rslt[rsltpos++] = buff[buffpos++];
}
}
varsValues = addAndCreateList(varsValues, new String(rslt, 0,
rsltpos));
rsltpos = 0;
}
}