public class PreferencesReader extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private boolean |
defaults |
private java.io.File |
file |
private javax.xml.stream.XMLStreamReader |
parser |
private java.io.Reader |
reader |
private java.util.SortedMap<java.lang.String,Setting<?>> |
settings |
private int |
version |
Constructor and Description |
---|
PreferencesReader(java.io.File file,
boolean defaults)
Constructs a new
PreferencesReader . |
PreferencesReader(java.io.Reader reader,
boolean defaults)
Constructs a new
PreferencesReader . |
Modifier and Type | Method and Description |
---|---|
private void |
doParse() |
java.util.SortedMap<java.lang.String,Setting<?>> |
getSettings()
Return the parsed preferences as a settings map
|
int |
getVersion()
Return the version from the XML root element.
|
private boolean |
isNil()
Check if the current element is nil (meaning the value of the setting is null).
|
private void |
jumpToEnd() |
void |
parse()
Parse preferences.
|
private java.util.List<java.lang.String> |
parseInnerList() |
private java.util.Map<java.lang.String,java.lang.String> |
parseMap() |
private void |
parseRoot() |
private void |
parseToplevelList() |
private void |
throwException(java.lang.String msg)
Throw XmlStreamParsingException with line and column number.
|
static void |
validateXML(java.io.File f)
Validate the XML.
|
static void |
validateXML(java.io.Reader in)
Validate the XML.
|
private javax.xml.stream.XMLStreamReader parser
private int version
private final java.io.Reader reader
private final java.io.File file
private final boolean defaults
public PreferencesReader(java.io.File file, boolean defaults)
PreferencesReader
.file
- the filedefaults
- true when reading from the cache file for default preferences,
false for the regular preferences config filepublic PreferencesReader(java.io.Reader reader, boolean defaults)
PreferencesReader
.reader
- the Reader
defaults
- true when reading from the cache file for default preferences,
false for the regular preferences config filepublic static void validateXML(java.io.File f) throws java.io.IOException, org.xml.sax.SAXException
f
- the filejava.io.IOException
- if any I/O error occursorg.xml.sax.SAXException
- if any SAX error occurspublic static void validateXML(java.io.Reader in) throws java.io.IOException, org.xml.sax.SAXException
in
- the Reader
java.io.IOException
- if any I/O error occursorg.xml.sax.SAXException
- if any SAX error occurspublic java.util.SortedMap<java.lang.String,Setting<?>> getSettings()
public int getVersion()
public void parse() throws javax.xml.stream.XMLStreamException, java.io.IOException
javax.xml.stream.XMLStreamException
- if any XML parsing error occursjava.io.IOException
- if any I/O error occursprivate void doParse() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private void parseRoot() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private void jumpToEnd() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private void parseToplevelList() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private java.util.List<java.lang.String> parseInnerList() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private java.util.Map<java.lang.String,java.lang.String> parseMap() throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
private boolean isNil()
private void throwException(java.lang.String msg) throws XmlStreamParsingException
msg
- the error messageXmlStreamParsingException
- always