Package org.OpenGeoPortal.Download.Config

Source Code of org.OpenGeoPortal.Download.Config.ConfigRetriever

package org.OpenGeoPortal.Download.Config;

import java.io.File;
import java.io.IOException;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;

/**
* an abstract class for reading a JSON config file
* @author chris
*
*/
public abstract class ConfigRetriever {
  public JsonNode configContents = null;
  Resource resource;
  protected final Logger logger = LoggerFactory.getLogger(this.getClass());
 
  public void setResource(Resource resource){
    this.resource = resource;
  }
 
  /**
   * reads the JSON file into a string
   * @return a string containing the JSON config object
   * @throws java.io.IOException
   */
  public File loadConfigFile() throws java.io.IOException {
    File configFile = resource.getFile();
    return configFile;
  }
 
  /**
   * parses the JSON string into a Jackson JsonNode, stores it in the property configContents
   * @throws IOException
   */
  public void readConfigFile() throws IOException{
    if (configContents == null){
      ObjectMapper mapper = new ObjectMapper();
      JsonNode rootNode = mapper.readValue(this.loadConfigFile(), JsonNode.class);     
      JsonNode jsonResponse = rootNode.path("config");
      this.configContents = jsonResponse;
    }
  }

}
TOP

Related Classes of org.OpenGeoPortal.Download.Config.ConfigRetriever

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.