Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com)
   *
   * This software is dual-licensed under:
   *
   * - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
   *   later version;
   * - the Apache Software License (ASL) version 2.0.
   *
  * The text of this file and of both licenses is available at the root of this
  * project or, if you have the jar distribution, in directory META-INF/, under
  * the names LGPL-3.0.txt and ASL-2.0.txt respectively.
  *
  * Direct link to the sources:
  *
  * - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
  * - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
  */
 
 package com.github.fge.jsonschema.processors.syntax;
 
 
 import java.util.Map;

Standalone syntax validator

This is the syntax validator built, and returned, by com.github.fge.jsonschema.main.JsonSchemaFactory.getSyntaxValidator(). It can be used to validate schemas independently of the validation chain. Among other features, it detects $schema and acts accordingly.

Note that the reports used are always com.github.fge.jsonschema.core.report.ListProcessingReports.

 
 // TODO REMOVE
 public final class SyntaxValidator
 {
     private static final Function<ValueHolder<SchemaTree>, JsonRefFUNCTION
         = new Function<ValueHolder<SchemaTree>, JsonRef>()
     {
         @Override
         public JsonRef apply(final ValueHolder<SchemaTreeinput)
         {
             return input.getValue().getDollarSchema();
         }
     };
 
         processor;

    
Constructor

Parameters:
cfg the validation configuration to use
 
     public SyntaxValidator(final ValidationConfiguration cfg)
     {
         final MessageBundle syntaxMessages = cfg.getSyntaxMessages();
             map = new ProcessorMap<JsonRefValueHolder<SchemaTree>, ValueHolder<SchemaTree>>();
 
         Dictionary<SyntaxCheckerdict;
         dict = cfg.getDefaultLibrary().getSyntaxCheckers();
 
         final SyntaxProcessor byDefault = new SyntaxProcessor(
             cfg.getSyntaxMessages(), dict);
 
         map.setDefaultProcessor(byDefault);
 
         final Map<JsonRef,Librarylibraries = cfg.getLibraries();
 
         JsonRef ref;
         SyntaxProcessor syntaxProcessor;
 
         for (final Map.Entry<JsonRefLibraryentrylibraries.entrySet()) {
             ref = entry.getKey();
             dict = entry.getValue().getSyntaxCheckers();
             syntaxProcessor = new SyntaxProcessor(syntaxMessagesdict);
             map.addEntry(refsyntaxProcessor);
         }
         = map.getProcessor();
    }

    
Tell whether a schema is valid

Parameters:
schema the schema
Returns:
true if the schema is valid
    public boolean schemaIsValid(final JsonNode schema)
    {
        final ProcessingReport report = new DevNullProcessingReport();
        return getResult(schemareport).isSuccess();
    }

    
Validate a schema and return a report

Parameters:
schema the schema
Returns:
a report
    public ProcessingReport validateSchema(final JsonNode schema)
    {
        final ProcessingReport report = new ListProcessingReport();
        return getResult(schemareport).getReport();
    }

    
Return the underlying processor

You can use this processor to chain it with your own.

Returns:
a processor performing full syntax validation
    {
        return ;
    }
    private ProcessingResult<ValueHolder<SchemaTree>> getResult(final JsonNode schema,
        final ProcessingReport report)
    {
        final ValueHolder<SchemaTreeholder = holder(schema);
        return ProcessingResult.uncheckedResult(reportholder);
    }
    private static ValueHolder<SchemaTreeholder(final JsonNode node)
    {
        return ValueHolder.<SchemaTree>hold("schema",
            new CanonicalSchemaTree(node));
    }
New to GrepCode? Check out our FAQ X