Package com.sk89q.util.yaml
Class YAMLProcessor
java.lang.Object
com.sk89q.util.yaml.YAMLNode
com.sk89q.util.yaml.YAMLProcessor
YAML configuration loader. To use this class, construct it with path to
a file and call its load() method. For specifying node paths in the
various get*() methods, they support SK's path notation, allowing you to
select child nodes by delimiting node names with periods.
For example, given the following configuration file:
members: - Hollie - Jason - Bobo - Aya - Tetsu worldguard: fire: spread: false blocks: [cloth, rock, glass] sturmeh: cool: false eats: babies: true
Calling code could access sturmeh's baby eating state by using
getBoolean("sturmeh.eats.babies", false)
. For lists, there are
methods such as getStringList
that will return a type safe list.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
protected final File
protected YAMLFormat
protected String
static final String
protected final org.yaml.snakeyaml.Yaml
-
Constructor Summary
ConstructorDescriptionYAMLProcessor
(File file, boolean writeDefaults) YAMLProcessor
(File file, boolean writeDefaults, YAMLFormat format) -
Method Summary
Modifier and TypeMethodDescriptiongetComment
(String key) Returns a root-level comment.Returns root-level comments.static YAMLNode
getEmptyNode
(boolean writeDefaults) Get an empty ConfigurationNode for using as a default in methods that select a node from a node list.Return the set header.void
load()
Loads the configuration file.boolean
save()
Saves the configuration to disk.void
setComment
(String key, String comment) void
setComment
(String key, String... comment) Set a root-level comment.void
setComments
(Map<String, String> comments) Set root-level comments from a map.void
Set the header for the file.void
Set the header for the file as a series of lines that are terminated by a new line sequence.Methods inherited from class com.sk89q.util.yaml.YAMLNode
addNode, clear, getBlockVector2List, getBoolean, getBoolean, getBooleanList, getDouble, getDouble, getDoubleList, getInt, getInt, getIntList, getKeys, getList, getMap, getNode, getNodeList, getNodes, getProperty, getString, getString, getStringList, getVector, getVector, getVector2, getVector2List, getVectorList, removeProperty, setProperty, setWriteDefaults, writeDefaults
-
Field Details
-
LINE_BREAK
-
COMMENT_CHAR
public static final char COMMENT_CHAR- See Also:
-
yaml
protected final org.yaml.snakeyaml.Yaml yaml -
file
-
header
-
format
-
-
Constructor Details
-
YAMLProcessor
-
YAMLProcessor
-
-
Method Details
-
load
Loads the configuration file.- Throws:
IOException
- on load error
-
setHeader
Set the header for the file as a series of lines that are terminated by a new line sequence.- Parameters:
headerLines
- header lines to prepend
-
setHeader
Set the header for the file. A header can be provided to prepend the YAML data output on configuration save. The header is printed raw and so must be manually commented if used. A new line will be appended after the header, however, if a header is provided.- Parameters:
header
- header to prepend
-
getHeader
Return the set header.- Returns:
- the header text
-
save
public boolean save()Saves the configuration to disk. All errors are clobbered.- Returns:
- true if it was successful
-
getInputStream
- Throws:
IOException
-
getOutputStream
- Throws:
IOException
-
getComment
Returns a root-level comment.- Parameters:
key
- the property key- Returns:
- the comment or
null
-
setComment
-
setComment
Set a root-level comment.- Parameters:
key
- the property keycomment
- the comment. May benull
, in which case the comment is removed.
-
getComments
Returns root-level comments.- Returns:
- map of root-level comments
-
setComments
Set root-level comments from a map.- Parameters:
comments
- comment map
-
getEmptyNode
Get an empty ConfigurationNode for using as a default in methods that select a node from a node list.- Parameters:
writeDefaults
- true to write default values when a property is requested that doesn't exist- Returns:
- a node
-