public static void main(final String... args) throws IOException, ProcessingException { final JsonNode good = Utils.loadResource("/fstab-good.json"); final JsonNode bad = Utils.loadResource("/fstab-bad.json"); final JsonNode bad2 = Utils.loadResource("/fstab-bad2.json"); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder() .addScheme("foobar", CustomDownloader.getInstance()).freeze(); final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder() .setLoadingConfiguration(cfg).freeze(); final JsonSchema schema = factory.getJsonSchema("foobar:/fstab.json#"); ProcessingReport report; report = schema.validate(good); System.out.println(report); report = schema.validate(bad); System.out.println(report); report = schema.validate(bad2); System.out.println(report); }
/** * A builder with the default configuration * * @see JsonSchemaFactory#newBuilder() */ JsonSchemaFactoryBuilder() { reportProvider = new ListReportProvider(LogLevel.INFO, LogLevel.FATAL); loadingCfg = LoadingConfiguration.byDefault(); validationCfg = ValidationConfiguration.byDefault(); }
.freeze(); LoadingConfigurationBuilder loadingConfigurationBuilder = LoadingConfiguration.newBuilder() .setURITranslatorConfiguration(uriTranslatorConfiguration); Map<String, URIDownloader> downloaders = loadingConfigurationBuilder.freeze().getDownloaderMap(); URIDownloader redirectingDownloader = new URIDownloader() { @Override
/** * Create a new schema loader with a given loading configuration * * @param cfg the configuration * @see LoadingConfiguration * @see LoadingConfigurationBuilder */ public SchemaLoader(final LoadingConfiguration cfg) { translator = new URITranslator(cfg.getTranslatorConfiguration()); dereferencing = cfg.getDereferencing(); manager = new URIManager(cfg); preloadedSchemas = ImmutableMap.copyOf(cfg.getPreloadedSchemas()); CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); if (cfg.getCacheSize() != -1) { builder.maximumSize(cfg.getCacheSize()); } cache = builder.build(new CacheLoader<URI, JsonNode>() { @Nonnull @Override public JsonNode load(@Nonnull final URI key) throws ProcessingException { return manager.getContent(key); } }); }
/** * Create a new schema loader with a given loading configuration * * @param cfg the configuration * @see LoadingConfiguration * @see LoadingConfigurationBuilder */ public SchemaLoader(final LoadingConfiguration cfg) { translator = new URITranslator(cfg.getTranslatorConfiguration()); dereferencing = cfg.getDereferencing(); manager = new URIManager(cfg); preloadedSchemas = ImmutableMap.copyOf(cfg.getPreloadedSchemas()); final CacheBuilder<Object, Object> cacheBuilder = cfg.getEnableCache() ? CacheBuilder.newBuilder() : CacheBuilder.from(CacheBuilderSpec.disableCaching()); cache = cacheBuilder.build(new CacheLoader<URI, JsonNode>() { @Nonnull @Override public JsonNode load(@Nonnull final URI key) throws ProcessingException { return manager.getContent(key); } }); }
public URIManager(final LoadingConfiguration cfg) { downloaders = cfg.getDownloaderMap(); reader = cfg.getReader(); }
@Test public void registeringAndUnregisteringSchemeWorks() { final String scheme = "foo"; cfg.addScheme(scheme, downloader); assertNotNull(cfg.freeze().getDownloaderMap().get(scheme)); cfg.removeScheme(scheme); assertNull(cfg.freeze().getDownloaderMap().get(scheme)); }
/** * Freeze this configuration * * @return a frozen copy of this builder */ @Override public LoadingConfiguration freeze() { return new LoadingConfiguration(this); }
/** * Create a frozen loading configuration from a thawed one * * @param builder the thawed configuration * @see LoadingConfigurationBuilder#freeze() */ LoadingConfiguration(final LoadingConfigurationBuilder builder) { downloaders = builder.downloaders.build(); translatorCfg = builder.translatorCfg; dereferencing = builder.dereferencing; preloadedSchemas = ImmutableMap.copyOf(builder.preloadedSchemas); parserFeatures = EnumSet.copyOf(builder.parserFeatures); reader = buildReader(); enableCache = builder.enableCache; }
@Test(dataProvider = "schemaVersions", enabled = false) public void basicConfigurationContainsCoreSchemas( final SchemaVersion version) { final Map<URI, JsonNode> map = cfg.freeze().getPreloadedSchemas(); final JsonNode actual = map.get(version.getLocation()); final JsonNode expected = version.getSchema(); assertTrue(JsonNumEquals.getInstance().equivalent(actual, expected)); }
/** * Create a new schema loader with a given loading configuration * * @param cfg the configuration * @see LoadingConfiguration * @see LoadingConfigurationBuilder */ public SchemaLoader(final LoadingConfiguration cfg) { translator = new URITranslator(cfg.getTranslatorConfiguration()); dereferencing = cfg.getDereferencing(); manager = new URIManager(cfg); preloadedSchemas = ImmutableMap.copyOf(cfg.getPreloadedSchemas()); CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); if (cfg.getCacheSize() != -1) { builder.maximumSize(cfg.getCacheSize()); } cache = builder.build(new CacheLoader<URI, JsonNode>() { @Nonnull @Override public JsonNode load(@Nonnull final URI key) throws ProcessingException { return manager.getContent(key); } }); }
public URIManager(final LoadingConfiguration cfg) { downloaders = cfg.getDownloaderMap(); reader = cfg.getReader(); }
/** * Freeze this configuration * * @return a frozen copy of this builder */ @Override public LoadingConfiguration freeze() { return new LoadingConfiguration(this); }
/** * Create a frozen loading configuration from a thawed one * * @param builder the thawed configuration * @see LoadingConfigurationBuilder#freeze() */ LoadingConfiguration(final LoadingConfigurationBuilder builder) { downloaders = builder.downloaders.build(); translatorCfg = builder.translatorCfg; dereferencing = builder.dereferencing; preloadedSchemas = ImmutableMap.copyOf(builder.preloadedSchemas); parserFeatures = EnumSet.copyOf(builder.parserFeatures); reader = buildReader(); cacheSize = builder.cacheSize; }
public static void main(final String... args) throws IOException, ProcessingException { final JsonNode fstabSchema = Utils.loadResource("/fstab-inline.json"); final JsonNode good = Utils.loadResource("/fstab-good.json"); final JsonNode bad = Utils.loadResource("/fstab-bad.json"); final JsonNode bad2 = Utils.loadResource("/fstab-bad2.json"); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder() .dereferencing(Dereferencing.INLINE).freeze(); final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder() .setLoadingConfiguration(cfg).freeze(); final JsonSchema schema = factory.getJsonSchema(fstabSchema); ProcessingReport report; report = schema.validate(good); System.out.println(report); report = schema.validate(bad); System.out.println(report); report = schema.validate(bad2); System.out.println(report); } }
public URIManager(final LoadingConfiguration cfg) { downloaders = cfg.getDownloaderMap(); reader = cfg.getReader(); }
/** * Create a new schema loader with the default loading configuration */ public SchemaLoader() { this(LoadingConfiguration.byDefault()); }
/** * Freeze this configuration * * @return a frozen copy of this builder */ @Override public LoadingConfiguration freeze() { return new LoadingConfiguration(this); }
/** * Create a frozen loading configuration from a thawed one * * @param builder the thawed configuration * @see LoadingConfigurationBuilder#freeze() */ LoadingConfiguration(final LoadingConfigurationBuilder builder) { downloaders = builder.downloaders.build(); translatorCfg = builder.translatorCfg; dereferencing = builder.dereferencing; preloadedSchemas = ImmutableMap.copyOf(builder.preloadedSchemas); parserFeatures = EnumSet.copyOf(builder.parserFeatures); reader = buildReader(); cacheSize = builder.cacheSize; }
public static void main(final String... args) throws IOException, ProcessingException { final JsonNode good = Utils.loadResource("/fstab-good.json"); final JsonNode bad = Utils.loadResource("/fstab-bad.json"); final JsonNode bad2 = Utils.loadResource("/fstab-bad2.json"); final URITranslatorConfiguration translatorCfg = URITranslatorConfiguration.newBuilder() .addSchemaRedirect(FROM, TO).freeze(); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder() .setURITranslatorConfiguration(translatorCfg).freeze(); final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder() .setLoadingConfiguration(cfg).freeze(); final JsonSchema schema = factory.getJsonSchema(FROM); ProcessingReport report; report = schema.validate(good); System.out.println(report); report = schema.validate(bad); System.out.println(report); report = schema.validate(bad2); System.out.println(report); } }