Search in sources :

Example 1 with JSONSchemaDocument

use of org.eclipse.json.impl.schema.JSONSchemaDocument in project webtools.sourceediting by eclipse.

the class JSONSchemaProcessor method getSchema.

@Override
public IJSONSchemaDocument getSchema(String uriString) throws IOException {
    IJSONSchemaDocument schemaDocument = schemaDocuments.get(uriString);
    if (schemaDocument != null) {
        return schemaDocument;
    }
    int size = schemaDocuments.size();
    if (size > MAP_SIZE) {
        String key = schemaDocuments.keySet().iterator().next();
        schemaDocuments.remove(key);
    }
    URL url = new URL(uriString);
    InputStream is = null;
    try {
        if ("jar".equals(url.getProtocol())) {
            is = url.openStream();
        } else {
            File f = HttpClientProvider.getFile(url);
            if (f != null) {
                is = new FileInputStream(f);
            }
        }
        if (is != null) {
            schemaDocument = new JSONSchemaDocument(new InputStreamReader(is));
        }
    } finally {
        if (is != null) {
            is.close();
        }
    }
    if (schemaDocument != null) {
        schemaDocuments.put(uriString, schemaDocument);
    }
    return schemaDocument;
}
Also used : IJSONSchemaDocument(org.eclipse.json.schema.IJSONSchemaDocument) JSONSchemaDocument(org.eclipse.json.impl.schema.JSONSchemaDocument) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IJSONSchemaDocument(org.eclipse.json.schema.IJSONSchemaDocument) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 JSONSchemaDocument (org.eclipse.json.impl.schema.JSONSchemaDocument)1 IJSONSchemaDocument (org.eclipse.json.schema.IJSONSchemaDocument)1