void parseIf(String atRule) throws CSSException {
String predicate = atRule.substring(3, atRule.indexOf('{') - 1).trim();
String blockContents = atRule.substring(atRule.indexOf('{') + 1,
atRule.length() - 1);
CssIf cssIf = new CssIf();
if (predicate.startsWith("(") && predicate.endsWith(")")) {
cssIf.setExpression(predicate);
} else {
String[] predicateParts = predicate.split("\\s");
switch (predicateParts.length) {
case 0:
throw new CSSException(CSSException.SAC_SYNTAX_ERR,
"Incorrect format for @if predicate", null);
case 1:
if (predicateParts[0].length() == 0) {
throw new CSSException(CSSException.SAC_SYNTAX_ERR,
"Incorrect format for @if predicate", null);
}
errors.log(
TreeLogger.WARN,
"Deprecated syntax for Java expression detected. Enclose the expression in parentheses");
cssIf.setExpression(predicateParts[0]);
break;
default:
if (predicateParts[0].startsWith("!")) {
cssIf.setNegated(true);
cssIf.setProperty(predicateParts[0].substring(1));
} else {
cssIf.setProperty(predicateParts[0]);
}
String[] values = new String[predicateParts.length - 1];
System.arraycopy(predicateParts, 1, values, 0, values.length);
cssIf.setPropertyValues(values);
}
}
parseInnerStylesheet("@if", cssIf, blockContents);
}