APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.util.prefs

pack-priv Class XmlSupport

extends Object
Class Inheritance
Imports
java.util.*, java.io.*, javax.xml.parsers.*, javax.xml.transform.*, javax.xml.transform.dom.*, javax.xml.transform.stream.*, org.xml.sax.*, org.w3c.dom.*

XML Support for java.util.prefs. Methods to import and export preference nodes and subtrees.
Author
Josh Bloch and Mark Reinhold
Since
1.4
See Also
Preferences

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final String
EXTERNAL_XML_VERSION

Version number for the format exported preferences files.

private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static Document
createPrefsDoc(String qname)

Create a new prefs XML document.

pack-priv static void
export(OutputStream os, final Preferences p, boolean subTree)

Export the specified preferences node and, if subTree is true, all subnodes, to the specified output stream.

pack-priv static void
exportMap(OutputStream os, Map<String, String> map)

Export the specified Map<String,String> to a map document on the specified OutputStream as per the prefs DTD.

pack-priv static void
importMap(InputStream is, Map<String, String> m)

Import Map from the specified input stream, which is assumed to contain a map document as per the prefs DTD.

pack-priv 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, 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, 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 Document
loadPrefsDoc(InputStream in)

Load an XML document from specified input stream, which must have the requisite DTD URI.

private static void
putPreferencesInXml(Element elt, 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.

private static final void
writeDoc(Document doc, OutputStream out)

Write XML document to the specified output stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EXTERNAL_XML_VERSIONback to summary
private static final String EXTERNAL_XML_VERSION

Version number for the format exported preferences files.

MAP_XML_VERSIONback to summary
private static final String MAP_XML_VERSION
PREFS_DTDback to summary
private static final String PREFS_DTD
PREFS_DTD_URIback to summary
private static final String PREFS_DTD_URI

Constructor Detail

XmlSupportback to summary
pack-priv XmlSupport()

Method Detail

createPrefsDocback to summary
private static Document createPrefsDoc(String qname)

Create a new prefs XML document.

exportback to summary
pack-priv static void export(OutputStream os, final 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.

Exceptions
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 Preferences#removeNode() method.
exportMapback to summary
pack-priv static void exportMap(OutputStream os, Map<String, String> map) throws IOException

Export the specified Map<String,String> to a map document on the specified OutputStream as per the prefs DTD. This is used as the internal (undocumented) format for FileSystemPrefs.

Exceptions
IOException:
if writing to the specified output stream results in an IOException.
importMapback to summary
pack-priv static void importMap(InputStream is, Map<String, String> 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.)

Exceptions
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.
importPreferencesback to summary
pack-priv 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.

Exceptions
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.
ImportPrefsback to summary
private static void ImportPrefs(Preferences prefsNode, Element map)

Import the preferences described by the specified XML element (a map from a preferences document) into the specified preferences node.

ImportSubtreeback to summary
private static void ImportSubtree(Preferences prefsNode, Element xmlNode)

Recursively traverse the specified preferences node and store the described preferences into the system or current user preferences tree, as appropriate.

loadPrefsDocback to summary
private static Document loadPrefsDoc(InputStream in) throws SAXException, IOException

Load an XML document from specified input stream, which must have the requisite DTD URI.

putPreferencesInXmlback to summary
private static void putPreferencesInXml(Element elt, 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.

Exceptions
BackingStoreException:
if it is not possible to read the preferences or children out of the specified preferences node.
writeDocback to summary
private static final void writeDoc(Document doc, OutputStream out) throws IOException

Write XML document to the specified output stream.

java.util.prefs back to summary

private Class XmlSupport.EH

extends Object
implements ErrorHandler
Class Inheritance
All Implemented Interfaces
org.xml.sax.ErrorHandler

Constructor Summary

AccessConstructor and Description
private
EH()

Method Summary

Modifier and TypeMethod and Description
public void
error(SAXParseException x)

Implements org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

public void
fatalError(SAXParseException x)

Implements org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

public void
warning(SAXParseException x)

Implements org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EHback to summary
private EH()

Method Detail

errorback to summary
public void error(SAXParseException x) throws SAXException

Implements org.xml.sax.ErrorHandler.error.

Doc from org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
fatalErrorback to summary
public void fatalError(SAXParseException x) throws SAXException

Implements org.xml.sax.ErrorHandler.fatalError.

Doc from org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

As defined in section 1.2 of the W3C XML 1.0 Recommendation, fatal errors are those that would make it impossible for a parser to continue normal processing. These include violation of a well-formedness constraint, invalid encoding, and forbidden structural errors as described in the W3C XML 1.0 Recommendation.

Exceptions
SAXException:
if the application chooses to discontinue the parsing
warningback to summary
public void warning(SAXParseException x) throws SAXException

Implements org.xml.sax.ErrorHandler.warning.

Doc from org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
java.util.prefs back to summary

private Class XmlSupport.Resolver

extends Object
implements EntityResolver
Class Inheritance
All Implemented Interfaces
org.xml.sax.EntityResolver

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public InputSource
resolveEntity(String pid, String sid)

Implements org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Resolverback to summary
private Resolver()

Method Detail

resolveEntityback to summary
public InputSource resolveEntity(String pid, String sid) throws SAXException

Implements org.xml.sax.EntityResolver.resolveEntity.

Doc from org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream).

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL.

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.