if (type == ANCHOR_VAR) {
Map levelResult = context.getMapByAnchor(module.getStringValue());
if (levelResult == null) {
throw new PatternException("Error while evaluating '" + this.originalExpr +
"' : no anchor '" + String.valueOf(module.getStringValue()) + "' found in context");
}
Object result = levelResult.get(expr.getStringValue());
return new Token(EXPR, result==null ? "" : result.toString());
} else if (type == THREADSAFE_MODULE) {
try {
InputModule im = module.getModule();
Object result = im.getAttribute(expr.getStringValue(), null, objectModel);
return new Token(EXPR, result==null ? "" : result.toString());
} catch(ConfigurationException confEx) {
throw new PatternException("Cannot get variable '" + expr.getStringValue() +
"' in expression '" + this.originalExpr + "'", confEx);
}
} else if (type == STATEFUL_MODULE) {
InputModule im = null;
String moduleName = module.getStringValue();
try {
im = (InputModule) this.selector.select(moduleName);
Object result = im.getAttribute(expr.getStringValue(), null, objectModel);
return new Token(EXPR, result==null ? "" : result.toString());
} catch(ServiceException e) {
throw new PatternException("Cannot get module '" + moduleName +
"' in expression '" + this.originalExpr + "'", e);
} catch(ConfigurationException confEx) {
throw new PatternException("Cannot get variable '" + expr.getStringValue() +
"' in expression '" + this.originalExpr + "'", confEx);
} finally {
this.selector.release(im);
}
} else if (type == SITEMAP_VAR) {
// Prefixed sitemap variable must be parsed at runtime
String variable = expr.getStringValue();
Token token;
if (variable.startsWith("/")) {
token = new Token(ROOT_SITEMAP_VARIABLE, variable.substring(1));
} else {
// Find level
int level = 1; // Start at 1 since it will be substracted from list.size()
int pos = 0;
while (variable.startsWith("../", pos)) {
level++;
pos += "../".length();
}
token = new Token(level, variable.substring(pos));
}
return processVariable(token, mapStack, stackSize);
} else {
throw new PatternException("Unknown token type: " + expr.getType());
}
}