Class PreferencesReader
- java.lang.Object
-
- org.openstreetmap.josm.data.preferences.PreferencesReader
-
public class PreferencesReader extends Object
Loads preferences from XML.
-
-
Constructor Summary
Constructors Constructor Description PreferencesReader(File file, boolean defaults)
Constructs a newPreferencesReader
.PreferencesReader(Reader reader, boolean defaults)
Constructs a newPreferencesReader
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
doParse()
SortedMap<String,Setting<?>>
getSettings()
Return the parsed preferences as a settings mapint
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 List<String>
parseInnerList()
private Map<String,String>
parseMap()
private void
parseRoot()
private void
parseToplevelList()
private void
throwException(String msg)
Throw XmlStreamParsingException with line and column number.static void
validateXML(File f)
Validate the XML.static void
validateXML(Reader in)
Validate the XML.
-
-
-
Constructor Detail
-
PreferencesReader
public PreferencesReader(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(Reader reader, boolean defaults)
Constructs a newPreferencesReader
.- Parameters:
reader
- theReader
defaults
- true when reading from the cache file for default preferences, false for the regular preferences config file
-
-
Method Detail
-
validateXML
public static void validateXML(File f) throws IOException, SAXException
Validate the XML.- Parameters:
f
- the file- Throws:
IOException
- if any I/O error occursSAXException
- if any SAX error occurs
-
validateXML
public static void validateXML(Reader in) throws IOException, SAXException
Validate the XML.- Parameters:
in
- theReader
- Throws:
IOException
- if any I/O error occursSAXException
- if any SAX error occurs
-
getSettings
public SortedMap<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 XMLStreamException, IOException
Parse preferences.- Throws:
XMLStreamException
- if any XML parsing error occursIOException
- if any I/O error occurs
-
doParse
private void doParse() throws XMLStreamException
- Throws:
XMLStreamException
-
parseRoot
private void parseRoot() throws XMLStreamException
- Throws:
XMLStreamException
-
jumpToEnd
private void jumpToEnd() throws XMLStreamException
- Throws:
XMLStreamException
-
parseToplevelList
private void parseToplevelList() throws XMLStreamException
- Throws:
XMLStreamException
-
parseInnerList
private List<String> parseInnerList() throws XMLStreamException
- Throws:
XMLStreamException
-
parseMap
private Map<String,String> parseMap() throws XMLStreamException
- Throws:
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(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
-
-