|
||||||||||
| 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(java.io.File jsonFile)
Creates a JSON configuration from the specified file |
|
JsonConfigHelper(java.io.InputStream jsonIn)
Creates a JSON configuration from the specified input stream |
|
JsonConfigHelper(java.util.Map<java.lang.String,java.lang.Object> rootNode)
Creates a JSON configuration from a map. |
|
JsonConfigHelper(java.io.Reader jsonReader)
Creates a JSON configuration from the specified reader |
|
JsonConfigHelper(java.lang.String jsonContent)
Creates a JSON configuration from the specified string |
|
| Method Summary | |
|---|---|
java.lang.String |
get(java.lang.String path)
Gets the value of the specified node |
java.lang.String |
get(java.lang.String path,
java.lang.String defaultValue)
Gets the value of the specified node, with a specified default if the not was not found |
java.util.List<JsonConfigHelper> |
getJsonList(java.lang.String path)
Get list of JsonConfigHelper of the specified node |
java.util.Map<java.lang.String,JsonConfigHelper> |
getJsonMap(java.lang.String path)
Get the JSON Map of the specified node |
java.util.List<java.lang.Object> |
getList(java.lang.String path)
Gets values of the specified node as a list. |
java.util.Map<java.lang.String,java.lang.Object> |
getMap(java.lang.String path)
Gets a map of the child nodes of the specified node |
java.util.Map<java.lang.String,java.lang.Object> |
getMapWithChild(java.lang.String path)
Gets a map of the child (and the 2nd level children) nodes of the specified node |
java.lang.String |
getPlainText(java.lang.String path,
java.lang.String defaultValue)
Get the value of specified node, with a specified default if it's not found |
void |
move(java.lang.String source,
java.lang.String dest)
Move node from one path to another path in the JSON |
void |
moveAfter(java.lang.String path,
java.lang.String refPath)
Move node to a node after the specified node |
void |
moveBefore(java.lang.String path,
java.lang.String refPath)
Move node to a node before the specified node |
void |
removePath(java.lang.String path)
Remove specified path from json |
void |
set(java.lang.String path,
java.lang.String value)
Sets the value of the specified node. |
void |
setJsonList(java.lang.String path,
java.util.List<JsonConfigHelper> jsonList)
Set Map on the specified path |
void |
setJsonMap(java.lang.String path,
java.util.Map<java.lang.String,JsonConfigHelper> map)
Set Map on the specified path |
void |
setMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> map)
Set map with its child |
void |
setMultiMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> json)
Set Multiple nested map on the specified path |
void |
store(java.io.Writer writer)
Serialises the current state of the JSON configuration to the specified writer. |
void |
store(java.io.Writer writer,
boolean pretty)
Serialises the current state of the JSON configuration to the specified writer. |
java.lang.String |
toString()
Convert Json to String |
java.lang.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(java.util.Map<java.lang.String,java.lang.Object> rootNode)
rootNode - a JSON structured map
public JsonConfigHelper(java.lang.String jsonContent)
throws java.io.IOException
jsonContent - a JSON content string
java.io.IOException - if there was an error parsing or reading the content
public JsonConfigHelper(java.io.File jsonFile)
throws java.io.IOException
jsonFile - a JSON file
java.io.IOException - if there was an error parsing or reading the file
public JsonConfigHelper(java.io.InputStream jsonIn)
throws java.io.IOException
jsonIn - a JSON stream
java.io.IOException - if there was an error parsing or reading the stream
public JsonConfigHelper(java.io.Reader jsonReader)
throws java.io.IOException
jsonReader - a reader for a JSON file
java.io.IOException - if there was an error parsing or reading the reader| Method Detail |
|---|
public java.lang.String get(java.lang.String path)
path - XPath to node
public java.lang.String get(java.lang.String path,
java.lang.String defaultValue)
path - XPath to nodedefaultValue - value to return if the node was not found
public java.lang.String getPlainText(java.lang.String path,
java.lang.String defaultValue)
path - defaultValue -
public java.util.List<java.lang.Object> getList(java.lang.String path)
path - XPath to node
public java.util.Map<java.lang.String,java.lang.Object> getMap(java.lang.String path)
path - XPath to node
public java.util.List<JsonConfigHelper> getJsonList(java.lang.String path)
path - XPath to node
public java.util.Map<java.lang.String,JsonConfigHelper> getJsonMap(java.lang.String path)
path - XPath to node
public void setMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> map)
path - XPath to nodemap - node Map
public void setMultiMap(java.lang.String path,
java.util.Map<java.lang.String,java.lang.Object> json)
path - XPath to nodejson - node Map
public void setJsonMap(java.lang.String path,
java.util.Map<java.lang.String,JsonConfigHelper> map)
path - XPath to nodemap - node Map
public void setJsonList(java.lang.String path,
java.util.List<JsonConfigHelper> jsonList)
path - XPath to nodemap - node Mappublic java.util.Map<java.lang.String,java.lang.Object> getMapWithChild(java.lang.String path)
path - XPath to node
public void removePath(java.lang.String path)
path - to node
public void set(java.lang.String path,
java.lang.String value)
path - XPath to nodevalue - value to set
public void move(java.lang.String source,
java.lang.String dest)
source - XPath to nodedest - XPath to node
public void moveBefore(java.lang.String path,
java.lang.String refPath)
path - XPath to noderefPath - XPath to node
public void moveAfter(java.lang.String path,
java.lang.String refPath)
path - XPath to noderefPath - XPath to node
public void store(java.io.Writer writer)
throws java.io.IOException
writer - a writer
java.io.IOException - if there was an error writing the configuration
public void store(java.io.Writer writer,
boolean pretty)
throws java.io.IOException
writer - a writerpretty - use pretty printer
java.io.IOException - if there was an error writing the configurationpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.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 | |||||||||