Package net.sf.basedb.core
Class Presets
java.lang.Object
net.sf.basedb.core.Presets
- All Implemented Interfaces:
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) $
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate Presets.Preset
private static final URL
The DTD which is used to validate the XML data.private Map<String,
Presets.Preset> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionasXml()
Convert the presets to an XML string.private Document
Convert the presets to a XML document.void
deletePreset
(String name) Delete a named preset.boolean
Check if a preset with the given name exists.Get the default preset.Get a named preset.iterator()
Iterate over all named presets.void
loadFrom
(InputStream in, String filename) Load presets from a stream.void
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
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
dtdFile
The DTD which is used to validate the XML data. -
defaultPreset
-
presets
-
-
Constructor Details
-
Presets
public Presets()Create a new empty presets object.
-
-
Method Details
-
iterator
Iterate over all named presets. The default preset, if it exists, is not included in the iteration.- Specified by:
iterator
in interfaceIterable<Presets.Preset>
-
loadFrom
Load presets from an XML string.- Parameters:
xml
- The XML string
-
loadFrom
Load presets from a stream.- Parameters:
in
- The stream to read fromfilename
- The original filename the stream is loaded from, or null if not known- Since:
- 2.7
-
writeTo
Write the prestes to a stream as an XML file.- Parameters:
out
- The stream to write to.- Since:
- 2.7
-
asXml
Convert the presets to an XML string.- Returns:
- The XML string
-
buildDocument
Convert the presets to a XML document.- Since:
- 2.7
-
getDefault
Get the default preset. If no default exists a new default will be created. -
getPreset
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
Check if a preset with the given name exists.- Since:
- 3.4
-
deletePreset
Delete a named preset.- Parameters:
name
- The name of the preset to delete
-
loadPresets
Parse an XML Document and load all presets.
-