Search in sources :

Example 1 with SurveyValidationException

use of org.openforis.collect.manager.exception.SurveyValidationException in project collect by openforis.

the class SurveyValidator method validateAgainstSchema.

public void validateAgainstSchema(InputStream is, Version version) throws SurveyValidationException {
    try {
        SchemaFactory factory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
        String[] schemaFileNames = getSchemaFileNames(version);
        Source[] schemas = getSourcesFromClassPath(schemaFileNames);
        javax.xml.validation.Schema schema = factory.newSchema(schemas);
        Validator validator = schema.newValidator();
        validator.validate(new StreamSource(is));
    } catch (SAXException e) {
        throw new SurveyValidationException(e);
    } catch (IOException e) {
        throw new SurveyValidationException(e.getMessage(), e);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException) SurveyValidationException(org.openforis.collect.manager.exception.SurveyValidationException) ExpressionValidator(org.openforis.idm.metamodel.expression.ExpressionValidator) Validator(javax.xml.validation.Validator)

Aggregations

IOException (java.io.IOException)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 Validator (javax.xml.validation.Validator)1 SurveyValidationException (org.openforis.collect.manager.exception.SurveyValidationException)1 ExpressionValidator (org.openforis.idm.metamodel.expression.ExpressionValidator)1 SAXException (org.xml.sax.SAXException)1