use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject 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.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.
the class Validator method validate.
private void validate(IJSONNode node, JsonObject schema, Member member, JSONValidationInfo valinfo) {
if (IJSONSchemaNode.ALL_OF.equals(member.getName()) && member.getValue() instanceof JsonArray) {
JsonArray jsonArray = (JsonArray) member.getValue();
Iterator<JsonValue> iter = jsonArray.iterator();
while (iter.hasNext()) {
JsonValue value = iter.next();
if (value instanceof JsonObject) {
validate(node, (JsonObject) value, valinfo);
}
}
}
if (IJSONSchemaNode.ANY_OF.equals(member.getName()) && member.getValue() instanceof JsonArray) {
JsonArray jsonArray = (JsonArray) member.getValue();
Iterator<JsonValue> iter = jsonArray.iterator();
while (iter.hasNext()) {
JsonValue value = iter.next();
if (value instanceof JsonObject) {
JSONValidationInfo info = new JSONValidationInfo("");
validate(node, (JsonObject) value, info);
if (info.getValidationMessages() == null || info.getValidationMessages().length == 0) {
return;
}
}
}
int offset = node.getStartOffset();
int line = node.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Matches a schema that is not allowed", line, 0, offset == 0 ? 1 : offset);
}
if (IJSONSchemaNode.ONE_OF.equals(member.getName()) && member.getValue() instanceof JsonArray) {
JsonArray jsonArray = (JsonArray) member.getValue();
Iterator<JsonValue> iter = jsonArray.iterator();
int count = 0;
while (iter.hasNext()) {
JsonValue value = iter.next();
if (value instanceof JsonObject) {
JSONValidationInfo info = new JSONValidationInfo("");
validate(node, (JsonObject) value, info);
if (info.getValidationMessages() == null || info.getValidationMessages().length == 0) {
count = count + 1;
}
}
}
if (count != 1) {
int offset = node.getStartOffset();
int line = node.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Matches a schema that is not allowed", line, 0, offset == 0 ? 1 : offset);
}
}
if (IJSONSchemaNode.NOT.equals(member.getName()) && member.getValue() instanceof JsonObject) {
JsonObject json = (JsonObject) member.getValue();
JSONValidationInfo info = new JSONValidationInfo("");
validate(node, json, info);
if (info.getValidationMessages() == null || info.getValidationMessages().length == 0) {
int offset = node.getStartOffset();
int line = node.getModel().getStructuredDocument().getLineOfOffset(offset);
valinfo.addMessage("Matches a schema that is not allowed", line, 0, offset == 0 ? 1 : offset);
}
}
if (IJSONSchemaNode.TYPE.equals(member.getName())) {
validateType(node, member, valinfo);
}
if (IJSONSchemaNode.ENUM.equals(member.getName())) {
validateEnum(node, schema, valinfo);
}
if (node.getNodeType() == IJSONNode.OBJECT_NODE) {
if (IJSONSchemaNode.REQUIRED.equals(member.getName())) {
validateRequired(node, schema, valinfo);
}
if (IJSONSchemaNode.MAX_PROPERTIES.equals(member.getName())) {
validateMaxProperties(node, schema, valinfo);
}
if (IJSONSchemaNode.MIN_PROPERTIES.equals(member.getName())) {
validateMinProperties(node, schema, valinfo);
}
if (IJSONSchemaNode.ADDITIONAL_PROPERTIES.equals(member.getName())) {
validateAdditionalProperties(node, schema, member.getValue(), valinfo);
}
}
if (node.getNodeType() == IJSONNode.PAIR_NODE) {
IJSONValue value = ((IJSONPair) node).getValue();
JSONSchemaType[] types = JSONSchemaNode.getType(schema.get(IJSONSchemaNode.TYPE));
if (value != null) {
if (value.getNodeType() == IJSONNode.VALUE_STRING_NODE && isType(types, JSONSchemaType.String)) {
validateString(node, schema, member, valinfo, value);
}
if (value.getNodeType() == IJSONNode.VALUE_NUMBER_NODE && (isType(types, JSONSchemaType.Integer) || isType(types, JSONSchemaType.Number))) {
validateNumber(node, schema, member, valinfo, value);
}
if (value.getNodeType() == IJSONNode.ARRAY_NODE && isType(types, JSONSchemaType.Array)) {
validateArray(node, schema, member, valinfo, value);
}
}
}
}
use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.
the class CatalogSchemastoreReader method readSchemastore.
protected void readSchemastore() {
File f = getUrl();
if (f != null) {
int type = ICatalogEntry.ENTRY_TYPE_SCHEMA;
JsonValue schemas;
try {
InputStreamReader reader = new InputStreamReader(new FileInputStream(f));
JsonObject json = JsonObject.readFrom(reader);
schemas = json.get(SCHEMAS);
} catch (IOException e) {
Logger.logException(e);
return;
}
if (schemas != null && schemas instanceof JsonArray) {
JsonArray elements = (JsonArray) schemas;
Iterator<JsonValue> iter = elements.iterator();
while (iter.hasNext()) {
JsonValue value = iter.next();
if (value instanceof JsonObject) {
JsonObject jsonObject = (JsonObject) value;
// $NON-NLS-1$
JsonValue urlJson = jsonObject.get("url");
// $NON-NLS-1$
JsonValue fileMatchJson = jsonObject.get("fileMatch");
if (urlJson != null && fileMatchJson != null && urlJson.isString() && fileMatchJson.isArray()) {
String url = urlJson.asString();
JsonArray fileMatchArray = fileMatchJson.asArray();
Iterator<JsonValue> fileIter = fileMatchArray.iterator();
while (fileIter.hasNext()) {
JsonValue fileMatchValue = fileIter.next();
if (fileMatchValue.isString()) {
String fileMatch = fileMatchValue.asString();
ICatalogElement catalogElement = catalog.createCatalogElement(type);
if (catalogElement instanceof ICatalogEntry) {
ICatalogEntry entry = (ICatalogEntry) catalogElement;
entry.setKey(fileMatch);
entry.setURI(url);
entry.setId(fileMatch);
}
catalog.addCatalogElement(catalogElement);
}
}
}
}
}
}
}
}
use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.
the class JSONSchemaNode method addProperties.
private void addProperties(IJSONSchemaNode schemaNode, JsonObject properties) {
if (properties == null) {
return;
}
Iterator<Member> members = properties.iterator();
while (members.hasNext()) {
Member member = members.next();
schemaNode.addProperty(new JSONSchemaProperty(member.getName(), (JsonObject) member.getValue(), schemaNode));
}
}
use of org.eclipse.json.provisonnal.com.eclipsesource.json.JsonObject in project webtools.sourceediting by eclipse.
the class JSONSchemaNode method addDefinitions.
private void addDefinitions() {
// $NON-NLS-1$
JsonValue defs = jsonObject.get("definitions");
if (defs instanceof JsonObject) {
Iterator<Member> members = ((JsonObject) defs).iterator();
while (members.hasNext()) {
Member member = members.next();
JsonValue value = member.getValue();
if (value instanceof JsonObject) {
definitions.put(member.getName(), member.getValue());
}
}
}
}
Aggregations