ix.util.xml
Class XML

java.lang.Object
  extended by ix.util.xml.XML

public class XML
extends java.lang.Object

A class containing static XML utilities.

See Also:
XMLConfig

Nested Class Summary
static class XML.XSAXBuilder
          A minor variation on the JDOM SAXBuilder class.
 
Field Summary
static org.jdom.output.XMLOutputter prettyXMLOutputter
          An XML outputter created by makePrettyXMLOutputter().
 
Method Summary
static void addImport(java.lang.String name)
          Adds an import in the default ClassFinder.
static XMLConfig config()
          Returns the configuration currently being used by the XML tools.
static java.lang.String decodeAttribute(java.lang.String text)
          Decodes text containing encoded double quotes, ampersands, and angle brackets.
static java.lang.String decodeText(java.lang.String text)
          Decodes text containing encoded ampersands and angle brackets.
static XMLTranslator defaultTranslator()
          The XMLTranslator used by static method in this class.
static java.lang.String documentToXMLString(org.jdom.Document doc)
          Converts a JDOM Document to a string of XML using the default translator.
static java.lang.String encodeAttribute(java.lang.String text)
          Encodes double quotes as well as ampersands and angle brackets to make text safe for use as XML attribute values.
static java.lang.String encodeText(java.lang.String text)
          Encodes ampersands and angle brackets so that they can appear in XML without being mistaken for markup.
static FileSyntaxManager fileSyntaxManager()
          Returns the FileSyntaxManager used by static methods in this class.
static org.jdom.Namespace getHomeNamespace()
          Returns the JDOM Namespace used by the default translator.
static boolean looksLikeAnIXDocument(org.jdom.Document doc)
          Deprecated. As of I-X 3.3, use looksLikeAnObjectDocument(Document).
static boolean looksLikeAnObjectDocument(org.jdom.Document doc)
          Asks the default translator whether the document looks like it can be read as an Object.
static void main(java.lang.String[] argv)
          Test loop that asks the user for a line of text and shows the result of calling encodeAttribute(String) on the input then calling decodeAttribute(String) on the encoded result.
static org.jdom.output.XMLOutputter makePrettyXMLOutputter()
          Constructs a JDOM XMLOutputter that outputs a JDOM Document in a nicely indented fashion.
static org.jdom.input.SAXBuilder makeSAXBuilder()
          Constructs a JDOM SAXBuilder.
static java.lang.String nameForClass(java.lang.Class c)
          Returns the class-name that would be used by the default ClassFinder.
static java.lang.Object objectFromDocument(org.jdom.Document doc)
          Converts a JDOM Document to an object using the default translator.
static java.lang.Object objectFromElement(org.jdom.Element elt)
          Converts a JDOM Element to an object using the default translator.
static java.lang.Object objectFromFile(java.io.File file)
          Deprecated. As of I-X 3.3, use readObject(String).
static java.lang.Object objectFromXML(java.lang.String xml)
          Converts a string of XML to an Object using the default translator.
static org.jdom.Document objectToDocument(java.lang.Object obj)
          Converts an object to a JDOM Document using the default translator.
static java.lang.String objectToXMLString(java.lang.Object obj)
          Converts an object to a string of XML using the default translator.
static org.jdom.Document parseXML(java.io.File file)
          Converts a File of XML to a JDOM Document.
static org.jdom.Document parseXML(java.lang.String text)
          Converts a String of XML to a JDOM Document.
static org.jdom.Document parseXML(java.net.URL url)
          Converts XML from a URL to a JDOM Document.
static void printXMLWithWhitespace(org.jdom.Document doc, int indentation)
          Prints a document as text to System.out with blank lines between top-level parts of the root element.
static void printXMLWithWhitespace(java.lang.String xml, int indentation)
          Prints a multi-line string of XML with blank lines between top-level parts of the root element.
static org.jdom.Document readDocument(java.lang.String resourceName)
          Reads a JDOM Document from the specified resource. /\/ explain ...
static
<T> T
readObject(java.lang.Class<T> desiredClass, java.lang.String resourceName)
          Reads an object from the specified resource. /\/ explain...
static
<T> T
readObject(java.lang.Class<T> desiredClass, java.net.URL url)
          Reads an object from the specified resource. /\/ explain...
static java.lang.Object readObject(java.lang.String resourceName)
          Reads an object from the specified resource. /\/ explain ...
static java.net.URL requireURL(java.lang.String resourceName)
          Returns a URL for a specified resource.
static void setAttributes(org.jdom.Element elt, java.lang.String[][] attributes)
          Sets attributes of a JDOM Element as specified by a String[][] array.
static void setConfig(XMLConfig c)
          Sets the configuration that will be used by the XML tools.
static java.net.URL toURL(java.lang.String resourceName)
          Returns a URL for a specified resource.
static void withDefaultTranslator(XMLTranslator xmlt, java.lang.Runnable thunk)
          Allows temporary replacement of the default translator.
static void writeObject(java.lang.Object obj, java.lang.String filename)
          Writes an object as XML to the specified file. /\/ explain ...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prettyXMLOutputter

public static org.jdom.output.XMLOutputter prettyXMLOutputter
An XML outputter created by makePrettyXMLOutputter().

Method Detail

config

public static XMLConfig config()
Returns the configuration currently being used by the XML tools.


setConfig

public static void setConfig(XMLConfig c)
Sets the configuration that will be used by the XML tools.


defaultTranslator

public static XMLTranslator defaultTranslator()
The XMLTranslator used by static method in this class.


withDefaultTranslator

public static void withDefaultTranslator(XMLTranslator xmlt,
                                         java.lang.Runnable thunk)
Allows temporary replacement of the default translator.


getHomeNamespace

public static org.jdom.Namespace getHomeNamespace()
Returns the JDOM Namespace used by the default translator.


nameForClass

public static java.lang.String nameForClass(java.lang.Class c)
Returns the class-name that would be used by the default ClassFinder.


addImport

public static void addImport(java.lang.String name)
Adds an import in the default ClassFinder. It will therefore affect all XML translators that use that ClassFinder.


fileSyntaxManager

public static FileSyntaxManager fileSyntaxManager()
Returns the FileSyntaxManager used by static methods in this class.


objectFromXML

public static java.lang.Object objectFromXML(java.lang.String xml)
Converts a string of XML to an Object using the default translator.


objectFromFile

public static java.lang.Object objectFromFile(java.io.File file)
Deprecated. As of I-X 3.3, use readObject(String).

Converts a File of XML to an Object using the default translator.


readObject

public static java.lang.Object readObject(java.lang.String resourceName)
Reads an object from the specified resource. /\/ explain ...


readObject

public static <T> T readObject(java.lang.Class<T> desiredClass,
                               java.lang.String resourceName)
Reads an object from the specified resource. /\/ explain...


readObject

public static <T> T readObject(java.lang.Class<T> desiredClass,
                               java.net.URL url)
Reads an object from the specified resource. /\/ explain...


readDocument

public static org.jdom.Document readDocument(java.lang.String resourceName)
Reads a JDOM Document from the specified resource. /\/ explain ...


objectFromDocument

public static java.lang.Object objectFromDocument(org.jdom.Document doc)
Converts a JDOM Document to an object using the default translator.


looksLikeAnObjectDocument

public static boolean looksLikeAnObjectDocument(org.jdom.Document doc)
Asks the default translator whether the document looks like it can be read as an Object.

See Also:
XMLTranslator.looksLikeAnObjectDocument(Document)

looksLikeAnIXDocument

public static boolean looksLikeAnIXDocument(org.jdom.Document doc)
Deprecated. As of I-X 3.3, use looksLikeAnObjectDocument(Document).

Asks the default translator whether the document looks like it can be read as an Object.


objectFromElement

public static java.lang.Object objectFromElement(org.jdom.Element elt)
Converts a JDOM Element to an object using the default translator.


makeSAXBuilder

public static org.jdom.input.SAXBuilder makeSAXBuilder()
Constructs a JDOM SAXBuilder. This is used by the parseXML methods.

See Also:
XMLConfig.makeSAXBuilder()

parseXML

public static org.jdom.Document parseXML(java.lang.String text)
Converts a String of XML to a JDOM Document.


parseXML

public static org.jdom.Document parseXML(java.io.File file)
Converts a File of XML to a JDOM Document.


parseXML

public static org.jdom.Document parseXML(java.net.URL url)
Converts XML from a URL to a JDOM Document.


toURL

public static java.net.URL toURL(java.lang.String resourceName)
Returns a URL for a specified resource.

See Also:
FileSyntaxManager.toURL(String)

requireURL

public static java.net.URL requireURL(java.lang.String resourceName)
Returns a URL for a specified resource.

See Also:
FileSyntaxManager.requireURL(String)

objectToXMLString

public static java.lang.String objectToXMLString(java.lang.Object obj)
Converts an object to a string of XML using the default translator.


documentToXMLString

public static java.lang.String documentToXMLString(org.jdom.Document doc)
Converts a JDOM Document to a string of XML using the default translator.


objectToDocument

public static org.jdom.Document objectToDocument(java.lang.Object obj)
Converts an object to a JDOM Document using the default translator.


writeObject

public static void writeObject(java.lang.Object obj,
                               java.lang.String filename)
Writes an object as XML to the specified file. /\/ explain ...


makePrettyXMLOutputter

public static org.jdom.output.XMLOutputter makePrettyXMLOutputter()
Constructs a JDOM XMLOutputter that outputs a JDOM Document in a nicely indented fashion.

See Also:
XMLConfig.makePrettyXMLOutputter()

printXMLWithWhitespace

public static void printXMLWithWhitespace(org.jdom.Document doc,
                                          int indentation)
Prints a document as text to System.out with blank lines between top-level parts of the root element. Calls printXMLWithWhitespace(String xml, int indentation).


printXMLWithWhitespace

public static void printXMLWithWhitespace(java.lang.String xml,
                                          int indentation)
Prints a multi-line string of XML with blank lines between top-level parts of the root element.


setAttributes

public static void setAttributes(org.jdom.Element elt,
                                 java.lang.String[][] attributes)
Sets attributes of a JDOM Element as specified by a String[][] array. Each row of the array is a {name, value} pair.


encodeText

public static java.lang.String encodeText(java.lang.String text)
Encodes ampersands and angle brackets so that they can appear in XML without being mistaken for markup.


decodeText

public static java.lang.String decodeText(java.lang.String text)
Decodes text containing encoded ampersands and angle brackets. This is the inverse of encodeText(String).


encodeAttribute

public static java.lang.String encodeAttribute(java.lang.String text)
Encodes double quotes as well as ampersands and angle brackets to make text safe for use as XML attribute values.


decodeAttribute

public static java.lang.String decodeAttribute(java.lang.String text)
Decodes text containing encoded double quotes, ampersands, and angle brackets. This is the inverse of encodeAttribute(String).


main

public static void main(java.lang.String[] argv)
Test loop that asks the user for a line of text and shows the result of calling encodeAttribute(String) on the input then calling decodeAttribute(String) on the encoded result.