Search in sources :

Example 1 with CombineValidator

use of com.thaiopensource.relaxng.impl.CombineValidator in project validator by validator.

the class VerifierServletTransaction method validatorByUrls.

/**
 * @param validator
 * @return
 * @throws SAXException
 * @throws IOException
 * @throws IncorrectSchemaException
 */
private Validator validatorByUrls(String schemaList) throws SAXException, IOException, IncorrectSchemaException {
    System.setProperty("nu.validator.schema.rdfa-full", "0");
    schemaListForStats = schemaList;
    Validator v = null;
    String[] schemas = SPACE.split(schemaList);
    for (int i = schemas.length - 1; i > -1; i--) {
        String url = schemas[i];
        if ("http://s.validator.nu/html5-all.rnc".equals(url)) {
            System.setProperty("nu.validator.schema.rdfa-full", "1");
        }
        if ("http://c.validator.nu/all/".equals(url) || "http://hsivonen.iki.fi/checkers/all/".equals(url)) {
            for (String checker : ALL_CHECKERS) {
                v = combineValidatorByUrl(v, checker);
            }
        } else if ("http://c.validator.nu/all-html4/".equals(url) || "http://hsivonen.iki.fi/checkers/all-html4/".equals(url)) {
            for (String checker : ALL_CHECKERS_HTML4) {
                v = combineValidatorByUrl(v, checker);
            }
        } else {
            v = combineValidatorByUrl(v, url);
        }
    }
    if (imageCollector != null && v != null) {
        v = new CombineValidator(imageCollector, v);
    }
    return v;
}
Also used : CombineValidator(com.thaiopensource.relaxng.impl.CombineValidator) Validator(com.thaiopensource.validate.Validator) CombineValidator(com.thaiopensource.relaxng.impl.CombineValidator)

Example 2 with CombineValidator

use of com.thaiopensource.relaxng.impl.CombineValidator in project validator by validator.

the class ValidationWorker method setupValidator.

private Validator setupValidator(Set<Schema> schemas) {
    PropertyMapBuilder builder = new PropertyMapBuilder();
    builder.put(ValidateProperty.ERROR_HANDLER, new ErrorHandler() {

        public void error(SAXParseException exception) throws SAXException {
            validationErrors.add(replaceSpecificValues(exception.getMessage()));
        }

        public void fatalError(SAXParseException exception) throws SAXException {
            // should not happen
            validationErrors.add(replaceSpecificValues(exception.getMessage()));
        }

        public void warning(SAXParseException exception) throws SAXException {
        }
    });
    PropertyMap map = builder.toPropertyMap();
    Validator rv = null;
    for (Schema schema : schemas) {
        Validator v = schema.createValidator(map);
        if (rv == null) {
            rv = v;
        } else {
            rv = new CombineValidator(rv, v);
        }
    }
    return rv;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) PropertyMap(com.thaiopensource.util.PropertyMap) SAXParseException(org.xml.sax.SAXParseException) Schema(com.thaiopensource.validate.Schema) CheckerSchema(org.whattf.checker.jing.CheckerSchema) PropertyMapBuilder(com.thaiopensource.util.PropertyMapBuilder) CombineValidator(com.thaiopensource.relaxng.impl.CombineValidator) Validator(com.thaiopensource.validate.Validator) CombineValidator(com.thaiopensource.relaxng.impl.CombineValidator) SAXException(org.xml.sax.SAXException)

Example 3 with CombineValidator

use of com.thaiopensource.relaxng.impl.CombineValidator in project validator by validator.

the class SimpleDocumentValidator method setUpValidatorAndParsers.

/* *
     * Prepares a Validator instance along with HTML and XML parsers, and then
     * attaches the Validator instance and supplied ErrorHandler instance to the
     * parsers so that the ErrorHandler is used for processing of all document-
     * validation problems reported.
     * 
     * @param docValidationErrHandler error handler for doc-validation reporting
     * 
     * @param loadExternalEnts whether XML parser should load remote DTDs, etc.
     * 
     * @param noStream whether HTML parser should buffer instead of streaming
     */
public void setUpValidatorAndParsers(ErrorHandler docValidationErrHandler, boolean noStream, boolean loadExternalEnts) throws SAXException {
    PropertyMapBuilder pmb = new PropertyMapBuilder();
    pmb.put(ValidateProperty.ERROR_HANDLER, docValidationErrHandler);
    pmb.put(ValidateProperty.XML_READER_CREATOR, new Jaxp11XMLReaderCreator());
    RngProperty.CHECK_ID_IDREF.add(pmb);
    PropertyMap jingPropertyMap = pmb.toPropertyMap();
    validator = this.mainSchema.createValidator(jingPropertyMap);
    if (this.hasHtml5Schema) {
        Validator assertionValidator = assertionSchema.createValidator(jingPropertyMap);
        validator = new CombineValidator(validator, assertionValidator);
        validator = new CombineValidator(validator, new CheckerValidator(new TableChecker(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new ConformingButObsoleteWarner(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new MicrodataChecker(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new NormalizationChecker(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new TextContentChecker(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new UncheckedSubtreeWarner(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new UnsupportedFeatureChecker(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new UsemapChecker(), jingPropertyMap));
        validator = new CombineValidator(validator, new CheckerValidator(new XmlPiChecker(), jingPropertyMap));
    }
    HtmlParser htmlParser = new HtmlParser();
    htmlParser.addCharacterHandler(sourceCode);
    htmlParser.setCommentPolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setContentNonXmlCharPolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setContentSpacePolicy(XmlViolationPolicy.ALTER_INFOSET);
    htmlParser.setNamePolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setXmlnsPolicy(XmlViolationPolicy.ALTER_INFOSET);
    htmlParser.setMappingLangToXmlLang(true);
    htmlParser.setHeuristics(Heuristics.ALL);
    htmlParser.setContentHandler(validator.getContentHandler());
    htmlParser.setErrorHandler(docValidationErrHandler);
    htmlParser.setNamePolicy(XmlViolationPolicy.ALLOW);
    htmlParser.setMappingLangToXmlLang(true);
    htmlParser.setFeature("http://xml.org/sax/features/unicode-normalization-checking", true);
    if (!noStream) {
        htmlParser.setStreamabilityViolationPolicy(XmlViolationPolicy.FATAL);
    }
    htmlReader = getWiretap(htmlParser);
    xmlParser = new SAXDriver();
    xmlParser.setContentHandler(validator.getContentHandler());
    if (lexicalHandler != null) {
        xmlParser.setProperty("http://xml.org/sax/properties/lexical-handler", lexicalHandler);
    }
    xmlReader = new IdFilter(xmlParser);
    xmlReader.setFeature("http://xml.org/sax/features/string-interning", true);
    xmlReader.setContentHandler(validator.getContentHandler());
    xmlReader.setFeature("http://xml.org/sax/features/unicode-normalization-checking", true);
    if (loadExternalEnts) {
        xmlReader.setEntityResolver(entityResolver);
    } else {
        xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
        xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        xmlReader.setEntityResolver(new NullEntityResolver());
    }
    xmlReader = getWiretap(xmlParser);
    xmlParser.setErrorHandler(docValidationErrHandler);
    xmlParser.lockErrorHandler();
}
Also used : IdFilter(nu.validator.xml.IdFilter) NullEntityResolver(nu.validator.xml.NullEntityResolver) Jaxp11XMLReaderCreator(com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator) ConformingButObsoleteWarner(nu.validator.checker.ConformingButObsoleteWarner) XmlPiChecker(nu.validator.checker.XmlPiChecker) TextContentChecker(nu.validator.checker.TextContentChecker) CheckerValidator(nu.validator.checker.jing.CheckerValidator) SAXDriver(nu.validator.gnu.xml.aelfred2.SAXDriver) UnsupportedFeatureChecker(nu.validator.checker.UnsupportedFeatureChecker) HtmlParser(nu.validator.htmlparser.sax.HtmlParser) PropertyMap(com.thaiopensource.util.PropertyMap) NormalizationChecker(nu.validator.checker.NormalizationChecker) UsemapChecker(nu.validator.checker.UsemapChecker) PropertyMapBuilder(com.thaiopensource.util.PropertyMapBuilder) TableChecker(nu.validator.checker.table.TableChecker) UncheckedSubtreeWarner(nu.validator.checker.UncheckedSubtreeWarner) CombineValidator(com.thaiopensource.relaxng.impl.CombineValidator) CheckerValidator(nu.validator.checker.jing.CheckerValidator) Validator(com.thaiopensource.validate.Validator) CombineValidator(com.thaiopensource.relaxng.impl.CombineValidator) MicrodataChecker(nu.validator.checker.MicrodataChecker)

Aggregations

CombineValidator (com.thaiopensource.relaxng.impl.CombineValidator)3 Validator (com.thaiopensource.validate.Validator)3 PropertyMap (com.thaiopensource.util.PropertyMap)2 PropertyMapBuilder (com.thaiopensource.util.PropertyMapBuilder)2 Schema (com.thaiopensource.validate.Schema)1 Jaxp11XMLReaderCreator (com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator)1 ConformingButObsoleteWarner (nu.validator.checker.ConformingButObsoleteWarner)1 MicrodataChecker (nu.validator.checker.MicrodataChecker)1 NormalizationChecker (nu.validator.checker.NormalizationChecker)1 TextContentChecker (nu.validator.checker.TextContentChecker)1 UncheckedSubtreeWarner (nu.validator.checker.UncheckedSubtreeWarner)1 UnsupportedFeatureChecker (nu.validator.checker.UnsupportedFeatureChecker)1 UsemapChecker (nu.validator.checker.UsemapChecker)1 XmlPiChecker (nu.validator.checker.XmlPiChecker)1 CheckerValidator (nu.validator.checker.jing.CheckerValidator)1 TableChecker (nu.validator.checker.table.TableChecker)1 SAXDriver (nu.validator.gnu.xml.aelfred2.SAXDriver)1 HtmlParser (nu.validator.htmlparser.sax.HtmlParser)1 IdFilter (nu.validator.xml.IdFilter)1 NullEntityResolver (nu.validator.xml.NullEntityResolver)1