Search in sources :

Example 1 with ValidationDriver

use of com.thaiopensource.validate.ValidationDriver 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)

Aggregations

PropertyMapBuilder (com.thaiopensource.util.PropertyMapBuilder)1 SchemaReader (com.thaiopensource.validate.SchemaReader)1 ValidationDriver (com.thaiopensource.validate.ValidationDriver)1 AutoSchemaReader (com.thaiopensource.validate.auto.AutoSchemaReader)1 CompactSchemaReader (com.thaiopensource.validate.rng.CompactSchemaReader)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1