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;
}
Aggregations