2.17.2: 2011-06-17

net.sf.basedb.core
Class Presets

java.lang.Object
  extended by 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: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Nested Class Summary
static class Presets.Preset
          Represents a single preset.
 
Field Summary
private  Presets.Preset defaultPreset
           
private static URL dtdFile
          The DTD which is used to validate the XML data.
private  Map<String,Presets.Preset> presets
           
 
Constructor Summary
Presets()
          Create a new empty presets object.
 
Method Summary
 String asXml()
          Convert the presets to an XML string.
private  Document buildDocument()
          Convert the presets to a XML document.
 void deletePreset(String name)
          Delete a named preset.
 Presets.Preset getDefault()
          Get the default preset.
 Presets.Preset getPreset(String name)
          Get a named preset.
 Iterator<Presets.Preset> iterator()
          Iterate over all named presets.
 void loadFrom(InputStream in, String filename)
          Load presets from a stream.
 void loadFrom(String xml)
          Load presets from an XML string.
private  void loadPresets(Document dom)
          Parse an XML Document and load all presets.
 void writeTo(OutputStream out)
          Write the prestes to a stream as an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dtdFile

private static final URL dtdFile
The DTD which is used to validate the XML data.


defaultPreset

private Presets.Preset defaultPreset

presets

private Map<String,Presets.Preset> presets
Constructor Detail

Presets

public Presets()
Create a new empty presets object.

Method Detail

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

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.


2.17.2: 2011-06-17