java.util.prefs
Class XmlSupport

java.lang.Object
  extended byjava.util.prefs.XmlSupport

class XmlSupport
extends Object

XML Support for java.util.prefs. Methods to import and export preference nodes and subtrees.

Since:
1.4
Author:
Josh Bloch and Mark Reinhold
See Also:
Preferences

Nested Class Summary
private static class XmlSupport.EH
           
private static class XmlSupport.Resolver
           
 
Field Summary
private static String EXTERNAL_XML_VERSION
          Version number for the format exported preferences files.
private static String MAP_XML_VERSION
           
private static String PREFS_DTD
           
private static String PREFS_DTD_URI
           
 
Constructor Summary
(package private) XmlSupport()
           
 
Method Summary
(package private) static void export(OutputStream os, Preferences p, boolean subTree)
          Export the specified preferences node and, if subTree is true, all subnodes, to the specified output stream.
(package private) static void exportMap(OutputStream os, Map map)
          Export the specified Map to a map document on the specified OutputStream as per the prefs DTD.
(package private) static void importMap(InputStream is, Map m)
          Import Map from the specified input stream, which is assumed to contain a map document as per the prefs DTD.
(package private) static void importPreferences(InputStream is)
          Import preferences from the specified input stream, which is assumed to contain an XML document in the format described in the Preferences spec.
private static void ImportPrefs(Preferences prefsNode, org.w3c.dom.Element map)
          Import the preferences described by the specified XML element (a map from a preferences document) into the specified preferences node.
private static void ImportSubtree(Preferences prefsNode, org.w3c.dom.Element xmlNode)
          Recursively traverse the specified preferences node and store the described preferences into the system or current user preferences tree, as appropriate.
private static org.w3c.dom.Document load(InputStream in)
          Load an XML document from specified input stream, which must have the requisite DTD URI.
private static void putPreferencesInXml(org.w3c.dom.Element elt, org.w3c.dom.Document doc, Preferences prefs, boolean subTree)
          Put the preferences in the specified Preferences node into the specified XML element which is assumed to represent a node in the specified XML document which is assumed to conform to PREFS_DTD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREFS_DTD_URI

private static final String PREFS_DTD_URI
See Also:
Constant Field Values

PREFS_DTD

private static final String PREFS_DTD
See Also:
Constant Field Values

EXTERNAL_XML_VERSION

private static final String EXTERNAL_XML_VERSION
Version number for the format exported preferences files.

See Also:
Constant Field Values

MAP_XML_VERSION

private static final String MAP_XML_VERSION
See Also:
Constant Field Values
Constructor Detail

XmlSupport

XmlSupport()
Method Detail

export

static void export(OutputStream os,
                   Preferences p,
                   boolean subTree)
            throws IOException,
                   BackingStoreException
Export the specified preferences node and, if subTree is true, all subnodes, to the specified output stream. Preferences are exported as an XML document conforming to the definition in the Preferences spec.

Throws:
IOException - if writing to the specified output stream results in an IOException.
BackingStoreException - if preference data cannot be read from backing store.
IllegalStateException - if this node (or an ancestor) has been removed with the #removeNode() method.

putPreferencesInXml

private static void putPreferencesInXml(org.w3c.dom.Element elt,
                                        org.w3c.dom.Document doc,
                                        Preferences prefs,
                                        boolean subTree)
                                 throws BackingStoreException
Put the preferences in the specified Preferences node into the specified XML element which is assumed to represent a node in the specified XML document which is assumed to conform to PREFS_DTD. If subTree is true, create children of the specified XML node conforming to all of the children of the specified Preferences node and recurse.

Throws:
BackingStoreException - if it is not possible to read the preferences or children out of the specified preferences node.

importPreferences

static void importPreferences(InputStream is)
                       throws IOException,
                              InvalidPreferencesFormatException
Import preferences from the specified input stream, which is assumed to contain an XML document in the format described in the Preferences spec.

Throws:
IOException - if reading from the specified output stream results in an IOException.
InvalidPreferencesFormatException - Data on input stream does not constitute a valid XML document with the mandated document type.

load

private static org.w3c.dom.Document load(InputStream in)
                                  throws org.xml.sax.SAXException,
                                         IOException
Load an XML document from specified input stream, which must have the requisite DTD URI.

Throws:
org.xml.sax.SAXException
IOException

ImportSubtree

private static void ImportSubtree(Preferences prefsNode,
                                  org.w3c.dom.Element xmlNode)
Recursively traverse the specified preferences node and store the described preferences into the system or current user preferences tree, as appropriate.


ImportPrefs

private static void ImportPrefs(Preferences prefsNode,
                                org.w3c.dom.Element map)
Import the preferences described by the specified XML element (a map from a preferences document) into the specified preferences node.


exportMap

static void exportMap(OutputStream os,
                      Map map)
               throws IOException
Export the specified Map to a map document on the specified OutputStream as per the prefs DTD. This is used as the internal (undocumented) format for FileSystemPrefs.

Throws:
IOException - if writing to the specified output stream results in an IOException.

importMap

static void importMap(InputStream is,
                      Map m)
               throws IOException,
                      InvalidPreferencesFormatException
Import Map from the specified input stream, which is assumed to contain a map document as per the prefs DTD. This is used as the internal (undocumented) format for FileSystemPrefs. The key-value pairs specified in the XML document will be put into the specified Map. (If this Map is empty, it will contain exactly the key-value pairs int the XML-document when this method returns.)

Throws:
IOException - if reading from the specified output stream results in an IOException.
InvalidPreferencesFormatException - Data on input stream does not constitute a valid XML document with the mandated document type.