use of org.eclipse.json.schema.IJSONSchemaProcessor in project webtools.sourceediting by eclipse.
the class SchemaProcessorRegistryReader method getSchemaDocument.
public IJSONSchemaDocument getSchemaDocument(IJSONModel model) throws IOException {
IJSONSchemaProcessor processor = getDefaultProcessor();
if (processor == null) {
return null;
}
IJSONDocument document = model.getDocument();
IJSONNode jsonObject = document.getFirstChild();
if (jsonObject != null) {
IJSONNode child = jsonObject.getFirstChild();
while (child != null) {
if (child instanceof IJSONPair) {
IJSONPair pair = (IJSONPair) child;
String name = pair.getName();
IJSONValue valueNode = pair.getValue();
if (valueNode != null && "$schema".equals(name)) {
// $NON-NLS-1$
String schema = JSONUtil.getString(valueNode);
try {
if (schema != null) {
schema = URIHelper.addImpliedFileProtocol(schema);
new URL(schema);
return processor.getSchema(schema);
}
} catch (MalformedURLException e) {
}
}
}
child = child.getNextSibling();
}
}
String base = model == null || model.getResolver() == null ? null : model.getResolver().getFileBaseLocation();
// Assert.isNotNull(base, "Base location is expected to be non null."); //$NON-NLS-1$
if (base != null) {
base = URIHelper.addImpliedFileProtocol(base);
}
String schemaURL = resolve(base, null, null);
if (schemaURL != null) {
return processor.getSchema(schemaURL);
}
return null;
}
use of org.eclipse.json.schema.IJSONSchemaProcessor in project webtools.sourceediting by eclipse.
the class SchemaProcessorRegistryReader method readElement.
protected void readElement(IConfigurationElement element) {
if (TAG_CONTRIBUTION.equals(element.getName())) {
String id = element.getAttribute("id");
String name = element.getAttribute("name");
try {
IJSONSchemaProcessor schemaProcessor = (IJSONSchemaProcessor) element.createExecutableExtension("class");
this.defaultProcessor = schemaProcessor;
} catch (CoreException e) {
Logger.logException(e);
}
}
}
Aggregations