use of com.thaiopensource.validate.auto.AutoSchemaReader in project intellij-community by JetBrains.
the class ValidateAction method doValidation.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
private static void doValidation(VirtualFile instanceFile, VirtualFile schemaFile, org.xml.sax.ErrorHandler eh) {
final SchemaReader sr = schemaFile.getFileType() == RncFileType.getInstance() ? CompactSchemaReader.getInstance() : new AutoSchemaReader();
final PropertyMapBuilder properties = new PropertyMapBuilder();
ValidateProperty.ERROR_HANDLER.put(properties, eh);
// TODO: should some options dialog displayed before validating?
RngProperty.CHECK_ID_IDREF.add(properties);
try {
final String schemaPath = VfsUtilCore.fixIDEAUrl(schemaFile.getUrl());
try {
final ValidationDriver driver = new ValidationDriver(properties.toPropertyMap(), sr);
final InputSource in = ValidationDriver.uriOrFileInputSource(schemaPath);
in.setEncoding(schemaFile.getCharset().name());
if (driver.loadSchema(in)) {
final String path = VfsUtilCore.fixIDEAUrl(instanceFile.getUrl());
try {
driver.validate(ValidationDriver.uriOrFileInputSource(path));
} catch (IOException e1) {
eh.fatalError(new SAXParseException(e1.getMessage(), null, UriOrFile.fileToUri(path), -1, -1, e1));
}
}
} catch (SAXParseException e1) {
eh.fatalError(e1);
} catch (IOException e1) {
eh.fatalError(new SAXParseException(e1.getMessage(), null, UriOrFile.fileToUri(schemaPath), -1, -1, e1));
}
} catch (SAXException | MalformedURLException e1) {
// huh?
Logger.getInstance(ValidateAction.class.getName()).error(e1);
}
}
use of com.thaiopensource.validate.auto.AutoSchemaReader in project validator by validator.
the class VerifierServletTransaction method schemaByUrl.
/**
* @param url
* @return
* @throws SAXException
* @throws IOException
* @throws IncorrectSchemaException
*/
private static Schema schemaByUrl(String url, EntityResolver resolver, PropertyMap pMap) throws SAXException, IOException, IncorrectSchemaException {
log4j.debug("Will load schema: " + url);
TypedInputSource schemaInput;
try {
schemaInput = (TypedInputSource) resolver.resolveEntity(null, url);
} catch (ClassCastException e) {
log4j.fatal(url, e);
throw e;
}
SchemaReader sr = null;
if ("application/relax-ng-compact-syntax".equals(schemaInput.getType())) {
sr = CompactSchemaReader.getInstance();
} else {
sr = new AutoSchemaReader();
}
Schema sch = sr.createSchema(schemaInput, pMap);
return sch;
}
use of com.thaiopensource.validate.auto.AutoSchemaReader in project validator by validator.
the class VerifierServletTransaction method resolveSchema.
@Override
public Schema resolveSchema(String url, PropertyMap options) throws SAXException, IOException, IncorrectSchemaException {
int i = Arrays.binarySearch(preloadedSchemaUrls, url);
if (i > -1) {
Schema rv = preloadedSchemas[i];
if (options.contains(WrapProperty.ATTRIBUTE_OWNER)) {
if (rv instanceof CheckerSchema) {
errorHandler.error(new SAXParseException("A non-schema checker cannot be used as an attribute schema.", null, url, -1, -1));
throw new IncorrectSchemaException();
} else {
// ugly fall through
}
} else {
return rv;
}
}
externalSchema = true;
TypedInputSource schemaInput = (TypedInputSource) entityResolver.resolveEntity(null, url);
SchemaReader sr = null;
if ("application/relax-ng-compact-syntax".equals(schemaInput.getType())) {
sr = CompactSchemaReader.getInstance();
} else {
sr = new AutoSchemaReader();
}
Schema sch = sr.createSchema(schemaInput, options);
if (Statistics.STATISTICS != null && "com.thaiopensource.validate.schematron.SchemaImpl".equals(sch.getClass().getName())) {
externalSchematron = true;
}
return sch;
}
use of com.thaiopensource.validate.auto.AutoSchemaReader in project validator by validator.
the class SimpleDocumentValidator method schemaByUrl.
private Schema schemaByUrl(String schemaUrl, ErrorHandler errorHandler) throws Exception, SchemaReadException {
PropertyMapBuilder pmb = new PropertyMapBuilder();
pmb.put(ValidateProperty.ERROR_HANDLER, errorHandler);
pmb.put(ValidateProperty.ENTITY_RESOLVER, entityResolver);
pmb.put(ValidateProperty.XML_READER_CREATOR, new Jaxp11XMLReaderCreator());
RngProperty.CHECK_ID_IDREF.add(pmb);
PropertyMap jingPropertyMap = pmb.toPropertyMap();
try {
TypedInputSource schemaInput = (TypedInputSource) entityResolver.resolveEntity(null, schemaUrl);
SchemaReader sr;
if ("application/relax-ng-compact-syntax".equals(schemaInput.getType())) {
sr = CompactSchemaReader.getInstance();
} else {
sr = new AutoSchemaReader();
}
return sr.createSchema(schemaInput, jingPropertyMap);
} catch (ClassCastException e) {
throw new SchemaReadException(String.format("Failed to resolve schema URL \"%s\".", schemaUrl));
}
}
Aggregations