com.arsdigita.xml
Class XML

java.lang.Object
  extended bycom.arsdigita.xml.XML

public class XML
extends Object

Provides a set of helper methods for dealing with XML, including file parsing & object -> string serialization


Nested Class Summary
static interface XML.Action
          This visitor is called by traverse(Element, int, XML.Action).
 
Method Summary
static Formatter findFormatter(Class klass)
          Looks for the best matching formatter.
static String format(Object value)
          Converts an object to a String using the closest matching registered Formatter implementation.
static Formatter getFormatter(Class klass)
          Gets a directly registered formatter for a class.
static void parse(InputStream source, org.xml.sax.helpers.DefaultHandler handler)
          Processes an XML file with the default SAX Parser, with namespace processing, schema validation & DTD validation enabled.
static void parseResource(String path, org.xml.sax.helpers.DefaultHandler handler)
          Processes an XML file with the default SAX Parser, with namespace processing, schema validation & DTD validation enabled.
static void registerFormatter(Class klass, Formatter formatter)
          Registers a formatter for serializing objects of a class to a String suitable for XML output.
static String toSkeleton(Element element)
          This is a wrapper for toSkeleton(Element, PrintWriter).
static void toSkeleton(Element element, PrintWriter writer)
          Prints the skeleton structure of the element to the supplied print writer.
static void traverse(Element elem, int level, XML.Action action)
          Pre-order, depth-first traversal.
static void unregisterFormatter(Class klass)
          Unregisters a formatter against a class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

registerFormatter

public static void registerFormatter(Class klass,
                                     Formatter formatter)
Registers a formatter for serializing objects of a class to a String suitable for XML output.


unregisterFormatter

public static void unregisterFormatter(Class klass)
Unregisters a formatter against a class.


getFormatter

public static Formatter getFormatter(Class klass)
Gets a directly registered formatter for a class.

Parameters:
klass - the class to find a formatter for
Returns:
the formatter, or null if non is registered

findFormatter

public static Formatter findFormatter(Class klass)
Looks for the best matching formatter.

Parameters:
klass - the class to find a formatter for
Returns:
the formatter, or null if non is registered

format

public static String format(Object value)
Converts an object to a String using the closest matching registered Formatter implementation. Looks for a formatter registered against the object's class first, then its superclass, etc. If no formatter is found, uses the toString() method


parseResource

public static final void parseResource(String path,
                                       org.xml.sax.helpers.DefaultHandler handler)
Processes an XML file with the default SAX Parser, with namespace processing, schema validation & DTD validation enabled.

Parameters:
path - the XML file relative to the webapp root
handler - the content handler

parse

public static final void parse(InputStream source,
                               org.xml.sax.helpers.DefaultHandler handler)
Processes an XML file with the default SAX Parser, with namespace processing, schema validation & DTD validation enabled.

Parameters:
source - the xml input stream
handler - the content handler

toSkeleton

public static void toSkeleton(Element element,
                              PrintWriter writer)
Prints the skeleton structure of the element to the supplied print writer.


toSkeleton

public static String toSkeleton(Element element)
This is a wrapper for toSkeleton(Element, PrintWriter).


traverse

public static void traverse(Element elem,
                            int level,
                            XML.Action action)
Pre-order, depth-first traversal.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC