use of nu.validator.checker.XmlPiChecker in project validator by validator.
the class VerifierServletTransaction method validatorByUrl.
/**
* @param url
* @return
* @throws SAXException
* @throws IOException
* @throws IncorrectSchemaException
*/
private Validator validatorByUrl(String url) throws SAXException, IOException, IncorrectSchemaException {
if (loadedValidatorUrls.contains(url)) {
return null;
}
loadedValidatorUrls.add(url);
if ("http://s.validator.nu/xhtml5.rnc".equals(url) || "http://s.validator.nu/html5.rnc".equals(url) || "http://s.validator.nu/html5-all.rnc".equals(url) || "http://s.validator.nu/xhtml5-all.rnc".equals(url) || "http://s.validator.nu/html5-its.rnc".equals(url) || "http://s.validator.nu/xhtml5-rdfalite.rnc".equals(url) || "http://s.validator.nu/html5-rdfalite.rnc".equals(url)) {
errorHandler.setSpec(html5spec);
}
Schema sch = resolveSchema(url, jingPropertyMap);
Validator validator = sch.createValidator(jingPropertyMap);
ContentHandler validatorContentHandler = validator.getContentHandler();
if (validatorContentHandler instanceof XmlPiChecker) {
lexicalHandler = (LexicalHandler) validatorContentHandler;
}
if (validatorContentHandler instanceof Assertions) {
Assertions assertions = (Assertions) validatorContentHandler;
assertions.setRequest(request);
assertions.setSourceIsCss(sourceCode.getIsCss());
}
if (validatorContentHandler instanceof LanguageDetectingChecker) {
//
LanguageDetectingChecker langdetect = (LanguageDetectingChecker) validatorContentHandler;
langdetect.setRequest(request);
langdetect.setHttpContentLanguageHeader(request.getHeader("Content-Language"));
}
return validator;
}
use of nu.validator.checker.XmlPiChecker 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();
}
Aggregations