use of com.thaiopensource.validate.Schema in project intellij-community by JetBrains.
the class XmlInstanceValidator method doValidation.
public static void doValidation(@NotNull final XmlDocument doc, final Validator.ValidationHost host, final XmlFile descriptorFile) {
try {
final Schema schema = RngParser.getCachedSchema(descriptorFile);
if (schema == null) {
// did not manage to get a compiled schema. no validation...
return;
}
final ErrorHandler eh = MyErrorHandler.create(doc, host);
if (eh == null) {
return;
}
final PropertyMapBuilder builder = new PropertyMapBuilder();
builder.put(ValidateProperty.ERROR_HANDLER, eh);
final ContentHandler handler = schema.createValidator(builder.toPropertyMap()).getContentHandler();
doc.accept(new Psi2SaxAdapter(handler));
} catch (ProcessCanceledException e) {
throw e;
} catch (RuntimeException e) {
LOG.error(e);
} catch (Exception e) {
LOG.info(e);
}
}
use of com.thaiopensource.validate.Schema in project intellij-community by JetBrains.
the class RngParser method getCachedSchema.
public static Schema getCachedSchema(final XmlFile descriptorFile) {
CachedValue<Schema> value = descriptorFile.getUserData(SCHEMA_KEY);
if (value == null) {
final CachedValueProvider<Schema> provider = () -> {
final InputSource inputSource = makeInputSource(descriptorFile);
try {
final Schema schema = new MySchemaReader(descriptorFile).createSchema(inputSource, EMPTY_PROPS);
final PsiElementProcessor.CollectElements<XmlFile> processor = new PsiElementProcessor.CollectElements<>();
RelaxIncludeIndex.processForwardDependencies(descriptorFile, processor);
if (processor.getCollection().size() > 0) {
return CachedValueProvider.Result.create(schema, processor.toArray(), descriptorFile);
} else {
return CachedValueProvider.Result.createSingleDependency(schema, descriptorFile);
}
} catch (Exception e) {
LOG.info(e);
return CachedValueProvider.Result.createSingleDependency(null, descriptorFile);
}
};
final CachedValuesManager mgr = CachedValuesManager.getManager(descriptorFile.getProject());
value = mgr.createCachedValue(provider, false);
descriptorFile.putUserData(SCHEMA_KEY, value);
}
return value.getValue();
}
use of com.thaiopensource.validate.Schema in project validator by validator.
the class ValidationWorker method main.
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]), "utf-8"));
PrintWriter out = new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(args[1])), "utf-8"), true);
File rootDir = new File(args[2]);
Set<Schema> schemas = new HashSet<Schema>();
schemas.add(CheckerSchema.ASSERTION_SCH);
schemas.add(CheckerSchema.NORMALIZATION_CHECKER);
schemas.add(CheckerSchema.TABLE_CHECKER);
schemas.add(CheckerSchema.TEXT_CONTENT_CHECKER);
schemas.add(CheckerSchema.USEMAP_CHECKER);
InputSource is = new InputSource((new File(args[3])).toURL().toExternalForm());
SchemaReader sr = CompactSchemaReader.getInstance();
schemas.add(new XmlLangAttributeDroppingSchemaWrapper(new DataAttributeDroppingSchemaWrapper(sr.createSchema(is, PropertyMap.EMPTY))));
CountingReadLine countingReadLine = new CountingReadLine(in);
for (int i = 0; i < 4; i++) {
(new Thread(new ValidationWorker(countingReadLine, out, rootDir, schemas))).start();
}
}
use of com.thaiopensource.validate.Schema 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;
}
use of com.thaiopensource.validate.Schema 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;
}
Aggregations