protected void checkAngleType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_DEG && value.getPrimitiveType() != CSSPrimitiveValue.CSS_RAD && value.getPrimitiveType() != CSSPrimitiveValue.CSS_GRAD) { throw new CSSParseException("Value for " + cssName + "must be an angle (degrees, radians or grads)", -1); } }
protected void checkIdentOrColorType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_RGBCOLOR) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a color", -1); } }
protected void checkIdentOrNumberType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_NUMBER) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a length", -1); } }
protected void checkNumberType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_NUMBER) { throw new CSSParseException("Value for " + cssName + " must be a number", -1); } }
protected void checkStringType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_STRING) { throw new CSSParseException("Value for " + cssName + " must be a string", -1); } }
protected void checkIdentType(CSSName cssName, CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_IDENT) { throw new CSSParseException("Value for " + cssName + " must be an identifier", -1); } }
protected void checkIdentOrURIType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_URI) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a URI", -1); } }
protected void checkIdentOrString(CSSName cssName, CSSPrimitiveValue value) { short type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_STRING && type != CSSPrimitiveValue.CSS_IDENT) { throw new CSSParseException("Value for " + cssName + " must be an identifier or string", -1); } }
protected boolean isLength(CSSPrimitiveValue value) { int unit = value.getPrimitiveType(); return unit == CSSPrimitiveValue.CSS_EMS || unit == CSSPrimitiveValue.CSS_EXS || unit == CSSPrimitiveValue.CSS_PX || unit == CSSPrimitiveValue.CSS_IN || unit == CSSPrimitiveValue.CSS_CM || unit == CSSPrimitiveValue.CSS_MM || unit == CSSPrimitiveValue.CSS_PT || unit == CSSPrimitiveValue.CSS_PC || (unit == CSSPrimitiveValue.CSS_NUMBER && value.getFloatValue(CSSPrimitiveValue.CSS_IN) == 0.0f); }
/** * Returns true if the specified value was absolute (even if we have a * computed value for it), meaning that either the value can be used * directly (e.g. pixels) or there is a fixed context-independent conversion * for it (e.g. inches). Proportional types (e.g. %) return false. * * @param primitive The CSSValue instance to check. * @return See desc. */ //TODO: method may be unnecessary (tobe) public static boolean isAbsoluteUnit(CSSPrimitiveValue primitive) { short type = 0; type = ((CSSPrimitiveValue) primitive).getPrimitiveType(); return isAbsoluteUnit(type); }
private boolean isBorderStyle(CSSPrimitiveValue value) { if (value.getPrimitiveType() != CSSPrimitiveValue.CSS_IDENT) { return false; } IdentValue ident = IdentValue.valueOf(value.getCssText()); if (ident == null) { return false; } return PrimitivePropertyBuilders.BORDER_STYLES.get(ident.FS_ID); }
protected void checkIdentOrLengthType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && ! isLength(value)) { throw new CSSParseException("Value for " + cssName + " must be an identifier or a length", -1); } }
protected void checkIdentLengthNumberOrPercentType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && ! isLength(value) && type != CSSPrimitiveValue.CSS_PERCENTAGE && type != CSSPrimitiveValue.CSS_NUMBER) { throw new CSSParseException("Value for " + cssName + " must be an identifier, length, or percentage", -1); } }
protected void checkIdentOrIntegerType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if ((type != CSSPrimitiveValue.CSS_IDENT && type != CSSPrimitiveValue.CSS_NUMBER) || (type == CSSPrimitiveValue.CSS_NUMBER && (int)value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) != Math.round(value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)))) { throw new CSSParseException("Value for " + cssName + " must be an identifier or an integer", -1); } }
protected void checkIdentLengthOrPercentType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_IDENT && ! isLength(value) && type != CSSPrimitiveValue.CSS_PERCENTAGE) { throw new CSSParseException("Value for " + cssName + " must be an identifier, length, or percentage", -1); } }
protected void checkLengthOrPercentType(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (! isLength(value) && type != CSSPrimitiveValue.CSS_PERCENTAGE) { throw new CSSParseException("Value for " + cssName + " must be a length or percentage", -1); } }
protected void checkInteger(CSSName cssName, CSSPrimitiveValue value) { int type = value.getPrimitiveType(); if (type != CSSPrimitiveValue.CSS_NUMBER || (type == CSSPrimitiveValue.CSS_NUMBER && (int)value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) != Math.round(value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)))) { throw new CSSParseException("Value for " + cssName + " must be an integer", -1); } }
public List buildDeclarations( CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); CSSPrimitiveValue value = (CSSPrimitiveValue)values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSPrimitiveValue.CSS_INHERIT) { checkIdentOrURIType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, ALLOWED, ident); } } return Collections.singletonList( new PropertyDeclaration(cssName, value, important, origin)); } }
public List buildDeclarations( CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); CSSPrimitiveValue value = (CSSPrimitiveValue)values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSPrimitiveValue.CSS_INHERIT) { checkIdentOrIntegerType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, ALLOWED, ident); } } return Collections.singletonList( new PropertyDeclaration(cssName, value, important, origin)); } }
@Override public List buildDeclarations( CSSName cssName, List values, int origin, boolean important, boolean inheritAllowed) { checkValueCount(cssName, 1, values.size()); CSSPrimitiveValue value = (CSSPrimitiveValue)values.get(0); checkInheritAllowed(value, inheritAllowed); if (value.getCssValueType() != CSSPrimitiveValue.CSS_INHERIT) { checkIdentOrIntegerType(cssName, value); if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { IdentValue ident = checkIdent(cssName, value); checkValidity(cssName, ALLOWED, ident); } else if (value.getFloatValue(CSSPrimitiveValue.CSS_NUMBER) < 1) { throw new CSSParseException("column-count must be one or greater", -1); } } return Collections.singletonList( new PropertyDeclaration(cssName, value, important, origin)); } }