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.load;
 
 
 import java.net.URI;
 import java.util.Map;
 
 import static com.github.fge.jsonschema.messages.RefProcessingMessages.*;

Class to fetch JSON documents

This uses a map of URIDownloader instances to fetch the contents of a URI as an java.io.InputStream, then tries and turns this content into JSON using an com.fasterxml.jackson.databind.ObjectMapper.

Normally, you will never use this class directly.

 
 public final class URIManager
 {
    
Our object reader
 
     private static final ObjectReader READER = JacksonUtils.getReader();
 
     private final Map<StringURIDownloaderdownloaders;
 
     private final Map<URIURIschemaRedirects;
 
     public URIManager()
     {
         this(LoadingConfiguration.byDefault());
     }
 
     public URIManager(final LoadingConfiguration cfg)
     {
          = cfg.getDownloaders().entries();
          = cfg.getSchemaRedirects();
     }

    
Get the content at a given URI as a com.fasterxml.jackson.databind.JsonNode

Parameters:
uri the URI
Returns:
the content
Throws:
com.github.fge.jsonschema.exceptions.ProcessingException scheme is not registered, failed to get content, or content is not JSON
 
     public JsonNode getContent(final URI uri)
         throws ProcessingException
     {
         Preconditions.checkNotNull(uri"null URI");
 
         final URI target = .containsKey(uri)
             ? .get(uri) : uri;
 
         final ProcessingMessage msg = new ProcessingMessage()
             .put("uri"uri);
 
         if (!target.isAbsolute())
             throw new ProcessingException(msg.message());
 
         final String scheme = target.getScheme();
 
         final URIDownloader downloader = .get(scheme);
 
         if (downloader == null)
             throw new ProcessingException(msg.message()
                 .put("scheme"scheme));
        final InputStream in;
        try {
            in = downloader.fetch(target);
            return .readTree(in);
        } catch (JsonProcessingException e) {
            throw new ProcessingException(msg.message()
                .put("parsingMessage"e.getOriginalMessage()));
        } catch (IOException e) {
            throw new ProcessingException(msg.message()
                .put("exceptionMessage"e.getMessage()));
        }
    }
New to GrepCode? Check out our FAQ X