Class PreferencesReader


  • public class PreferencesReader
    extends java.lang.Object
    Loads preferences from XML.
    • Field Summary

      Fields 
      Modifier and Type Field 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 Summary

      Constructors 
      Constructor Description
      PreferencesReader​(java.io.File file, boolean defaults)
      Constructs a new PreferencesReader.
      PreferencesReader​(java.io.Reader reader, boolean defaults)
      Constructs a new PreferencesReader.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • settings

        private final java.util.SortedMap<java.lang.String,​Setting<?>> settings
      • parser

        private javax.xml.stream.XMLStreamReader parser
      • reader

        private final java.io.Reader reader
      • file

        private final java.io.File file
      • defaults

        private final boolean defaults
    • Constructor Detail

      • PreferencesReader

        public PreferencesReader​(java.io.File file,
                                 boolean defaults)
        Constructs a new PreferencesReader.
        Parameters:
        file - the file
        defaults - 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 new PreferencesReader.
        Parameters:
        reader - the Reader
        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​(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 occurs
        org.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 - the Reader
        Throws:
        java.io.IOException - if any I/O error occurs
        org.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 occurs
        java.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
      • 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