Search in sources :

Example 1 with IJSONSchemaProcessor

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) IJSONPair(org.eclipse.wst.json.core.document.IJSONPair) IJSONValue(org.eclipse.wst.json.core.document.IJSONValue) IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode) IJSONSchemaProcessor(org.eclipse.json.schema.IJSONSchemaProcessor) URL(java.net.URL)

Example 2 with IJSONSchemaProcessor

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);
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IJSONSchemaProcessor(org.eclipse.json.schema.IJSONSchemaProcessor)

Aggregations

IJSONSchemaProcessor (org.eclipse.json.schema.IJSONSchemaProcessor)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 CoreException (org.eclipse.core.runtime.CoreException)1 IJSONDocument (org.eclipse.wst.json.core.document.IJSONDocument)1 IJSONNode (org.eclipse.wst.json.core.document.IJSONNode)1 IJSONPair (org.eclipse.wst.json.core.document.IJSONPair)1 IJSONValue (org.eclipse.wst.json.core.document.IJSONValue)1