Class PreferencesReader
- java.lang.Object
-
- org.openstreetmap.josm.data.preferences.PreferencesReader
-
public class PreferencesReader extends java.lang.Object
Loads preferences from XML.
-
-
Constructor Summary
Constructors Constructor Description PreferencesReader(java.io.File file, boolean defaults)Constructs a newPreferencesReader.PreferencesReader(java.io.Reader reader, boolean defaults)Constructs a newPreferencesReader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddoParse()java.util.SortedMap<java.lang.String,Setting<?>>getSettings()Return the parsed preferences as a settings mapintgetVersion()Return the version from the XML root element.private booleanisNil()Check if the current element is nil (meaning the value of the setting is null).private voidjumpToEnd()voidparse()Parse preferences.private java.util.List<java.lang.String>parseInnerList()private java.util.Map<java.lang.String,java.lang.String>parseMap()private voidparseRoot()private voidparseToplevelList()private voidthrowException(java.lang.String msg)Throw XmlStreamParsingException with line and column number.static voidvalidateXML(java.io.File f)Validate the XML.static voidvalidateXML(java.io.Reader in)Validate the XML.
-
-
-
Constructor Detail
-
PreferencesReader
public PreferencesReader(java.io.File file, boolean defaults)
Constructs a newPreferencesReader.- Parameters:
file- the filedefaults- true when reading from the cache file for default preferences, false for the regular preferences config file
-
PreferencesReader
public PreferencesReader(java.io.Reader reader, boolean defaults)
Constructs a newPreferencesReader.- Parameters:
reader- theReaderdefaults- true when reading from the cache file for default preferences, false for the regular preferences config file
-
-
Method Detail
-
validateXML
public static void validateXML(java.io.File f) throws java.io.IOException, org.xml.sax.SAXException
Validate the XML.- Parameters:
f- the file- Throws:
java.io.IOException- if any I/O error occursorg.xml.sax.SAXException- if any SAX error occurs
-
validateXML
public static void validateXML(java.io.Reader in) throws java.io.IOException, org.xml.sax.SAXException
Validate the XML.- Parameters:
in- theReader- Throws:
java.io.IOException- if any I/O error occursorg.xml.sax.SAXException- if any SAX error occurs
-
getSettings
public java.util.SortedMap<java.lang.String,Setting<?>> getSettings()
Return the parsed preferences as a settings map- Returns:
- the parsed preferences as a settings map
-
getVersion
public int getVersion()
Return the version from the XML root element. (Represents the JOSM version when the file was written.)- Returns:
- the version
-
parse
public void parse() throws javax.xml.stream.XMLStreamException, java.io.IOException
Parse preferences.- Throws:
javax.xml.stream.XMLStreamException- if any XML parsing error occursjava.io.IOException- if any I/O error occurs
-
doParse
private void doParse() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseRoot
private void parseRoot() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
jumpToEnd
private void jumpToEnd() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseToplevelList
private void parseToplevelList() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseInnerList
private java.util.List<java.lang.String> parseInnerList() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
parseMap
private java.util.Map<java.lang.String,java.lang.String> parseMap() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
isNil
private boolean isNil()
Check if the current element is nil (meaning the value of the setting is null).- Returns:
- true, if the current element is nil
- See Also:
- Nillable Attribute on MS Developer Network
-
throwException
private void throwException(java.lang.String msg) throws XmlStreamParsingException
Throw XmlStreamParsingException with line and column number. Only use this for errors that should not be possible after schema validation.- Parameters:
msg- the error message- Throws:
XmlStreamParsingException- always
-
-