Search in sources :

Example 1 with AutoSchemaReader

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);
    }
}
Also used : CompactSchemaReader(com.thaiopensource.validate.rng.CompactSchemaReader) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) SchemaReader(com.thaiopensource.validate.SchemaReader) InputSource(org.xml.sax.InputSource) MalformedURLException(java.net.MalformedURLException) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) SAXParseException(org.xml.sax.SAXParseException) ValidationDriver(com.thaiopensource.validate.ValidationDriver) PropertyMapBuilder(com.thaiopensource.util.PropertyMapBuilder) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 2 with AutoSchemaReader

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;
}
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 3 with AutoSchemaReader

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;
}
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 4 with AutoSchemaReader

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));
    }
}
Also used : CompactSchemaReader(com.thaiopensource.validate.rng.CompactSchemaReader) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) SchemaReader(com.thaiopensource.validate.SchemaReader) Jaxp11XMLReaderCreator(com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator) PropertyMap(com.thaiopensource.util.PropertyMap) TypedInputSource(nu.validator.xml.TypedInputSource) AutoSchemaReader(com.thaiopensource.validate.auto.AutoSchemaReader) PropertyMapBuilder(com.thaiopensource.util.PropertyMapBuilder)

Aggregations

SchemaReader (com.thaiopensource.validate.SchemaReader)4 AutoSchemaReader (com.thaiopensource.validate.auto.AutoSchemaReader)4 CompactSchemaReader (com.thaiopensource.validate.rng.CompactSchemaReader)4 TypedInputSource (nu.validator.xml.TypedInputSource)3 PropertyMapBuilder (com.thaiopensource.util.PropertyMapBuilder)2 Schema (com.thaiopensource.validate.Schema)2 CheckerSchema (nu.validator.checker.jing.CheckerSchema)2 SAXParseException (org.xml.sax.SAXParseException)2 PropertyMap (com.thaiopensource.util.PropertyMap)1 IncorrectSchemaException (com.thaiopensource.validate.IncorrectSchemaException)1 ValidationDriver (com.thaiopensource.validate.ValidationDriver)1 Jaxp11XMLReaderCreator (com.thaiopensource.xml.sax.Jaxp11XMLReaderCreator)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1