use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createDeclaration.
@Nullable
private CSSDeclaration _createDeclaration(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.STYLEDECLARATION);
final int nChildCount = aNode.jjtGetNumChildren();
if (nChildCount < 1 || nChildCount > 3)
_throwUnexpectedChildrenCount(aNode, "Expected 1-3 children but got " + nChildCount + "!");
if (nChildCount == 1) {
// Syntax error. E.g. "color:;"
return null;
}
if (!ECSSNodeType.EXPR.isNode(aNode.jjtGetChild(1), m_eVersion)) {
// Syntax error. E.g. "color: !important;"
return null;
}
final String sProperty = aNode.jjtGetChild(0).getText();
final CSSExpression aExpression = _createExpression(aNode.jjtGetChild(1));
boolean bImportant = false;
if (nChildCount == 3) {
// Must be an "!important" node
final CSSNode aChildNode = aNode.jjtGetChild(2);
if (ECSSNodeType.IMPORTANT.isNode(aChildNode, m_eVersion))
bImportant = true;
else
m_aErrorHandler.onCSSInterpretationError("Expected an " + ECSSNodeType.IMPORTANT.getNodeName(m_eVersion) + " token but got a " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
}
final CSSDeclaration ret = new CSSDeclaration(sProperty, aExpression, bImportant);
ret.setSourceLocation(aNode.getSourceLocation());
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createExpression.
@Nonnull
private CSSExpression _createExpression(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.EXPR);
final CSSExpression ret = new CSSExpression();
ret.setSourceLocation(aNode.getSourceLocation());
for (final CSSNode aChildNode : aNode) {
if (ECSSNodeType.EXPRTERM.isNode(aChildNode, m_eVersion))
ret.addMember(_createExpressionTerm(aChildNode));
else if (ECSSNodeType.EXPROPERATOR.isNode(aChildNode, m_eVersion)) {
final String sText = aChildNode.getText();
final ECSSExpressionOperator eOp = ECSSExpressionOperator.getFromNameOrNull(sText);
if (eOp == null)
m_aErrorHandler.onCSSInterpretationError("Failed to parse expression operator '" + sText + "'");
else
ret.addMember(eOp);
} else {
m_aErrorHandler.onCSSInterpretationError("Unsupported child of " + ECSSNodeType.getNodeName(aNode, m_eVersion) + ": " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
}
}
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createSelector.
@Nonnull
private CSSSelector _createSelector(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.SELECTOR);
final CSSSelector ret = new CSSSelector();
ret.setSourceLocation(aNode.getSourceLocation());
for (final CSSNode aChildNode : aNode) {
final ICSSSelectorMember aMember = _createSelectorMember(aChildNode);
if (aMember != null)
ret.addMember(aMember);
}
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createFontFaceRule.
@Nonnull
private CSSFontFaceRule _createFontFaceRule(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.FONTFACERULE);
final String sFontFaceDeclaration = aNode.getText();
final CSSFontFaceRule ret = new CSSFontFaceRule(sFontFaceDeclaration);
ret.setSourceLocation(aNode.getSourceLocation());
for (final CSSNode aChildNode : aNode) {
if (ECSSNodeType.STYLEDECLARATIONLIST.isNode(aChildNode, m_eVersion)) {
// Read all contained declarations
_readStyleDeclarationList(aChildNode, aDeclaration -> ret.addDeclaration(aDeclaration));
} else if (!ECSSNodeType.isErrorNode(aChildNode, m_eVersion))
m_aErrorHandler.onCSSInterpretationError("Unsupported font-face rule child: " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
}
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createSupportsConditionMemberRecursive.
@Nullable
private ICSSSupportsConditionMember _createSupportsConditionMemberRecursive(@Nonnull final CSSNode aNode) {
final int nChildCount = aNode.jjtGetNumChildren();
if (ECSSNodeType.SUPPORTSCONDITIONOPERATOR.isNode(aNode, m_eVersion)) {
if (nChildCount != 0)
_throwUnexpectedChildrenCount(aNode, "Expected no children but got " + nChildCount + "!");
return ECSSSupportsConditionOperator.getFromNameCaseInsensitiveOrNull(aNode.getText());
}
if (ECSSNodeType.SUPPORTSNEGATION.isNode(aNode, m_eVersion)) {
if (nChildCount != 1)
_throwUnexpectedChildrenCount(aNode, "Expected at exactly 1 child but got " + nChildCount + "!");
final ICSSSupportsConditionMember aNestedMember = _createSupportsConditionMemberRecursive(aNode.jjtGetChild(0));
if (aNestedMember == null)
return null;
final CSSSupportsConditionNegation ret = new CSSSupportsConditionNegation(aNestedMember);
ret.setSourceLocation(aNode.getSourceLocation());
return ret;
}
if (ECSSNodeType.SUPPORTSCONDITIONINPARENS.isNode(aNode, m_eVersion)) {
if (nChildCount != 1)
_throwUnexpectedChildrenCount(aNode, "Expected at exactly 1 child but got " + nChildCount + "!");
final CSSNode aChildNode = aNode.jjtGetChild(0);
if (ECSSNodeType.STYLEDECLARATION.isNode(aChildNode, m_eVersion)) {
final CSSDeclaration aDeclaration = _createDeclaration(aChildNode);
if (aDeclaration == null)
throw new CSSHandlingException(aChildNode, "The style declaration in the @supports rule is invalid!");
final CSSSupportsConditionDeclaration ret = new CSSSupportsConditionDeclaration(aDeclaration);
ret.setSourceLocation(aNode.getSourceLocation());
return ret;
}
if (ECSSNodeType.SUPPORTSCONDITION.isNode(aChildNode, m_eVersion)) {
final CSSSupportsConditionNested ret = new CSSSupportsConditionNested();
for (final CSSNode aChildChildNode : aChildNode) {
final ICSSSupportsConditionMember aMember = _createSupportsConditionMemberRecursive(aChildChildNode);
if (aMember != null)
ret.addMember(aMember);
}
return ret;
}
m_aErrorHandler.onCSSInterpretationError("Unsupported supportsConditionInParents child: " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
return null;
}
if (!ECSSNodeType.isErrorNode(aNode, m_eVersion))
m_aErrorHandler.onCSSInterpretationError("Unsupported supports-condition child: " + ECSSNodeType.getNodeName(aNode, m_eVersion));
return null;
}
Aggregations