Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.xml.dom.ls
Class DomLSParser  view DomLSParser download DomLSParser.java

java.lang.Object
  extended bygnu.xml.dom.ls.DomLSParser
All Implemented Interfaces:
org.w3c.dom.DOMConfiguration, org.w3c.dom.DOMStringList, org.xml.sax.ErrorHandler, org.w3c.dom.ls.LSParser

public class DomLSParser
extends java.lang.Object
implements org.w3c.dom.ls.LSParser, org.w3c.dom.DOMConfiguration, org.w3c.dom.DOMStringList, org.xml.sax.ErrorHandler

Parser implementation for GNU DOM.


Field Summary
private  boolean async
           
private  boolean coalescing
           
private  org.xml.sax.EntityResolver entityResolver
           
private  org.xml.sax.ErrorHandler errorHandler
           
private  SAXEventSink eventSink
           
private  boolean expandEntityReferences
           
private  javax.xml.parsers.SAXParserFactory factory
           
private  org.w3c.dom.ls.LSParserFilter filter
           
private  boolean ignoreComments
           
private  boolean ignoreWhitespace
           
private  boolean namespaceAware
           
private  org.xml.sax.XMLReader reader
           
private  java.lang.String schemaType
           
private static java.util.List SUPPORTED_PARAMETERS
           
private  boolean validating
           
private  boolean xIncludeAware
           
 
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, java.lang.String schemaType)
           
 
Method Summary
 void abort()
          Abort the loading of the document that is currently being loaded by the LSParser.
 boolean canSetParameter(java.lang.String name, java.lang.Object value)
          Check if setting a parameter to a specific value is supported.
 boolean contains(java.lang.String str)
          Test if a string is part of this DOMStringList.
private  org.w3c.dom.Document doParse(org.w3c.dom.ls.LSInput input)
           
 void error(org.xml.sax.SAXParseException e)
          Receive notification of a recoverable error.
 void fatalError(org.xml.sax.SAXParseException e)
          Receive notification of a non-recoverable error.
 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.
 org.w3c.dom.DOMConfiguration getDomConfig()
          The DOMConfiguration object used when parsing an input source.
 org.w3c.dom.ls.LSParserFilter getFilter()
          When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure.
private  org.xml.sax.InputSource getInputSource(org.w3c.dom.ls.LSInput input)
           
 int getLength()
          The number of DOMStrings in the list.
 java.lang.Object getParameter(java.lang.String name)
          Return the value of a parameter if known.
 org.w3c.dom.DOMStringList getParameterNames()
          The list of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the application.
private  org.xml.sax.XMLReader getXMLReader()
           
 java.lang.String item(int i)
          Returns the indexth item in the collection.
 org.w3c.dom.Document parse(org.w3c.dom.ls.LSInput input)
          Parse an XML document from a resource identified by a LSInput.
 org.w3c.dom.Document parseURI(java.lang.String uri)
          Parse an XML document from a location identified by a URI reference [IETF RFC 2396].
 org.w3c.dom.Node parseWithContext(org.w3c.dom.ls.LSInput input, org.w3c.dom.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(org.w3c.dom.ls.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(java.lang.String name, java.lang.Object value)
          Set the value of a parameter.
 void warning(org.xml.sax.SAXParseException e)
          Receive notification of a warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUPPORTED_PARAMETERS

private static final java.util.List SUPPORTED_PARAMETERS

filter

private org.w3c.dom.ls.LSParserFilter filter

async

private final boolean async

schemaType

private java.lang.String schemaType

eventSink

private SAXEventSink eventSink

factory

private javax.xml.parsers.SAXParserFactory factory

reader

private org.xml.sax.XMLReader reader

namespaceAware

private boolean namespaceAware

ignoreWhitespace

private boolean ignoreWhitespace

expandEntityReferences

private boolean expandEntityReferences

ignoreComments

private boolean ignoreComments

coalescing

private boolean coalescing

validating

private boolean validating

xIncludeAware

private boolean xIncludeAware

entityResolver

private org.xml.sax.EntityResolver entityResolver

errorHandler

private org.xml.sax.ErrorHandler errorHandler
Constructor Detail

DomLSParser

public DomLSParser(short mode,
                   java.lang.String schemaType)
            throws org.w3c.dom.DOMException
Method Detail

getDomConfig

public org.w3c.dom.DOMConfiguration getDomConfig()
Description copied from interface: org.w3c.dom.ls.LSParser
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 org.w3c.dom.ls.LSParser

getFilter

public org.w3c.dom.ls.LSParserFilter getFilter()
Description copied from interface: org.w3c.dom.ls.LSParser
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 org.w3c.dom.ls.LSParser

setFilter

public void setFilter(org.w3c.dom.ls.LSParserFilter filter)
Description copied from interface: org.w3c.dom.ls.LSParser
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 org.w3c.dom.ls.LSParser

getAsync

public boolean getAsync()
Description copied from interface: org.w3c.dom.ls.LSParser
true if the LSParser is asynchronous, false if it is synchronous.

Specified by:
getAsync in interface org.w3c.dom.ls.LSParser

getBusy

public boolean getBusy()
Description copied from interface: org.w3c.dom.ls.LSParser
true if the LSParser is currently busy loading a document, otherwise false.

Specified by:
getBusy in interface org.w3c.dom.ls.LSParser

parse

public org.w3c.dom.Document parse(org.w3c.dom.ls.LSInput input)
                           throws org.w3c.dom.DOMException,
                                  org.w3c.dom.ls.LSException
Description copied from interface: org.w3c.dom.ls.LSParser
Parse an XML document from a resource identified by a LSInput.

Specified by:
parse in interface org.w3c.dom.ls.LSParser

parseURI

public org.w3c.dom.Document parseURI(java.lang.String uri)
                              throws org.w3c.dom.DOMException,
                                     org.w3c.dom.ls.LSException
Description copied from interface: org.w3c.dom.ls.LSParser
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 org.w3c.dom.ls.LSParser

parseWithContext

public org.w3c.dom.Node parseWithContext(org.w3c.dom.ls.LSInput input,
                                         org.w3c.dom.Node context,
                                         short action)
                                  throws org.w3c.dom.DOMException,
                                         org.w3c.dom.ls.LSException
Description copied from interface: org.w3c.dom.ls.LSParser
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 org.w3c.dom.ls.LSParser

abort

public void abort()
Description copied from interface: org.w3c.dom.ls.LSParser
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 org.w3c.dom.ls.LSParser

doParse

private org.w3c.dom.Document doParse(org.w3c.dom.ls.LSInput input)
                              throws org.w3c.dom.DOMException,
                                     org.w3c.dom.ls.LSException

getXMLReader

private org.xml.sax.XMLReader getXMLReader()
                                    throws org.w3c.dom.ls.LSException

getInputSource

private org.xml.sax.InputSource getInputSource(org.w3c.dom.ls.LSInput input)
                                        throws org.w3c.dom.ls.LSException

setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object value)
                  throws org.w3c.dom.DOMException
Description copied from interface: org.w3c.dom.DOMConfiguration
Set the value of a parameter.

Specified by:
setParameter in interface org.w3c.dom.DOMConfiguration

getParameter

public java.lang.Object getParameter(java.lang.String name)
                              throws org.w3c.dom.DOMException
Description copied from interface: org.w3c.dom.DOMConfiguration
Return the value of a parameter if known.

Specified by:
getParameter in interface org.w3c.dom.DOMConfiguration

canSetParameter

public boolean canSetParameter(java.lang.String name,
                               java.lang.Object value)
Description copied from interface: org.w3c.dom.DOMConfiguration
Check if setting a parameter to a specific value is supported.

Specified by:
canSetParameter in interface org.w3c.dom.DOMConfiguration

getParameterNames

public org.w3c.dom.DOMStringList getParameterNames()
Description copied from interface: org.w3c.dom.DOMConfiguration
The list of the parameters supported by this DOMConfiguration object and for which at least one value can be set by the application. Note that this list can also contain parameter names defined outside this specification.

Specified by:
getParameterNames in interface org.w3c.dom.DOMConfiguration

item

public java.lang.String item(int i)
Description copied from interface: org.w3c.dom.DOMStringList
Returns the indexth item in the collection. If index is greater than or equal to the number of DOMStrings in the list, this returns null.

Specified by:
item in interface org.w3c.dom.DOMStringList

getLength

public int getLength()
Description copied from interface: org.w3c.dom.DOMStringList
The number of DOMStrings in the list. The range of valid child node indices is 0 to length-1 inclusive.

Specified by:
getLength in interface org.w3c.dom.DOMStringList

contains

public boolean contains(java.lang.String str)
Description copied from interface: org.w3c.dom.DOMStringList
Test if a string is part of this DOMStringList.

Specified by:
contains in interface org.w3c.dom.DOMStringList

warning

public void warning(org.xml.sax.SAXParseException e)
             throws org.xml.sax.SAXException
Description copied from interface: org.xml.sax.ErrorHandler
Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Specified by:
warning in interface org.xml.sax.ErrorHandler

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Description copied from interface: org.xml.sax.ErrorHandler
Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Specified by:
error in interface org.xml.sax.ErrorHandler

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Description copied from interface: org.xml.sax.ErrorHandler
Receive notification of a non-recoverable error.

There is an apparent contradiction between the documentation for this method and the documentation for ContentHandler.endDocument()>ContentHandler.endDocument() 55 . Until this ambiguity is resolved in a future major release, clients should make no assumptions about whether endDocument() will or will not be invoked when the parser has reported a fatalError() or thrown an exception.

This corresponds to the definition of "fatal error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a parser would use this callback to report the violation of a well-formedness constraint.

The application must assume that the document is unusable after the parser has invoked this method, and should continue (if at all) only for the sake of collecting additional error messages: in fact, SAX parsers are free to stop reporting any other events once this method has been invoked.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler