/// <summary> Determines whether the given property (both name and value) are valid /// according to this validator's policy. /// /// </summary> /// <param name="name">the name of the property /// </param> /// <param name="lu">the value of the property /// </param> /// <returns> true if this property name/value is valid; false otherwise /// </returns> public virtual bool isValidProperty(string name, LexicalUnit lu) { bool isValid = false; Property property = null; if (name != null) { property = policy.getPropertyByName(name.ToLower()); } // if we were able to find the property by name, validate the value if (property != null) { // validate all values attached to this property isValid = true; while (lu != null) { System.String value_Renamed = lexicalValueToString(lu); if (value_Renamed == null || !validateValue(property, value_Renamed)) { isValid = false; break; } lu = lu.getNextLexicalUnit(); } } return(isValid); }
/// <summary> Converts the given lexical unit to a <code>String</code> /// representation. This method does not perform any validation - it is meant /// to be used in conjunction with the validator/logging methods. /// /// </summary> /// <param name="lu">the lexical unit to convert /// </param> /// <returns> a <code>String</code> representation of the given lexical unit /// </returns> public virtual System.String lexicalValueToString(LexicalUnit lu) { switch (lu.getLexicalUnitType()) { case CssValidator.SAC_PERCENTAGE: case CssValidator.SAC_DIMENSION: case CssValidator.SAC_EM: case CssValidator.SAC_EX: case CssValidator.SAC_PIXEL: case CssValidator.SAC_INCH: case CssValidator.SAC_CENTIMETER: case CssValidator.SAC_MILLIMETER: case CssValidator.SAC_POINT: case CssValidator.SAC_PICA: case CssValidator.SAC_DEGREE: case CssValidator.SAC_GRADIAN: case CssValidator.SAC_RADIAN: case CssValidator.SAC_MILLISECOND: case CssValidator.SAC_SECOND: case CssValidator.SAC_HERTZ: case CssValidator.SAC_KILOHERTZ: // these are all measurements return lu.getFloatValue() + lu.getDimensionUnitText(); case CssValidator.SAC_INTEGER: // just a number return System.Convert.ToString(lu.getIntegerValue()); case CssValidator.SAC_REAL: // just a number return System.Convert.ToString(lu.getFloatValue()); case CssValidator.SAC_STRING_VALUE: case CssValidator.SAC_IDENT: // just a string/identifier return lu.getStringValue(); case CssValidator.SAC_URI: // this is a URL return "url(" + lu.getStringValue() + ")"; case CssValidator.SAC_RGBCOLOR: // this is a rgb encoded color System.Text.StringBuilder sb = new System.Text.StringBuilder("rgb("); LexicalUnit param = lu.getParameters(); sb.Append(param.getIntegerValue()); // R value sb.Append(','); param = param.getNextLexicalUnit(); // comma param = param.getNextLexicalUnit(); // G value sb.Append(param.getIntegerValue()); sb.Append(','); param = param.getNextLexicalUnit(); // comma param = param.getNextLexicalUnit(); // B value sb.Append(param.getIntegerValue()); sb.Append(')'); return sb.ToString(); case CssValidator.SAC_INHERIT: // constant return "inherit"; case CssValidator.SAC_ATTR: case CssValidator.SAC_COUNTER_FUNCTION: case CssValidator.SAC_COUNTERS_FUNCTION: case CssValidator.SAC_FUNCTION: case CssValidator.SAC_RECT_FUNCTION: case CssValidator.SAC_SUB_EXPRESSION: case CssValidator.SAC_UNICODERANGE: default: // these are properties that shouldn't be necessary for most run // of the mill HTML/CSS return null; } }
/// <summary> Determines whether the given property (both name and value) are valid /// according to this validator's policy. /// /// </summary> /// <param name="name">the name of the property /// </param> /// <param name="lu">the value of the property /// </param> /// <returns> true if this property name/value is valid; false otherwise /// </returns> public virtual bool isValidProperty(string name, LexicalUnit lu) { bool isValid = false; Property property = null; if (name != null) { property = policy.getPropertyByName(name.ToLower()); } // if we were able to find the property by name, validate the value if (property != null) { // validate all values attached to this property isValid = true; while (lu != null) { System.String value_Renamed = lexicalValueToString(lu); if (value_Renamed == null || !validateValue(property, value_Renamed)) { isValid = false; break; } lu = lu.getNextLexicalUnit(); } } return isValid; }
/// <summary> Converts the given lexical unit to a <code>String</code> /// representation. This method does not perform any validation - it is meant /// to be used in conjunction with the validator/logging methods. /// /// </summary> /// <param name="lu">the lexical unit to convert /// </param> /// <returns> a <code>String</code> representation of the given lexical unit /// </returns> public virtual System.String lexicalValueToString(LexicalUnit lu) { switch (lu.getLexicalUnitType()) { case CssValidator.SAC_PERCENTAGE: case CssValidator.SAC_DIMENSION: case CssValidator.SAC_EM: case CssValidator.SAC_EX: case CssValidator.SAC_PIXEL: case CssValidator.SAC_INCH: case CssValidator.SAC_CENTIMETER: case CssValidator.SAC_MILLIMETER: case CssValidator.SAC_POINT: case CssValidator.SAC_PICA: case CssValidator.SAC_DEGREE: case CssValidator.SAC_GRADIAN: case CssValidator.SAC_RADIAN: case CssValidator.SAC_MILLISECOND: case CssValidator.SAC_SECOND: case CssValidator.SAC_HERTZ: case CssValidator.SAC_KILOHERTZ: // these are all measurements return(lu.getFloatValue() + lu.getDimensionUnitText()); case CssValidator.SAC_INTEGER: // just a number return(System.Convert.ToString(lu.getIntegerValue())); case CssValidator.SAC_REAL: // just a number return(System.Convert.ToString(lu.getFloatValue())); case CssValidator.SAC_STRING_VALUE: case CssValidator.SAC_IDENT: // just a string/identifier return(lu.getStringValue()); case CssValidator.SAC_URI: // this is a URL return("url(" + lu.getStringValue() + ")"); case CssValidator.SAC_RGBCOLOR: // this is a rgb encoded color System.Text.StringBuilder sb = new System.Text.StringBuilder("rgb("); LexicalUnit param = lu.getParameters(); sb.Append(param.getIntegerValue()); // R value sb.Append(','); param = param.getNextLexicalUnit(); // comma param = param.getNextLexicalUnit(); // G value sb.Append(param.getIntegerValue()); sb.Append(','); param = param.getNextLexicalUnit(); // comma param = param.getNextLexicalUnit(); // B value sb.Append(param.getIntegerValue()); sb.Append(')'); return(sb.ToString()); case CssValidator.SAC_INHERIT: // constant return("inherit"); case CssValidator.SAC_ATTR: case CssValidator.SAC_COUNTER_FUNCTION: case CssValidator.SAC_COUNTERS_FUNCTION: case CssValidator.SAC_FUNCTION: case CssValidator.SAC_RECT_FUNCTION: case CssValidator.SAC_SUB_EXPRESSION: case CssValidator.SAC_UNICODERANGE: default: // these are properties that shouldn't be necessary for most run // of the mill HTML/CSS return(null); } }