use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createExpressionFunction.
@Nonnull
private CSSExpressionMemberFunction _createExpressionFunction(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.FUNCTION);
final int nChildCount = aNode.jjtGetNumChildren();
if (nChildCount > 1)
_throwUnexpectedChildrenCount(aNode, "Expected 0 or 1 children but got " + nChildCount + "!");
final String sFunctionName = aNode.getText();
CSSExpressionMemberFunction aFunc;
if (nChildCount == 1) {
// Parameters present
final CSSNode aFirstChild = aNode.jjtGetChild(0);
final CSSExpression aFuncExpr = _createExpression(aFirstChild);
aFunc = new CSSExpressionMemberFunction(sFunctionName, aFuncExpr);
} else {
// No parameters
aFunc = new CSSExpressionMemberFunction(sFunctionName);
}
aFunc.setSourceLocation(aNode.getSourceLocation());
return aFunc;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createImportRule.
@Nonnull
private CSSImportRule _createImportRule(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.IMPORTRULE);
final int nChildCount = aNode.jjtGetNumChildren();
if (nChildCount > 2)
_throwUnexpectedChildrenCount(aNode, "Expected at last 2 children but got " + nChildCount + "!");
CSSURI aImportURI = null;
int nCurrentIndex = 0;
if (nChildCount > 0) {
final CSSNode aURINode = aNode.jjtGetChild(0);
if (ECSSNodeType.URL.isNode(aURINode, m_eVersion)) {
aImportURI = new CSSURI(aURINode.getText());
aImportURI.setSourceLocation(aURINode.getSourceLocation());
++nCurrentIndex;
} else if (!ECSSNodeType.MEDIALIST.isNode(aURINode, m_eVersion))
throw new IllegalStateException("Expected an URI or MEDIALIST node but got " + ECSSNodeType.getNodeName(aURINode, m_eVersion));
}
if (aImportURI == null) {
// No URI child node present, so the location is printed directly
// E.g. @import "abc.css"
aImportURI = new CSSURI(CSSParseHelper.extractStringValue(aNode.getText()));
}
// Import rule
final CSSImportRule ret = new CSSImportRule(aImportURI);
ret.setSourceLocation(aNode.getSourceLocation());
if (nChildCount > nCurrentIndex) {
// We have a media query present!
final CSSNode aMediaListNode = aNode.jjtGetChild(nCurrentIndex);
if (ECSSNodeType.MEDIALIST.isNode(aMediaListNode, m_eVersion)) {
for (final CSSNode aMediaQueryNode : aMediaListNode) {
ret.addMediaQuery(_createMediaQuery(aMediaQueryNode));
}
++nCurrentIndex;
} else
m_aErrorHandler.onCSSInterpretationError("Expected an MEDIALIST node but got " + ECSSNodeType.getNodeName(aMediaListNode, m_eVersion));
}
if (nCurrentIndex < nChildCount)
m_aErrorHandler.onCSSInterpretationError("Import statement has children which are unhandled.");
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createStyleRule.
@Nullable
private CSSStyleRule _createStyleRule(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.STYLERULE);
final CSSStyleRule ret = new CSSStyleRule();
ret.setSourceLocation(aNode.getSourceLocation());
boolean bSelectors = true;
for (final CSSNode aChildNode : aNode) {
if (ECSSNodeType.SELECTOR.isNode(aChildNode, m_eVersion)) {
if (!bSelectors)
m_aErrorHandler.onCSSInterpretationError("Found a selector after a declaration!");
ret.addSelector(_createSelector(aChildNode));
} else {
// OK, we're after the selectors
bSelectors = false;
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 child of " + ECSSNodeType.getNodeName(aNode, m_eVersion) + ": " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
}
}
if (ret.getSelectorCount() == 0) {
// Error in selector parsing in browser compliant mode
return null;
}
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createSupportsRule.
@Nonnull
private CSSSupportsRule _createSupportsRule(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.SUPPORTSRULE);
final CSSSupportsRule ret = new CSSSupportsRule();
ret.setSourceLocation(aNode.getSourceLocation());
for (final CSSNode aChildNode : aNode) {
if (ECSSNodeType.SUPPORTSCONDITION.isNode(aChildNode, m_eVersion)) {
for (final CSSNode aChildChildNode : aChildNode) {
final ICSSSupportsConditionMember aMember = _createSupportsConditionMemberRecursive(aChildChildNode);
if (aMember != null)
ret.addSupportConditionMember(aMember);
}
} else if (ECSSNodeType.STYLERULE.isNode(aChildNode, m_eVersion)) {
final CSSStyleRule aStyleRule = _createStyleRule(aChildNode);
if (aStyleRule != null)
ret.addRule(aStyleRule);
} else if (ECSSNodeType.MEDIARULE.isNode(aChildNode, m_eVersion))
ret.addRule(_createMediaRule(aChildNode));
else if (ECSSNodeType.PAGERULE.isNode(aChildNode, m_eVersion))
ret.addRule(_createPageRule(aChildNode));
else if (ECSSNodeType.FONTFACERULE.isNode(aChildNode, m_eVersion))
ret.addRule(_createFontFaceRule(aChildNode));
else if (ECSSNodeType.KEYFRAMESRULE.isNode(aChildNode, m_eVersion))
ret.addRule(_createKeyframesRule(aChildNode));
else if (ECSSNodeType.VIEWPORTRULE.isNode(aChildNode, m_eVersion))
ret.addRule(_createViewportRule(aChildNode));
else if (ECSSNodeType.SUPPORTSRULE.isNode(aChildNode, m_eVersion))
ret.addRule(_createSupportsRule(aChildNode));
else if (!ECSSNodeType.isErrorNode(aChildNode, m_eVersion))
m_aErrorHandler.onCSSInterpretationError("Unsupported supports-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 _createUnknownRule.
@Nonnull
private CSSUnknownRule _createUnknownRule(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.UNKNOWNRULE);
final int nChildCount = aNode.jjtGetNumChildren();
if (nChildCount != 2)
_throwUnexpectedChildrenCount(aNode, "Expected 2 children but got " + nChildCount + "!");
final CSSNode aParameterList = aNode.jjtGetChild(0);
_expectNodeType(aParameterList, ECSSNodeType.UNKNOWNRULEPARAMETERLIST);
final CSSNode aBody = aNode.jjtGetChild(1);
_expectNodeType(aBody, ECSSNodeType.UNKNOWNRULEBODY);
// Get the name of the rule
final String sRuleDeclaration = aNode.getText();
final CSSUnknownRule ret = new CSSUnknownRule(sRuleDeclaration);
ret.setSourceLocation(aNode.getSourceLocation());
ret.setParameterList(aParameterList.getText());
ret.setBody(aBody.getText());
return ret;
}
Aggregations