Package com.jcabi.w3c

Interface Validator


  • public interface Validator
    Validator of CSS pages through W3C validation API.

    Retrieve it from ValidatorBuilder and use like this:

     HtmlValidator validator = new ValidatorBuilder().css();
     ValidationResponse response = validator.validate(text);
     if (!response.valid()) {
       // report about a problem
     }

    Sometimes this Jigsaw validator makes mistakes, sometimes you just need to use some IE-specific feature, which is not CSS compliant. In this case you may add comments to the document, at the end of every line you want to ignore during validation, for example:

     div.test {
       color: red;
       #position: 50%; /* JIGSAW: this is a IE_-related hack */
     }

    You can also instruct the validator to ingore the entire file, by means of adding JIGSAW IGNORE comment anywhere in the text, for example:

     /* JIGSAW IGNORE: it's an experimental file */
     div.test {
       something-totally-incorrect:...
     }

    Validation will happen anyway, but ValidationResponse.valid() will return TRUE. You will still be able to read errors and warnings from it, but it will be valid.

    Objects of this interface should be immutable and thread-safe.

    Since:
    0.1
    See Also:
    W3C API, CSS, ValidatorBuilder
    • Method Detail

      • validate

        ValidationResponse validate​(String content)
                             throws IOException
        Validate and return validation response.

        The method should never throw runtime exceptions, no matter what happened with the HTTP connection to the W3C server. It will return an invalid response, but will never throw.

        This method expects content of a document which should be validated, not URL to the document

        Parameters:
        content - The HTML/CSS content to validate
        Returns:
        The response
        Throws:
        IOException - If fails