use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createMediaQuery.
@Nonnull
@SuppressFBWarnings("IL_INFINITE_LOOP")
private CSSMediaQuery _createMediaQuery(@Nonnull final CSSNode aNode) {
if (ECSSNodeType.MEDIUM.isNode(aNode, m_eVersion)) {
// CSS 2.1 compatibility
final String sMedium = aNode.getText();
if (ECSSMedium.getFromNameOrNull(sMedium) == null)
m_aErrorHandler.onCSSInterpretationWarning("CSS " + m_eVersion.getVersionString() + " Media query uses unknown medium '" + sMedium + "'");
final CSSMediaQuery ret = new CSSMediaQuery(EModifier.NONE, sMedium);
ret.setSourceLocation(aNode.getSourceLocation());
return ret;
}
// CSS 3.0 media query
_expectNodeType(aNode, ECSSNodeType.MEDIAQUERY);
final int nChildCount = aNode.jjtGetNumChildren();
int nStartIndex = 0;
EModifier eModifier = EModifier.NONE;
// Check if a media modifier is present
if (nChildCount > 0) {
final CSSNode aFirstChildNode = aNode.jjtGetChild(0);
if (ECSSNodeType.MEDIAMODIFIER.isNode(aFirstChildNode, m_eVersion)) {
final String sMediaModifier = aFirstChildNode.getText();
// The "mediaModifier" token might be present, but without text!!!
if (sMediaModifier != null) {
if ("not".equalsIgnoreCase(sMediaModifier))
eModifier = EModifier.NOT;
else if ("only".equalsIgnoreCase(sMediaModifier))
eModifier = EModifier.ONLY;
else
m_aErrorHandler.onCSSInterpretationError("Unsupported media modifier '" + sMediaModifier + "' found!");
}
++nStartIndex;
}
}
// Next check if a medium is present
String sMedium = null;
if (nChildCount > nStartIndex) {
final CSSNode aNextChild = aNode.jjtGetChild(nStartIndex);
if (ECSSNodeType.MEDIUM.isNode(aNextChild, m_eVersion)) {
sMedium = aNextChild.getText();
if (ECSSMedium.getFromNameOrNull(sMedium) == null)
m_aErrorHandler.onCSSInterpretationWarning("CSS " + m_eVersion.getVersionString() + " media query uses unknown medium '" + sMedium + "'");
++nStartIndex;
}
}
final CSSMediaQuery ret = new CSSMediaQuery(eModifier, sMedium);
ret.setSourceLocation(aNode.getSourceLocation());
for (int i = nStartIndex; i < nChildCount; ++i) {
final CSSNode aChildNode = aNode.jjtGetChild(i);
if (ECSSNodeType.MEDIAEXPR.isNode(aChildNode, m_eVersion))
ret.addMediaExpression(_createMediaExpr(aChildNode));
else if (!ECSSNodeType.isErrorNode(aChildNode, m_eVersion))
m_aErrorHandler.onCSSInterpretationError("Unsupported media query 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 _createExpressionTerm.
@Nonnull
private ICSSExpressionMember _createExpressionTerm(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.EXPRTERM);
final int nChildCount = aNode.jjtGetNumChildren();
if (nChildCount > 1)
_throwUnexpectedChildrenCount(aNode, "Expected 0 or 1 children but got " + nChildCount + "!");
// Simple value
if (nChildCount == 0) {
final CSSExpressionMemberTermSimple ret = new CSSExpressionMemberTermSimple(aNode.getText());
ret.setSourceLocation(aNode.getSourceLocation());
return ret;
}
final CSSNode aChildNode = aNode.jjtGetChild(0);
if (ECSSNodeType.URL.isNode(aChildNode, m_eVersion)) {
// URI value
return _createExpressionURL(aChildNode);
} else if (ECSSNodeType.FUNCTION.isNode(aChildNode, m_eVersion)) {
// function value
return _createExpressionFunction(aChildNode);
} else if (ECSSNodeType.MATH.isNode(aChildNode, m_eVersion)) {
// Math value
return _createExpressionMathTerm(aChildNode);
} else if (ECSSNodeType.LINE_NAMES.isNode(aChildNode, m_eVersion)) {
// Math value
return _createExpressionLineNamesTerm(aChildNode);
} else
throw new IllegalStateException("Expected an expression term but got " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createExpressionMathTerm.
@Nonnull
private CSSExpressionMemberMath _createExpressionMathTerm(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.MATH);
final CSSExpressionMemberMath ret = new CSSExpressionMemberMath();
ret.setSourceLocation(aNode.getSourceLocation());
// read all sums
for (final CSSNode aChildNode : aNode) {
if (ECSSNodeType.MATHPRODUCT.isNode(aChildNode, m_eVersion)) {
ret.addMember(_createExpressionMathProduct(aChildNode));
} else if (ECSSNodeType.MATHSUMOPERATOR.isNode(aChildNode, m_eVersion)) {
final String sText = aChildNode.getText();
final ECSSMathOperator eMathOp = ECSSMathOperator.getFromNameOrNull(sText);
if (eMathOp == null)
m_aErrorHandler.onCSSInterpretationError("Failed to parse math operator '" + sText + "'");
else
ret.addMember(eMathOp);
} 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 _createMediaExpr.
@Nonnull
private CSSMediaExpression _createMediaExpr(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.MEDIAEXPR);
final int nChildCount = aNode.jjtGetNumChildren();
if (nChildCount != 1 && nChildCount != 2)
_throwUnexpectedChildrenCount(aNode, "Expected 1 or 2 children but got " + nChildCount + "!");
final CSSNode aFeatureNode = aNode.jjtGetChild(0);
if (!ECSSNodeType.MEDIAFEATURE.isNode(aFeatureNode, m_eVersion))
throw new IllegalStateException("Expected a media feature but got " + ECSSNodeType.getNodeName(aFeatureNode, m_eVersion));
final String sFeature = aFeatureNode.getText();
if (ECSSMediaExpressionFeature.getFromNameOrNull(sFeature) == null)
m_aErrorHandler.onCSSInterpretationWarning("Media expression uses unknown feature '" + sFeature + "'");
CSSMediaExpression ret;
if (nChildCount == 1) {
// Feature only
ret = new CSSMediaExpression(sFeature);
} else {
// Feature + value
final CSSNode aValueNode = aNode.jjtGetChild(1);
ret = new CSSMediaExpression(sFeature, _createExpression(aValueNode));
}
ret.setSourceLocation(aNode.getSourceLocation());
return ret;
}
use of com.helger.css.parser.CSSNode in project ph-css by phax.
the class CSSNodeToDomainObject method _createViewportRule.
@Nonnull
private CSSViewportRule _createViewportRule(@Nonnull final CSSNode aNode) {
_expectNodeType(aNode, ECSSNodeType.VIEWPORTRULE);
// Get the identifier (e.g. the default "@viewport" or the non-standard
// "@-ms-viewport")
final String sViewportDeclaration = aNode.getText();
final CSSViewportRule ret = new CSSViewportRule(sViewportDeclaration);
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 viewport rule child: " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
}
return ret;
}
Aggregations