use of com.thaiopensource.validate.Schema 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.Schema 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.Schema in project validator by validator.
the class SimpleDocumentValidator method setUpMainSchema.
/* *
* Prepares the main RelaxNG schema to use for document validation, by
* retrieving a serialized schema instance from the copies of known
* http://s.validator.nu/* schemas in the local entity cache packaged with
* the validator code and creating a Schema instance from it. Also checks
* for resolution of secondary schemas.
*
* @param schemaUrl an http://s.validator.nu/* URL
*
* @param errorHandler error handler for schema-error reporting
*
* @throws SchemaReadException if retrieval of any schema fails
*/
public void setUpMainSchema(String schemaUrl, ErrorHandler errorHandler) throws SAXException, Exception, SchemaReadException {
Schema schema = schemaByUrl(schemaUrl, errorHandler);
if (schemaUrl.contains("html5")) {
try {
assertionSchema = CheckerSchema.ASSERTION_SCH;
} catch (Exception e) {
throw new SchemaReadException("Failed to retrieve secondary schema.");
}
schema = new DataAttributeDroppingSchemaWrapper(schema);
schema = new XmlLangAttributeDroppingSchemaWrapper(schema);
schema = new RoleAttributeFilteringSchemaWrapper(schema);
schema = new TemplateElementDroppingSchemaWrapper(schema);
schema = new NamespaceChangingSchemaWrapper(schema);
this.hasHtml5Schema = true;
if ("http://s.validator.nu/html5-all.rnc".equals(schemaUrl)) {
System.setProperty("nu.validator.schema.rdfa-full", "1");
} else {
System.setProperty("nu.validator.schema.rdfa-full", "0");
}
}
this.mainSchemaUrl = schemaUrl;
this.mainSchema = schema;
}
Aggregations