Search in sources :

Example 6 with Schema

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;
}
Also used : CompactSchemaReader(com.thaiopensource.validate.rng.CompactSchemaReader) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) SchemaReader(com.thaiopensource.validate.SchemaReader) TypedInputSource(nu.validator.xml.TypedInputSource) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) Schema(com.thaiopensource.validate.Schema) CheckerSchema(nu.validator.checker.jing.CheckerSchema)

Example 7 with Schema

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;
}
Also used : CheckerSchema(nu.validator.checker.jing.CheckerSchema) CompactSchemaReader(com.thaiopensource.validate.rng.CompactSchemaReader) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) SchemaReader(com.thaiopensource.validate.SchemaReader) TypedInputSource(nu.validator.xml.TypedInputSource) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) SAXParseException(org.xml.sax.SAXParseException) Schema(com.thaiopensource.validate.Schema) CheckerSchema(nu.validator.checker.jing.CheckerSchema) IncorrectSchemaException(com.thaiopensource.validate.IncorrectSchemaException)

Example 8 with Schema

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;
}
Also used : CheckerSchema(nu.validator.checker.jing.CheckerSchema) Schema(com.thaiopensource.validate.Schema) XmlLangAttributeDroppingSchemaWrapper(nu.validator.xml.langattributes.XmlLangAttributeDroppingSchemaWrapper) RoleAttributeFilteringSchemaWrapper(nu.validator.xml.roleattributes.RoleAttributeFilteringSchemaWrapper) DataAttributeDroppingSchemaWrapper(nu.validator.xml.dataattributes.DataAttributeDroppingSchemaWrapper) SAXException(org.xml.sax.SAXException) ResourceNotRetrievableException(nu.validator.xml.PrudentHttpEntityResolver.ResourceNotRetrievableException) IOException(java.io.IOException) FatalSAXException(nu.validator.gnu.xml.aelfred2.FatalSAXException) SAXParseException(org.xml.sax.SAXParseException) TemplateElementDroppingSchemaWrapper(nu.validator.xml.templateelement.TemplateElementDroppingSchemaWrapper) NamespaceChangingSchemaWrapper(nu.validator.xml.customelements.NamespaceChangingSchemaWrapper)

Aggregations

Schema (com.thaiopensource.validate.Schema)8 SAXParseException (org.xml.sax.SAXParseException)5 CheckerSchema (nu.validator.checker.jing.CheckerSchema)4 SAXException (org.xml.sax.SAXException)4 SchemaReader (com.thaiopensource.validate.SchemaReader)3 CompactSchemaReader (com.thaiopensource.validate.rng.CompactSchemaReader)3 CombineValidator (com.thaiopensource.relaxng.impl.CombineValidator)2 PropertyMapBuilder (com.thaiopensource.util.PropertyMapBuilder)2 Validator (com.thaiopensource.validate.Validator)2 AutoSchemaReader (com.thaiopensource.validate.auto.AutoSchemaReader)2 TypedInputSource (nu.validator.xml.TypedInputSource)2 DataAttributeDroppingSchemaWrapper (nu.validator.xml.dataattributes.DataAttributeDroppingSchemaWrapper)2 XmlLangAttributeDroppingSchemaWrapper (nu.validator.xml.langattributes.XmlLangAttributeDroppingSchemaWrapper)2 CheckerSchema (org.whattf.checker.jing.CheckerSchema)2 InputSource (org.xml.sax.InputSource)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 PsiElementProcessor (com.intellij.psi.search.PsiElementProcessor)1 CachedValuesManager (com.intellij.psi.util.CachedValuesManager)1 PropertyMap (com.thaiopensource.util.PropertyMap)1 IncorrectSchemaException (com.thaiopensource.validate.IncorrectSchemaException)1