gnu.xml.dom.ls

Class DomLSParser

Implemented Interfaces:
DOMConfiguration, DOMStringList, ErrorHandler, LSParser

public class DomLSParser
extends java.lang.Object
implements LSParser, DOMConfiguration, DOMStringList, ErrorHandler

Parser implementation for GNU DOM.

Fields inherited from interface org.w3c.dom.ls.LSParser

ACTION_APPEND_AS_CHILDREN, ACTION_INSERT_AFTER, ACTION_INSERT_BEFORE, ACTION_REPLACE, ACTION_REPLACE_CHILDREN

Constructor Summary

DomLSParser(short mode, String schemaType)

Method Summary

void
abort()
Abort the loading of the document that is currently being loaded by the LSParser.
boolean
canSetParameter(String name, Object value)
boolean
contains(String str)
void
error(SAXParseException e)
void
fatalError(SAXParseException e)
boolean
getAsync()
true if the LSParser is asynchronous, false if it is synchronous.
boolean
getBusy()
true if the LSParser is currently busy loading a document, otherwise false.
DOMConfiguration
getDomConfig()
The DOMConfiguration object used when parsing an input source.
LSParserFilter
getFilter()
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure.
int
getLength()
Object
getParameter(String name)
DOMStringList
getParameterNames()
String
item(int i)
Document
parse(LSInput input)
Parse an XML document from a resource identified by a LSInput.
Document
parseURI(String uri)
Parse an XML document from a location identified by a URI reference [IETF RFC 2396].
Node
parseWithContext(LSInput input, Node context, short action)
Parse an XML fragment from a resource identified by a LSInput and insert the content into an existing document at the position specified with the context and action arguments.
void
setFilter(LSParserFilter filter)
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure.
void
setParameter(String name, Object value)
void
warning(SAXParseException e)

Constructor Details

DomLSParser

public DomLSParser(short mode,
                   String schemaType)
            throws DOMException

Method Details

abort

public void abort()
Abort the loading of the document that is currently being loaded by the LSParser. If the LSParser is currently not busy, a call to this method does nothing.
Specified by:
abort in interface LSParser


canSetParameter

public boolean canSetParameter(String name,
                               Object value)
Specified by:
canSetParameter in interface DOMConfiguration


contains

public boolean contains(String str)
Specified by:
contains in interface DOMStringList


error

public void error(SAXParseException e)
            throws SAXException
Specified by:
error in interface ErrorHandler


fatalError

public void fatalError(SAXParseException e)
            throws SAXException
Specified by:
fatalError in interface ErrorHandler


getAsync

public boolean getAsync()
true if the LSParser is asynchronous, false if it is synchronous.
Specified by:
getAsync in interface LSParser


getBusy

public boolean getBusy()
true if the LSParser is currently busy loading a document, otherwise false.
Specified by:
getBusy in interface LSParser


getDomConfig

public DOMConfiguration getDomConfig()
The DOMConfiguration object used when parsing an input source. This DOMConfiguration is specific to the parse operation. No parameter values from this DOMConfiguration object are passed automatically to the DOMConfiguration object on the Document that is created, or used, by the parse operation. The DOM application is responsible for passing any needed parameter values from this DOMConfiguration object to the DOMConfiguration object referenced by the Document object.
In addition to the parameters recognized in on the DOMConfiguration interface defined in [DOM Level 3 Core] , the DOMConfiguration objects for LSParser add or modify the following parameters:
"charset-overrides-xml-encoding"
true
[optional] (default) If a higher level protocol such as HTTP [IETF RFC 2616] provides an indication of the character encoding of the input stream being processed, that will override any encoding specified in the XML declaration or the Text declaration (see also section 4.3.3, "Character Encoding in Entities", in [XML 1.0]). Explicitly setting an encoding in the LSInput overrides any encoding from the protocol.
false
[required] The parser ignores any character set encoding information from higher-level protocols.
"disallow-doctype"
true
[optional] Throw a fatal "doctype-not-allowed" error if a doctype node is found while parsing the document. This is useful when dealing with things like SOAP envelopes where doctype nodes are not allowed.
false
[required] (default) Allow doctype nodes in the document.
"ignore-unknown-character-denormalizations"
true
[required] (default) If, while verifying full normalization when [XML 1.1] is supported, a processor encounters characters for which it cannot determine the normalization properties, then the processor will ignore any possible denormalizations caused by these characters. This parameter is ignored for [XML 1.0].
false
[optional] Report an fatal "unknown-character-denormalization" error if a character is encountered for which the processor cannot determine the normalization properties.
"infoset"
See the definition of DOMConfiguration for a description of this parameter. Unlike in [DOM Level 3 Core] , this parameter will default to true for LSParser.
"namespaces"
true
[required] (default) Perform the namespace processing as defined in [XML Namespaces] and [XML Namespaces 1.1] .
false
[optional] Do not perform the namespace processing.
"resource-resolver"
[required] A reference to a LSResourceResolver object, or null. If the value of this parameter is not null when an external resource (such as an external XML entity or an XML schema location) is encountered, the implementation will request that the LSResourceResolver referenced in this parameter resolves the resource.
"supported-media-types-only"
true
[optional] Check that the media type of the parsed resource is a supported media type. If an unsupported media type is encountered, a fatal error of type "unsupported-media-type" will be raised. The media types defined in [IETF RFC 3023] must always be accepted.
false
[required] (default) Accept any media type.
"validate"
See the definition of DOMConfiguration for a description of this parameter. Unlike in [DOM Level 3 Core] , the processing of the internal subset is always accomplished, even if this parameter is set to false.
"validate-if-schema"
See the definition of DOMConfiguration for a description of this parameter. Unlike in [DOM Level 3 Core] , the processing of the internal subset is always accomplished, even if this parameter is set to false.
"well-formed"
See the definition of DOMConfiguration for a description of this parameter. Unlike in [DOM Level 3 Core] , this parameter cannot be set to false.
Specified by:
getDomConfig in interface LSParser


getFilter

public LSParserFilter getFilter()
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure. The filter can choose to remove elements from the document being constructed, or to terminate the parsing early.
The filter is invoked after the operations requested by the DOMConfiguration parameters have been applied. For example, if " validate" is set to true, the validation is done before invoking the filter.
Specified by:
getFilter in interface LSParser


getLength

public int getLength()
Specified by:
getLength in interface DOMStringList


getParameter

public Object getParameter(String name)
            throws DOMException
Specified by:
getParameter in interface DOMConfiguration


getParameterNames

public DOMStringList getParameterNames()
Specified by:
getParameterNames in interface DOMConfiguration


item

public String item(int i)
Specified by:
item in interface DOMStringList


parse

public Document parse(LSInput input)
            throws DOMException,
                   LSException
Parse an XML document from a resource identified by a LSInput.
Specified by:
parse in interface LSParser

Parameters:
input - The LSInput from which the source of the document is to be read.

Returns:
If the LSParser is a synchronous LSParser, the newly created and populated Document is returned. If the LSParser is asynchronous, null is returned since the document object may not yet be constructed when this method returns.

Throws:
DOMException - INVALID_STATE_ERR: Raised if the LSParser's LSParser.busy attribute is true.
LSException - PARSE_ERR: Raised if the LSParser was unable to load the XML document. DOM applications should attach a DOMErrorHandler using the parameter " error-handler" if they wish to get details on the error.


parseURI

public Document parseURI(String uri)
            throws DOMException,
                   LSException
Parse an XML document from a location identified by a URI reference [IETF RFC 2396]. If the URI contains a fragment identifier (see section 4.1 in [IETF RFC 2396]), the behavior is not defined by this specification, future versions of this specification may define the behavior.
Specified by:
parseURI in interface LSParser

Parameters:
uri - The location of the XML document to be read.

Returns:
If the LSParser is a synchronous LSParser, the newly created and populated Document is returned, or null if an error occured. If the LSParser is asynchronous, null is returned since the document object may not yet be constructed when this method returns.

Throws:
DOMException - INVALID_STATE_ERR: Raised if the LSParser.busy attribute is true.
LSException - PARSE_ERR: Raised if the LSParser was unable to load the XML document. DOM applications should attach a DOMErrorHandler using the parameter " error-handler" if they wish to get details on the error.


parseWithContext

public Node parseWithContext(LSInput input,
                             Node context,
                             short action)
            throws DOMException,
                   LSException
Parse an XML fragment from a resource identified by a LSInput and insert the content into an existing document at the position specified with the context and action arguments. When parsing the input stream, the context node (or its parent, depending on where the result will be inserted) is used for resolving unbound namespace prefixes. The context node's ownerDocument node (or the node itself if the node of type DOCUMENT_NODE) is used to resolve default attributes and entity references.
As the new data is inserted into the document, at least one mutation event is fired per new immediate child or sibling of the context node.
If the context node is a Document node and the action is ACTION_REPLACE_CHILDREN, then the document that is passed as the context node will be changed such that its xmlEncoding, documentURI, xmlVersion, inputEncoding, xmlStandalone, and all other such attributes are set to what they would be set to if the input source was parsed using LSParser.parse().
This method is always synchronous, even if the LSParser is asynchronous (LSParser.async is true).
If an error occurs while parsing, the caller is notified through the ErrorHandler instance associated with the " error-handler" parameter of the DOMConfiguration.
When calling parseWithContext, the values of the following configuration parameters will be ignored and their default values will always be used instead: " validate", " validate-if-schema", and " element-content-whitespace". Other parameters will be treated normally, and the parser is expected to call the LSParserFilter just as if a whole document was parsed.
Specified by:
parseWithContext in interface LSParser

Parameters:
input - The LSInput from which the source document is to be read. The source document must be an XML fragment, i.e. anything except a complete XML document (except in the case where the context node of type DOCUMENT_NODE, and the action is ACTION_REPLACE_CHILDREN), a DOCTYPE (internal subset), entity declaration(s), notation declaration(s), or XML or text declaration(s).
action - This parameter describes which action should be taken between the new set of nodes being inserted and the existing children of the context node. The set of possible actions is defined in ACTION_TYPES above.

Returns:
Return the node that is the result of the parse operation. If the result is more than one top-level node, the first one is returned.

Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if the content cannot replace, be inserted before, after, or as a child of the context node (see also Node.insertBefore or Node.replaceChild in [DOM Level 3 Core] ).
NOT_SUPPORTED_ERR: Raised if the LSParser doesn't support this method, or if the context node is of type Document and the DOM implementation doesn't support the replacement of the DocumentType child or Element child.
NO_MODIFICATION_ALLOWED_ERR: Raised if the context node is a read only node and the content is being appended to its child list, or if the parent node of the context node is read only node and the content is being inserted in its child list.
INVALID_STATE_ERR: Raised if the LSParser.busy attribute is true.
LSException - PARSE_ERR: Raised if the LSParser was unable to load the XML fragment. DOM applications should attach a DOMErrorHandler using the parameter " error-handler" if they wish to get details on the error.


setFilter

public void setFilter(LSParserFilter filter)
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure. The filter can choose to remove elements from the document being constructed, or to terminate the parsing early.
The filter is invoked after the operations requested by the DOMConfiguration parameters have been applied. For example, if " validate" is set to true, the validation is done before invoking the filter.
Specified by:
setFilter in interface LSParser


setParameter

public void setParameter(String name,
                         Object value)
            throws DOMException
Specified by:
setParameter in interface DOMConfiguration


warning

public void warning(SAXParseException e)
            throws SAXException
Specified by:
warning in interface ErrorHandler