@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String input = data.getInstance().getNode().textValue(); if (!MACADDR.matcher(input).matches()) report.error(newMsg(data, bundle, "err.format.macAddr.invalid") .putArgument("value", input)); } }
throws ProcessingException final JsonNode instance = data.getInstance().getNode(); final Set<String> fields = Sets.newHashSet(instance.fieldNames()); return; final SchemaTree tree = data.getSchema(); FullData newData; JsonPointer pointer; continue; pointer = JsonPointer.of(keyword, field); newData = data.withSchema(tree.append(pointer)); processor.process(report, newData);
/** * Return a new full data with another schema * * @param schema the schema * @return a new full data instance */ public FullData withSchema(final SchemaTree schema) { return new FullData(schema, instance, deepCheck); }
public SchemaContext(final FullData data) { schema = data.getSchema(); final JsonTree tree = data.getInstance(); instanceType = tree != null ? NodeType.getNodeType(tree.getNode()) : null; }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final JsonNode node = tree.getNode().get(keyword); FullData newData; if (node.isObject()) { newData = data.withSchema(tree.append(JsonPointer.of(keyword))); processor.process(report, newData); return; } /* * Not an object? An array */ final int size = node.size(); JsonPointer pointer; for (int index = 0; index < size; index++) { pointer = JsonPointer.of(keyword, index); newData = data.withSchema(tree.append(pointer)); processor.process(report, newData); } }
private void processObject(final ProcessingReport report, final FullData input) throws ProcessingException { final SchemaTree tree = input.getSchema(); final JsonTree instance = input.getInstance(); final JsonNode schema = tree.getNode(); final JsonNode node = instance.getNode(); final JsonNode digest = ObjectSchemaDigester.getInstance() .digest(schema); final ObjectSchemaSelector selector = new ObjectSchemaSelector(digest); final List<String> fields = Lists.newArrayList(node.fieldNames()); Collections.sort(fields); FullData data; JsonTree newInstance; for (final String field: fields) { newInstance = instance.append(JsonPointer.of(field)); data = input.withInstance(newInstance); for (final JsonPointer ptr: selector.selectSchemas(field)) { data = data.withSchema(tree.append(ptr)); process(report, data); } } }
final FullData data = new FullData(newContext.getSchema(), input.getInstance(), input.isDeepCheck()); if (!(report.isSuccess() || data.isDeepCheck())) { stack.pop(); return input; final JsonNode node = data.getInstance().getNode();
@Override public FullData process(final ProcessingReport report, final FullData input) throws ProcessingException { final JsonNode schema = input.getSchema().getNode(); final JsonPointer ptr = schema == sub1 ? ptr1 : ptr2; assertEquals(input.getSchema().getPointer(), ptr, "schema pointer differs from expectations"); final WantedState wanted = schema == sub1 ? wanted1 : wanted2; wanted.doIt(report); return input; } }
/** * Return a new message for this format attribute * * @param data the validation context * @param key key in the format bundle message * @return a new message */ protected final ProcessingMessage newMsg(final FullData data, final MessageBundle bundle, final String key) { return data.newMessage().put("domain", "validation") .put("keyword", "format").put("attribute", fmt) .setMessage(bundle.getMessage(key)) .put("value", data.getInstance().getNode()); } }
private ProcessingMessage validationLoopMessage(final FullData input) { final ArrayNode node = JacksonUtils.nodeFactory().arrayNode(); for (final SchemaURI uri: schemaURIs) node.add(uri.toString()); return input.newMessage() .put("domain", "validation") .setMessage(errmsg) .putArgument("alreadyVisited", new SchemaURI(input.getSchema())) .putArgument("instancePointer", pointer.toString()) .put("validationPath", node); } }
protected final ProcessingMessage newMsg(final FullData data) { return data.newMessage().put("domain", "validation") .put("keyword", keyword) .setExceptionProvider(EXCEPTION_PROVIDER); }
private void processArray(final ProcessingReport report, final FullData input) throws ProcessingException { final SchemaTree tree = input.getSchema(); final JsonTree instance = input.getInstance(); final JsonNode schema = tree.getNode(); final JsonNode node = instance.getNode(); final JsonNode digest = ArraySchemaDigester.getInstance() .digest(schema); final ArraySchemaSelector selector = new ArraySchemaSelector(digest); final int size = node.size(); FullData data; JsonTree newInstance; for (int index = 0; index < size; index++) { newInstance = instance.append(JsonPointer.of(index)); data = input.withInstance(newInstance); for (final JsonPointer ptr: selector.selectSchemas(index)) { data = data.withSchema(tree.append(ptr)); process(report, data); } } }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final ProcessingReport subReport = new ListProcessingReport(report.getLogLevel(), LogLevel.FATAL); processor.process(subReport, data.withSchema(tree.append(PTR))); if (subReport.isSuccess()) report.error(newMsg(data, bundle, "err.draftv4.not.fail")); }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String regex = data.getSchema().getNode().get(keyword) .textValue(); final String value = data.getInstance().getNode().textValue(); if (!RhinoHelper.regMatch(regex, value)) report.error(newMsg(data, bundle, "err.common.pattern.noMatch") .putArgument("regex", regex).putArgument("string", value)); }
@Override public FullData process(final ProcessingReport report, final FullData input) throws ProcessingException { assertEquals(input.getSchema().getPointer(), PTR); wanted.doIt(report, message); return input; } }
protected final ProcessingMessage newMsg(final FullData data, final MessageBundle bundle, final String key) { return data.newMessage().put("domain", "validation") .put("keyword", keyword).setMessage(bundle.getMessage(key)) .setExceptionProvider(EXCEPTION_PROVIDER); }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final Set<String> set = Sets.newLinkedHashSet(required); set.removeAll(Sets.newHashSet(data.getInstance().getNode() .fieldNames())); if (!set.isEmpty()) report.error(newMsg(data, bundle, "err.common.object.missingMembers") .put("required", required) .putArgument("missing", toArrayNode(set))); }
throws ProcessingException final JsonNode instance = data.getInstance().getNode(); final NodeType type = NodeType.getNodeType(instance); final SchemaTree tree = data.getSchema(); final JsonPointer schemaPointer = tree.getPointer(); LogLevel.FATAL); ptr = schemaPointer.append(JsonPointer.of(keyword, index)); newData = data.withSchema(tree.setPointer(ptr)); processor.process(subReport, newData); fullReport.put(ptr.toString(), subReport.asJson());
throws ProcessingException final SchemaTree tree = data.getSchema(); final JsonPointer schemaPointer = tree.getPointer(); final JsonNode schemas = tree.getNode().get(keyword); LogLevel.FATAL); ptr = schemaPointer.append(JsonPointer.of(keyword, index)); newData = data.withSchema(tree.setPointer(ptr)); processor.process(subReport, newData); fullReport.put(ptr.toString(), subReport.asJson());
throws ProcessingException final JsonPointer ptr = data.getInstance().getPointer(); final SchemaURI schemaURI = new SchemaURI(data.getSchema());