org.inria.ns.reflex.xml.sax
Class SAXUtil

java.lang.Object
  extended by org.inria.ns.reflex.xml.sax.SAXUtil

public abstract class SAXUtil
extends Object

SAX utilities : a set of static methods.

Author:
Philippe Poulard

Field Summary
static SAXFilter NULL_FILTER
          A filter that does nothing : works like /dev/null.
 
Method Summary
static SAXSource getSAXSource(Source source)
          Transform a source into a SAX source.
static SAXSource getSAXSource(Source source, ParserConfiguration parserConfiguration)
          Transform a source into a SAX source.
static TransformerHandler getTransformerHandler()
          Creates a transformer handler that copies the input.
static TransformerHandler getTransformerHandler(Templates templates)
          Creates a transformer handler from a templates.
static void plug(XMLReader reader, ContentHandler contentHandler)
          Plug some handlers on a reader.
static void plug(XMLReader reader, ContentHandler contentHandler, DTDHandler dtdHandler, LexicalHandler lexicalHandler, DeclHandler declHandler)
          Plug some handlers on a reader.
static void plug(XMLReader reader, SAXFilter filter)
          Plug a filter on a reader.
static void plug(XMLReader reader, TransformerHandler thandler)
          Plug the handlers of a transformer on a reader.
static void plug(XMLReader reader, XMLFilterImpl filter)
          Plug a filter on a reader.
static void plugHandlers(XMLReader targetReader, XMLReader modelReader)
          Plug the handlers of a reader on another reader.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_FILTER

public static final SAXFilter NULL_FILTER
A filter that does nothing : works like /dev/null.

Method Detail

plug

public static void plug(XMLReader reader,
                        SAXFilter filter)
Plug a filter on a reader. The filter is set as the child of the reader.

Parameters:
reader - The non-null reader.
filter - The non-null filter.
See Also:
plugHandlers(XMLReader, XMLReader)

plug

public static void plug(XMLReader reader,
                        XMLFilterImpl filter)
Plug a filter on a reader. The filter is set as the child of the reader.

Parameters:
reader - The non-null reader.
filter - The non-null filter.
See Also:
plugHandlers(XMLReader, XMLReader)

plug

public static void plug(XMLReader reader,
                        TransformerHandler thandler)
Plug the handlers of a transformer on a reader.

Parameters:
reader - The non-null reader.
thandler - The transformer, shouldn't be null.
See Also:
plug(XMLReader, ContentHandler, DTDHandler, LexicalHandler, DeclHandler)

plug

public static void plug(XMLReader reader,
                        ContentHandler contentHandler,
                        DTDHandler dtdHandler,
                        LexicalHandler lexicalHandler,
                        DeclHandler declHandler)
Plug some handlers on a reader.

Parameters:
reader - The non-null reader.
contentHandler - A content handler, may be null.
dtdHandler - A DTD handler, may be null.
lexicalHandler - A lexical handler, may be null.
declHandler - A decl handler, may be null.

plug

public static void plug(XMLReader reader,
                        ContentHandler contentHandler)
Plug some handlers on a reader. A convenient method for a content handler that is also a DTD handler, a lexical handler, and/or a decl. handler.

Parameters:
reader - The non-null reader.
contentHandler - A non-null content handler.

plugHandlers

public static void plugHandlers(XMLReader targetReader,
                                XMLReader modelReader)
Plug the handlers of a reader on another reader.

This means that when the job is done, the target reader will have the same handlers as the model.

Each handler undefined by the model (lexical, content, DTD, decl) cause plugging something like /dev/null to the counterpart handler of the target.

Parameters:
targetReader - The reader that will have its handlers set.
modelReader - The reader used as the model.

getTransformerHandler

public static TransformerHandler getTransformerHandler()
                                                throws TransformerConfigurationException
Creates a transformer handler that copies the input.

Returns:
A transformer handler that is the identity transformation.
Throws:
TransformerConfigurationException - If SAX is not supported.

getTransformerHandler

public static TransformerHandler getTransformerHandler(Templates templates)
                                                throws TransformerConfigurationException
Creates a transformer handler from a templates.

Parameters:
templates - The templates, that may be null.
Returns:
A transformer handler that is the identity transformation if the templates was null.
Throws:
TransformerConfigurationException - If SAX is not supported.

getSAXSource

public static SAXSource getSAXSource(Source source)
Transform a source into a SAX source.

Parameters:
source - The input source to convert. If it must be parsed, a namespace aware parser will be used.
Returns:
The SAX source.
See Also:
ParserConfiguration.NAMESPACEAWARE_PARSER_CONFIGURATION, DOMHelper.getDOMSource(Source)

getSAXSource

public static SAXSource getSAXSource(Source source,
                                     ParserConfiguration parserConfiguration)
Transform a source into a SAX source.

Parameters:
source - The input source to convert.
parserConfiguration - If the source must be parsed, this configuration will be used. Can be null if the source doesn't have to be parsed.
Returns:
The SAX source.
See Also:
DOMHelper.getDOMSource(Source, ParserConfiguration)