org.inria.ns.reflex.xml.dom
Class DOMAdaptableParser

java.lang.Object
  extended by org.inria.ns.reflex.xml.dom.DOMAdaptableParser

public class DOMAdaptableParser
extends Object

A DOMAdaptableParser parses an XML source that may be an entire XML document (with or without DTD stuff) as well as an XML fragment (with several root elements and/or eventually text around the root element(s) ).

Author:
Philippe Poulard
See Also:
SAXAdaptableParser

Constructor Summary
DOMAdaptableParser()
          Create a parser that parses XML fragments as well as entire XML documents with a namespace-aware parser.
DOMAdaptableParser(EntityResolver resolver, ErrorHandler errorHandler)
          Create a parser that parses XML fragments as well as entire XML documents with a namespace-aware parser.
DOMAdaptableParser(ParserConfiguration configuration)
          Create a parser that parses XML fragments as well as entire XML documents.
DOMAdaptableParser(ParserConfiguration configuration, EntityResolver resolver, ErrorHandler errorHandler)
          Create a parser that parses XML fragments as well as entire XML documents.
 
Method Summary
static Document adaptToDocument(Node node)
          Transform a node to a document.
static boolean canBeDocument(Node node)
          Test if a Node can be a Document : it may contain 1 Element, not more ; it may contain 1 DocumentType, not more ; it can't have attributes ; if any, its Text nodes must be blanks (but they can't be part of the document child nodes) ; container nodes are flatenned (entity reference, document fragment).
 Node parse(InputSource input)
          Parse an input source.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMAdaptableParser

public DOMAdaptableParser()
Create a parser that parses XML fragments as well as entire XML documents with a namespace-aware parser.

See Also:
ParserConfiguration.NAMESPACEAWARE_PARSER_CONFIGURATION

DOMAdaptableParser

public DOMAdaptableParser(ParserConfiguration configuration)
Create a parser that parses XML fragments as well as entire XML documents.

Parameters:
configuration - The non-null configuration expected for the parser.

DOMAdaptableParser

public DOMAdaptableParser(ParserConfiguration configuration,
                          EntityResolver resolver,
                          ErrorHandler errorHandler)
Create a parser that parses XML fragments as well as entire XML documents.

Parameters:
configuration - The non-null configuration expected for the parser.
resolver - The resolver to use while parsing.
errorHandler - The error handler to use while parsing.

DOMAdaptableParser

public DOMAdaptableParser(EntityResolver resolver,
                          ErrorHandler errorHandler)
Create a parser that parses XML fragments as well as entire XML documents with a namespace-aware parser.

Parameters:
resolver - The resolver to use while parsing.
errorHandler - The error handler to use while parsing.
See Also:
ParserConfiguration.NAMESPACEAWARE_PARSER_CONFIGURATION
Method Detail

parse

public Node parse(InputSource input)
           throws SAXException,
                  IOException,
                  ParserConfigurationException
Parse an input source.

Parameters:
input - The input to parse.
Returns:
A node, that may be either a document fragment or a document. A fragment will be supplied if the input can't be parsed to a document.
Throws:
ParserConfigurationException - Change your parser if you see this error.
SAXException
IOException
See Also:
DocumentFragment, Document

adaptToDocument

public static Document adaptToDocument(Node node)
                                throws ParserConfigurationException
Transform a node to a document. This method doesn't test if the transformation can be done : be care to invoke explicitely canBeDocument(Node) before. The result document is the same as the owner document of the candidate node if the candidate node is a fragment and its host document has no child node.

Parameters:
node - The node that can be a document.
Returns:
A document.
Throws:
ParserConfigurationException - Change your parser if you have such an error.
See Also:
canBeDocument(Node)

canBeDocument

public static boolean canBeDocument(Node node)
Test if a Node can be a Document :

Parameters:
node - The node to test.
Returns:
true if the node is a good candidate, false otherwise.
See Also:
adaptToDocument(Node)