/** * Build a {@link JsonSchema} instance * * @param schema the schema * @param pointer the pointer into the schema * @return a new {@link JsonSchema} * @throws ProcessingException resolving the pointer against the schema * leads to a {@link MissingNode} * @throws NullPointerException the schema or pointer is null */ JsonSchema buildJsonSchema(final JsonNode schema, final JsonPointer pointer) throws ProcessingException { final SchemaTree tree = loader.load(schema).setPointer(pointer); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }
/** * Add a {@code $schema} and matching library to this configuration * * @param uri the value for {@code $schema} * @param library the library * @return this * @throws NullPointerException URI us null or library is null * @throws IllegalArgumentException string is not a URI, or not an absolute * JSON Reference; or a library already exists at this URI. */ public ValidationConfigurationBuilder addLibrary(final String uri, final Library library) { final JsonRef ref; try { ref = JsonRef.fromString(uri); } catch (JsonReferenceException e) { throw new IllegalArgumentException(e.getMessage()); } BUNDLE.checkArgumentPrintf(ref.isAbsolute(), "refProcessing.uriNotAbsolute", ref); BUNDLE.checkNotNull(library, "nullLibrary"); BUNDLE.checkArgumentPrintf(libraries.put(ref, library) == null, "dupLibrary", ref); return this; }
@Test public void illegalURIThrowsAnException() { final String input = "+24:"; try { JsonRef.fromString(input); fail("No exception thrown!!"); } catch (JsonReferenceException e) { final ProcessingMessage message = e.getProcessingMessage(); assertMessage(message) .hasMessage(BUNDLE.printf("jsonRef.invalidURI", input)) .hasField("input", input) .hasField("exceptionClass", URISyntaxException.class.getName()); } } }
/** * Build a {@link JsonSchema} instance * * @param uri the URI to load the schema from * @return a {@link JsonSchema} * @throws ProcessingException invalid URI, or URI did not resolve to a * JSON Schema * @throws NullPointerException URI is null */ JsonSchema buildJsonSchema(final String uri) throws ProcessingException { final JsonRef ref = JsonRef.fromString(uri); if (!ref.isLegal()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("illegalJsonRef"))); final SchemaTree tree = loader.get(ref.getLocator()).setPointer(ref.getPointer()); if (tree.getNode().isMissingNode()) throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("danglingRef"))); return new JsonSchemaImpl(processor, tree, reportProvider); }
private static URI getLocator(final String input) { final JsonRef ref; try { ref = JsonRef.fromString(input); } catch (JsonReferenceException e) { throw new IllegalArgumentException(e.getMessage()); } BUNDLE.checkArgumentPrintf(ref.isAbsolute(), "jsonRef.notAbsolute", ref); return ref.getLocator(); } }
/** * Build a JSON Reference from a string input * * @param s the string * @return the reference * @throws JsonReferenceException string is not a valid URI * @throws NullPointerException provided string is null */ public static JsonRef fromString(final String s) throws JsonReferenceException { BUNDLE.checkNotNull(s, "jsonRef.nullInput"); try { return fromURI(new URI(s)); } catch (URISyntaxException e) { throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("jsonRef.invalidURI")) .putArgument("input", s), e); } }
private static URI getLocator(final String input) { final JsonRef ref; try { ref = JsonRef.fromString(input); } catch (JsonReferenceException e) { throw new IllegalArgumentException(e.getMessage()); } BUNDLE.checkArgumentPrintf(ref.isAbsolute(), "jsonRef.notAbsolute", ref); return ref.getLocator(); } }
/** * Build a JSON Reference from a string input * * @param s the string * @return the reference * @throws JsonReferenceException string is not a valid URI * @throws NullPointerException provided string is null */ public static JsonRef fromString(final String s) throws JsonReferenceException { BUNDLE.checkNotNull(s, "jsonRef.nullInput"); try { return fromURI(new URI(s)); } catch (URISyntaxException e) { throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("jsonRef.invalidURI")) .putArgument("input", s), e); } }
private static URI getLocator(final String input) { final JsonRef ref; try { ref = JsonRef.fromString(input); } catch (JsonReferenceException e) { throw new IllegalArgumentException(e.getMessage()); } BUNDLE.checkArgumentPrintf(ref.isAbsolute(), "jsonRef.notAbsolute", ref); return ref.getLocator(); } }
/** * Build a JSON Reference from a string input * * @param s the string * @return the reference * @throws JsonReferenceException string is not a valid URI * @throws NullPointerException provided string is null */ public static JsonRef fromString(final String s) throws JsonReferenceException { BUNDLE.checkNotNull(s, "jsonRef.nullInput"); try { return fromURI(new URI(s)); } catch (URISyntaxException e) { throw new JsonReferenceException(new ProcessingMessage() .setMessage(BUNDLE.getMessage("jsonRef.invalidURI")) .putArgument("input", s), e); } }