Class Presets

java.lang.Object
net.sf.basedb.core.Presets
All Implemented Interfaces:
Iterable<Presets.Preset>

public class Presets extends Object implements Iterable<Presets.Preset>
This is a generic class for handling named presets consisting of multiple key/value pairs. One instance can handle one default preset and multiple named ones. Saving and loading is done to/from XML strings. The XML strings could for example be stored as user settings (for example with SessionControl.setUserDefaultSetting(String, String) or as properties of items in the database.
Version:
2.2
Author:
Nicklas
Last modified
$Date: 2015-05-12 11:27:08 +0200 (ti, 12 maj 2015) $
  • Field Details

  • Constructor Details

    • Presets

      public Presets()
      Create a new empty presets object.
  • Method Details

    • iterator

      public Iterator<Presets.Preset> iterator()
      Iterate over all named presets. The default preset, if it exists, is not included in the iteration.
      Specified by:
      iterator in interface Iterable<Presets.Preset>
    • loadFrom

      public void loadFrom(String xml)
      Load presets from an XML string.
      Parameters:
      xml - The XML string
    • loadFrom

      public void loadFrom(InputStream in, String filename)
      Load presets from a stream.
      Parameters:
      in - The stream to read from
      filename - The original filename the stream is loaded from, or null if not known
      Since:
      2.7
    • writeTo

      public void writeTo(OutputStream out)
      Write the prestes to a stream as an XML file.
      Parameters:
      out - The stream to write to.
      Since:
      2.7
    • asXml

      public String asXml()
      Convert the presets to an XML string.
      Returns:
      The XML string
    • buildDocument

      private Document buildDocument()
      Convert the presets to a XML document.
      Since:
      2.7
    • getDefault

      public Presets.Preset getDefault()
      Get the default preset. If no default exists a new default will be created.
    • getPreset

      public Presets.Preset getPreset(String name)
      Get a named preset. If no preset with the given name exists a new preset is created.
      Parameters:
      name - The name of the preset
      Returns:
      The preset with the given name
    • exists

      public boolean exists(String name)
      Check if a preset with the given name exists.
      Since:
      3.4
    • deletePreset

      public void deletePreset(String name)
      Delete a named preset.
      Parameters:
      name - The name of the preset to delete
    • loadPresets

      private void loadPresets(Document dom)
      Parse an XML Document and load all presets.