throw new TemplateProcessingException(
"Cannot specify a \"" + attributeName + "\" attribute in an environment where no " +
"switch operator has been defined before.");
}
final SwitchStructure switchStructure =
(SwitchStructure) arguments.getLocalVariable(AbstractStandardSwitchStructureAttrProcessor.SWITCH_VARIABLE_NAME);
if (switchStructure.isExecuted()) {
return false;
}
final String attributeValue = element.getAttributeValue(attributeName);
if (attributeValue != null && attributeValue.trim().equals(CASE_DEFAULT_ATTRIBUTE_VALUE)) {
if (this.logger.isTraceEnabled()) {
this.logger.trace("[THYMELEAF][{}][{}] Case expression \"{}\" in attribute \"{}\" has been evaluated as: \"{}\"",
new Object[] {TemplateEngine.threadIndex(), arguments.getTemplateName(), attributeValue, attributeName, attributeValue, Boolean.TRUE});
}
switchStructure.setExecuted(true);
return true;
}
final Configuration configuration = arguments.getConfiguration();
final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);
final IStandardExpression caseExpression = expressionParser.parseExpression(configuration, arguments, attributeValue);
final EqualsExpression equalsExpression = new EqualsExpression(switchStructure.getExpression(), caseExpression);
final Object value = equalsExpression.execute(configuration, arguments);
final boolean visible = EvaluationUtil.evaluateAsBoolean(value);
if (this.logger.isTraceEnabled()) {
this.logger.trace("[THYMELEAF][{}][{}] Case expression \"{}\" in attribute \"{}\" has been evaluated as: \"{}\"",
new Object[] {TemplateEngine.threadIndex(), arguments.getTemplateName(), attributeValue, attributeName, attributeValue, Boolean.valueOf(visible)});
}
if (visible) {
switchStructure.setExecuted(true);
}
return visible;
}