public class JsonConfig extends Object
| Constructor and Description |
|---|
JsonConfig()
Creates a config with only the system settings
|
JsonConfig(File jsonFile)
Creates a JSON configuration from the specified file
|
JsonConfig(InputStream jsonIn)
Creates a JSON configuration from the specified input stream
|
JsonConfig(String jsonString)
Create a JSON configuration from the specified input string
|
| Modifier and Type | Method and Description |
|---|---|
static File |
backupSystemFile()
Performs a backup on the system-wide configuration file from the default
config dir if it exists.
|
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
|
Map<String,JsonConfigHelper> |
getJsonMap(String path)
Gets 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
|
static File |
getSystemFile()
Gets the system-wide configuration file from the default config dir.
|
boolean |
isConfigured()
Tests whether or not the system-config has been properly configured.
|
boolean |
isOutdated()
To check if configuration file is outdated
|
void |
set(String path,
String value,
boolean system)
Sets the value of the specified node.
|
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() |
public JsonConfig()
throws IOException
IOException - if these was an error parsing or reading the system
JSON filepublic JsonConfig(File jsonFile) throws IOException
jsonFile - a JSON fileIOException - if there was an error parsing or reading the filepublic JsonConfig(InputStream jsonIn) throws IOException
jsonIn - a JSON streamIOException - if there was an error parsing or reading the streampublic JsonConfig(String jsonString) throws IOException
jsonString - IOExceptionpublic String get(String path)
path - XPath to nodepublic String get(String path, String defaultValue)
path - XPath to nodedefaultValue - value to return if the node was not foundpublic List<Object> getList(String path)
path - XPath to nodepublic Map<String,Object> getMap(String path)
path - XPath to nodepublic Map<String,Object> getMapWithChild(String path)
path - XPath to nodepublic void set(String path, String value, boolean system)
path - XPath to nodevalue - value to setsystem - set the value in the system configurationpublic void store(Writer writer) throws IOException
writer - a writerIOException - if there was an error writing the configurationpublic void store(Writer writer, boolean pretty) throws IOException
writer - a writerpretty - use pretty printerIOException - if there was an error writing the configurationpublic static File backupSystemFile() throws IOException
IOException - if there was an error reading or writing either filepublic static File getSystemFile() throws IOException
IOException - if there was an error reading or writing the system
configuration filepublic Map<String,JsonConfigHelper> getJsonMap(String path)
path - XPath to nodepublic boolean isConfigured()
true if configured, false if still
using defaultspublic boolean isOutdated()
true if outdated, false otherwiseCopyright © 2009-2013. All Rights Reserved.