use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class Validator method validate.
private void validate(IJSONModel model, IJSONSchemaProperty schemaProperty, JSONValidationInfo valinfo) {
IJSONDocument document = model.getDocument();
IJSONNode node = document.getFirstChild();
while (node != null) {
validate(node, schemaProperty, valinfo);
node = node.getNextSibling();
}
}
use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class Validator method getSize.
private int getSize(IJSONArray instance) {
if (instance == null) {
return 0;
}
int instanceSize = 0;
IJSONNode child = instance.getFirstChild();
while (child != null) {
instanceSize = instanceSize + 1;
child = child.getNextSibling();
}
return instanceSize;
}
use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class Validator method validateAdditionalProperties.
private void validateAdditionalProperties(IJSONNode node, JsonObject schema, JsonValue value, JSONValidationInfo valinfo) {
if (value != null && value.isBoolean() && !value.asBoolean()) {
Set<String> s = getProperties(node);
Set<String> p = getProperties(schema.get(IJSONSchemaNode.PROPERTIES));
Set<String> pp = getProperties(schema.get(IJSONSchemaNode.PATTERN_PROPERTIES));
for (String string : p) {
if (s.contains(string)) {
s.remove(string);
}
}
for (String patternStr : pp) {
Pattern pattern = Pattern.compile(patternStr);
Iterator<String> iter = s.iterator();
while (iter.hasNext()) {
String ss = iter.next();
if (ss != null) {
Matcher matcher = pattern.matcher(ss);
if (matcher.find()) {
iter.remove();
}
}
}
}
for (String string : s) {
if ("$schema".equals(string)) {
// $NON-NLS-1$
continue;
}
IJSONNode n = node.getFirstChild();
while (n != null) {
if (n instanceof IJSONPair) {
IJSONPair pair = (IJSONPair) n;
if (string.equals(pair.getName())) {
break;
}
}
n = n.getNextSibling();
}
if (n == null) {
node = n;
}
int offset = n.getStartOffset();
int line = n.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Property " + string + " is not allowed", line, 0, offset == 0 ? 1 : offset);
}
}
}
use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class Validator method validate.
private void validate(IJSONNode node, IJSONSchemaProperty schemaProperty, JSONValidationInfo valinfo) {
if (node == null || schemaProperty == null) {
return;
}
JsonObject schema = schemaProperty.getJsonObject();
validate(node, schema, valinfo);
IJSONNode child = node.getFirstChild();
while (child != null) {
IJSONSchemaProperty property = schemaProperty.getSchemaDocument().getProperty(child.getPath());
validate(child, property, valinfo);
if (child instanceof IJSONPair) {
IJSONValue value = ((IJSONPair) child).getValue();
if (value instanceof IJSONObject) {
IJSONSchemaProperty prop = schemaProperty.getSchemaDocument().getProperty(value.getPath());
validate(value, prop, valinfo);
}
}
child = child.getNextSibling();
}
}
use of org.eclipse.wst.json.core.document.IJSONNode 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;
}
Aggregations