|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.googlecode.fascinator.common.JsonConfigHelper
public class JsonConfigHelper
Helper class for working with JSON configuration. Uses the JXPath library to use XPath syntax to access JSON nodes.
| Constructor Summary | |
|---|---|
JsonConfigHelper()
Creates an empty JSON configuration |
|
JsonConfigHelper(File jsonFile)
Creates a JSON configuration from the specified file |
|
JsonConfigHelper(InputStream jsonIn)
Creates a JSON configuration from the specified input stream |
|
JsonConfigHelper(Map<String,Object> rootNode)
Creates a JSON configuration from a map. |
|
JsonConfigHelper(Reader jsonReader)
Creates a JSON configuration from the specified reader |
|
JsonConfigHelper(String jsonContent)
Creates a JSON configuration from the specified string |
|
| Method Summary | |
|---|---|
String |
get(String path)
Gets the value of the specified node |
String |
get(String path,
String defaultValue)
Gets the value of the specified node, with a specified default if the not was not found |
List<JsonConfigHelper> |
getJsonList(String path)
Get list of JsonConfigHelper of the specified node |
Map<String,JsonConfigHelper> |
getJsonMap(String path)
Get the JSON Map of the specified node |
List<Object> |
getList(String path)
Gets values of the specified node as a list. |
Map<String,Object> |
getMap(String path)
Gets a map of the child nodes of the specified node |
Map<String,Object> |
getMapWithChild(String path)
Gets a map of the child (and the 2nd level children) nodes of the specified node |
String |
getPlainText(String path,
String defaultValue)
Get the value of specified node, with a specified default if it's not found |
void |
move(String source,
String dest)
Move node from one path to another path in the JSON |
void |
moveAfter(String path,
String refPath)
Move node to a node after the specified node |
void |
moveBefore(String path,
String refPath)
Move node to a node before the specified node |
void |
removePath(String path)
Remove specified path from json |
void |
set(String path,
String value)
Sets the value of the specified node. |
void |
setJsonList(String path,
List<JsonConfigHelper> jsonList)
Set Map on the specified path |
void |
setJsonMap(String path,
Map<String,JsonConfigHelper> map)
Set Map on the specified path |
void |
setMap(String path,
Map<String,Object> map)
Set map with its child |
void |
setMultiMap(String path,
Map<String,Object> json)
Set Multiple nested map on the specified path |
void |
store(Writer writer)
Serialises the current state of the JSON configuration to the specified writer. |
void |
store(Writer writer,
boolean pretty)
Serialises the current state of the JSON configuration to the specified writer. |
String |
toString()
Convert Json to String |
String |
toString(boolean pretty)
Convert Json to String |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JsonConfigHelper()
public JsonConfigHelper(Map<String,Object> rootNode)
rootNode - a JSON structured map
public JsonConfigHelper(String jsonContent)
throws IOException
jsonContent - a JSON content string
IOException - if there was an error parsing or reading the content
public JsonConfigHelper(File jsonFile)
throws IOException
jsonFile - a JSON file
IOException - if there was an error parsing or reading the file
public JsonConfigHelper(InputStream jsonIn)
throws IOException
jsonIn - a JSON stream
IOException - if there was an error parsing or reading the stream
public JsonConfigHelper(Reader jsonReader)
throws IOException
jsonReader - a reader for a JSON file
IOException - if there was an error parsing or reading the reader| Method Detail |
|---|
public String get(String path)
path - XPath to node
public String get(String path,
String defaultValue)
path - XPath to nodedefaultValue - value to return if the node was not found
public String getPlainText(String path,
String defaultValue)
path - defaultValue -
public List<Object> getList(String path)
path - XPath to node
public Map<String,Object> getMap(String path)
path - XPath to node
public List<JsonConfigHelper> getJsonList(String path)
path - XPath to node
public Map<String,JsonConfigHelper> getJsonMap(String path)
path - XPath to node
public void setMap(String path,
Map<String,Object> map)
path - XPath to nodemap - node Map
public void setMultiMap(String path,
Map<String,Object> json)
path - XPath to nodejson - node Map
public void setJsonMap(String path,
Map<String,JsonConfigHelper> map)
path - XPath to nodemap - node Map
public void setJsonList(String path,
List<JsonConfigHelper> jsonList)
path - XPath to nodemap - node Mappublic Map<String,Object> getMapWithChild(String path)
path - XPath to node
public void removePath(String path)
path - to node
public void set(String path,
String value)
path - XPath to nodevalue - value to set
public void move(String source,
String dest)
source - XPath to nodedest - XPath to node
public void moveBefore(String path,
String refPath)
path - XPath to noderefPath - XPath to node
public void moveAfter(String path,
String refPath)
path - XPath to noderefPath - XPath to node
public void store(Writer writer)
throws IOException
writer - a writer
IOException - if there was an error writing the configuration
public void store(Writer writer,
boolean pretty)
throws IOException
writer - a writerpretty - use pretty printer
IOException - if there was an error writing the configurationpublic String toString()
toString in class Objectpublic String toString(boolean pretty)
pretty - state to format the layout of the Json configuration file
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||