Search in sources :

Example 1 with JSONValidationReport

use of org.eclipse.wst.json.core.internal.validation.JSONValidationReport in project webtools.sourceediting by eclipse.

the class Validator method validate.

@Override
public ValidationReport validate(String uri, InputStream inputstream, NestedValidatorContext context, ValidationResult result) {
    JSONValidator validator = JSONValidator.getInstance();
    JSONValidationConfiguration configuration = new JSONValidationConfiguration();
    JSONValidationReport valreport = validator.validate(uri, inputstream, configuration, result, context);
    String prefs = JSONCorePlugin.getDefault().getBundle().getSymbolicName();
    IEclipsePreferences modelPreferences = InstanceScope.INSTANCE.getNode(prefs);
    boolean validateSchema = modelPreferences.getBoolean(JSONCorePreferenceNames.SCHEMA_VALIDATION, false);
    if (validateSchema) {
        IJSONModel model = null;
        try {
            IStructuredModel temp = getModel(uri);
            if (!(temp instanceof IJSONModel)) {
                return valreport;
            }
            model = (IJSONModel) temp;
            IJSONSchemaDocument schemaDocument = SchemaProcessorRegistryReader.getInstance().getSchemaDocument(model);
            if (schemaDocument != null) {
                JSONValidationInfo valinfo = null;
                if (valreport instanceof JSONValidationInfo) {
                    valinfo = (JSONValidationInfo) valreport;
                } else {
                    valinfo = new JSONValidationInfo(uri);
                }
                validate(model, schemaDocument, valinfo);
                // valreport.getValidationMessages();
                return valreport;
            }
        } catch (IOException e) {
            logWarning(e);
            return valreport;
        } finally {
            if (model != null) {
                model.releaseFromRead();
            }
        }
    }
    return valreport;
}
Also used : JSONValidationReport(org.eclipse.wst.json.core.internal.validation.JSONValidationReport) JSONValidationConfiguration(org.eclipse.wst.json.core.internal.validation.JSONValidationConfiguration) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IJSONModel(org.eclipse.wst.json.core.document.IJSONModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IJSONSchemaDocument(org.eclipse.json.schema.IJSONSchemaDocument) IOException(java.io.IOException) JSONValidationInfo(org.eclipse.wst.json.core.internal.validation.JSONValidationInfo)

Aggregations

IOException (java.io.IOException)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 IJSONSchemaDocument (org.eclipse.json.schema.IJSONSchemaDocument)1 IJSONModel (org.eclipse.wst.json.core.document.IJSONModel)1 JSONValidationConfiguration (org.eclipse.wst.json.core.internal.validation.JSONValidationConfiguration)1 JSONValidationInfo (org.eclipse.wst.json.core.internal.validation.JSONValidationInfo)1 JSONValidationReport (org.eclipse.wst.json.core.internal.validation.JSONValidationReport)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1