Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2013, Francis Galiegue <fgaliegue@gmail.com>
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the Lesser GNU General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * Lesser GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 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.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();
         }
     };
 
     private final Processor<ValueHolder<SchemaTree>, ValueHolder<SchemaTree>> processor;

    
Constructor

Parameters:
cfg the validation configuration to use
 
     public SyntaxValidator(final ValidationConfiguration cfg)
     {
             map = new ProcessorMap<JsonRefValueHolder<SchemaTree>, ValueHolder<SchemaTree>>();
 
         final SyntaxProcessor byDefault
             = new SyntaxProcessor(cfg.getDefaultLibrary().getSyntaxCheckers());
 
         map.setDefaultProcessor(byDefault);
 
         final Map<JsonRef,Librarylibraries = cfg.getLibraries();
 
         JsonRef ref;
         SyntaxProcessor syntaxProcessor;
         Dictionary<SyntaxCheckerdict;
 
         for (final Map.Entry<JsonRefLibraryentrylibraries.entrySet()) {
             ref = entry.getKey();
             dict = entry.getValue().getSyntaxCheckers();
             syntaxProcessor = new SyntaxProcessor(dict);
             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