Class PreferencesService

java.lang.Object
rs.baselib.prefs.AbstractPreferencesService
rs.baselib.prefs.PreferencesService
All Implemented Interfaces:
IPreferencesService

public class PreferencesService
extends AbstractPreferencesService
The default implementation of IPreferencesService. System preferences are stored in a common location depending on the OS. User preferences are stored in a hidden directory of the user's home directory.
Author:
ralph
  • Field Details

  • Method Details

    • createRootNode

      protected IPreferences createRootNode()
      Creates the root node.
      Specified by:
      createRootNode in class AbstractPreferencesService
      Returns:
      the root node for the service
    • loadUserPreferences

      protected void loadUserPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Loads the user preferences into the given node.
      Specified by:
      loadUserPreferences in class AbstractPreferencesService
      Parameters:
      node - node that shall be populated
      applicationName - name of application to be loaded
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • loadSystemPreferences

      protected void loadSystemPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Loads the system preferences into the given node.
      Specified by:
      loadSystemPreferences in class AbstractPreferencesService
      Parameters:
      node - node that shall be populated
      applicationName - name of application to be loaded
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • flushUserPreferences

      protected void flushUserPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Flushes the user preferences from the given node.
      Specified by:
      flushUserPreferences in class AbstractPreferencesService
      Parameters:
      node - node that shall be flushed
      applicationName - name of application to be flushed
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • flushSystemPreferences

      protected void flushSystemPreferences​(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreException
      Flushes the system preferences from the given node.
      Specified by:
      flushSystemPreferences in class AbstractPreferencesService
      Parameters:
      node - node that shall be flushed
      applicationName - name of application to be flushed
      Throws:
      java.util.prefs.BackingStoreException - when the storage fails
    • getInputStream

      protected java.io.InputStream getInputStream​(java.io.File f) throws java.util.prefs.BackingStoreException
      Returns an input stream that can be safely read.
      Parameters:
      f - file
      Returns:
      input stream (will be empty is file does not exists or cannot be read)
      Throws:
      java.util.prefs.BackingStoreException - when the file cannot be opened
    • getOutputStream

      protected java.io.OutputStream getOutputStream​(java.io.File f) throws java.util.prefs.BackingStoreException
      Returns an output stream that can be written to.
      Parameters:
      f - file
      Returns:
      output stream (intermediate directories will be created if required)
      Throws:
      java.util.prefs.BackingStoreException - when the file cannot be opened
    • load

      protected void load​(IPreferences node, java.io.InputStream in) throws java.util.prefs.BackingStoreException
      Loads the information from the stream into the node
      Parameters:
      node - node to be filled
      in - input stream
      Throws:
      java.util.prefs.BackingStoreException - when the stream contains errors
    • put

      protected void put​(IPreferences node, java.lang.String key, java.lang.String value)
      Stores the key at the appropriate sub-node.
      Parameters:
      node - node
      key - path of key (including node)
      value - value of key
    • save

      protected void save​(IPreferences node, java.io.OutputStream out) throws java.util.prefs.BackingStoreException
      Saves the node information into the stream
      Parameters:
      node - node to be saved
      out - output stream
      Throws:
      java.util.prefs.BackingStoreException - when the stream produces errors
    • save

      protected void save​(java.lang.String prefix, IPreferences node, java.io.PrintWriter out) throws java.util.prefs.BackingStoreException
      Recursively stores the given node into the writer.
      Parameters:
      prefix - prefix to be used for keys (can be null)
      node - node to be written
      out - print writer
      Throws:
      java.util.prefs.BackingStoreException - when a node cannot be written
    • getUserPreferencesHome

      public java.io.File getUserPreferencesHome​(java.lang.String applicationName)
      Returns the home directory for user preferences of the given application.
      Parameters:
      applicationName - name of application
      Returns:
      user preferences home
    • getUserHome

      protected java.io.File getUserHome()
      Returns the home directory of the user.
      Returns:
      the user home dir
    • getUserPreferencesFile

      protected java.io.File getUserPreferencesFile​(java.lang.String applicationName)
      Returns the application's preferences file of the user.
      Parameters:
      applicationName - name of the application
      Returns:
      the preferences file
    • getSystemPreferencesHome

      public java.io.File getSystemPreferencesHome​(java.lang.String applicationName)
      Returns the home directory for system preferences of the given application.
      Parameters:
      applicationName - name of application
      Returns:
      system preferences home
    • getSystemPreferencesFile

      protected java.io.File getSystemPreferencesFile​(java.lang.String applicationName)
      Returns the application's preferences file of the system.
      Parameters:
      applicationName - name of the application
      Returns:
      the preferences file
    • getSystemHome

      protected java.io.File getSystemHome()
      Returns the system home dir to store system prefs at.
      Returns:
      the system home dir (usually /var or C:\Users\AllUsers)