Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/w3c/dom/ls/LSParser.java
86410 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* This file is available under and governed by the GNU General Public26* License version 2 only, as published by the Free Software Foundation.27* However, the following notice accompanied the original version of this28* file and, per its terms, should not be removed:29*30* Copyright (c) 2004 World Wide Web Consortium,31*32* (Massachusetts Institute of Technology, European Research Consortium for33* Informatics and Mathematics, Keio University). All Rights Reserved. This34* work is distributed under the W3C(r) Software License [1] in the hope that35* it will be useful, but WITHOUT ANY WARRANTY; without even the implied36* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.37*38* [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-2002123139*/4041package org.w3c.dom.ls;4243import org.w3c.dom.Document;44import org.w3c.dom.DOMConfiguration;45import org.w3c.dom.Node;46import org.w3c.dom.DOMException;4748/**49* An interface to an object that is able to build, or augment, a DOM tree50* from various input sources.51* <p> <code>LSParser</code> provides an API for parsing XML and building the52* corresponding DOM document structure. A <code>LSParser</code> instance53* can be obtained by invoking the54* <code>DOMImplementationLS.createLSParser()</code> method.55* <p> As specified in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]56* , when a document is first made available via the LSParser:57* <ul>58* <li> there will59* never be two adjacent nodes of type NODE_TEXT, and there will never be60* empty text nodes.61* </li>62* <li> it is expected that the <code>value</code> and63* <code>nodeValue</code> attributes of an <code>Attr</code> node initially64* return the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#AVNormalize'>XML 1.065* normalized value</a>. However, if the parameters "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-validate-if-schema'>66* validate-if-schema</a>" and "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-datatype-normalization'>67* datatype-normalization</a>" are set to <code>true</code>, depending on the attribute normalization68* used, the attribute values may differ from the ones obtained by the XML69* 1.0 attribute normalization. If the parameters "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-datatype-normalization'>70* datatype-normalization</a>" is set to <code>false</code>, the XML 1.0 attribute normalization is71* guaranteed to occur, and if the attributes list does not contain72* namespace declarations, the <code>attributes</code> attribute on73* <code>Element</code> node represents the property <b>[attributes]</b> defined in [<a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204/'>XML Information Set</a>]74* .75* </li>76* </ul>77* <p> Asynchronous <code>LSParser</code> objects are expected to also78* implement the <code>events::EventTarget</code> interface so that event79* listeners can be registered on asynchronous <code>LSParser</code>80* objects.81* <p> Events supported by asynchronous <code>LSParser</code> objects are:82* <dl>83* <dt>load</dt>84* <dd>85* The <code>LSParser</code> finishes to load the document. See also the86* definition of the <code>LSLoadEvent</code> interface. </dd>87* <dt>progress</dt>88* <dd> The89* <code>LSParser</code> signals progress as data is parsed. This90* specification does not attempt to define exactly when progress events91* should be dispatched. That is intentionally left as92* implementation-dependent. Here is one example of how an application might93* dispatch progress events: Once the parser starts receiving data, a94* progress event is dispatched to indicate that the parsing starts. From95* there on, a progress event is dispatched for every 4096 bytes of data96* that is received and processed. This is only one example, though, and97* implementations can choose to dispatch progress events at any time while98* parsing, or not dispatch them at all. See also the definition of the99* <code>LSProgressEvent</code> interface. </dd>100* </dl>101* <p ><b>Note:</b> All events defined in this specification use the102* namespace URI <code>"http://www.w3.org/2002/DOMLS"</code>.103* <p> While parsing an input source, errors are reported to the application104* through the error handler (<code>LSParser.domConfig</code>'s "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-error-handler'>105* error-handler</a>" parameter). This specification does in no way try to define all possible106* errors that can occur while parsing XML, or any other markup, but some107* common error cases are defined. The types (<code>DOMError.type</code>) of108* errors and warnings defined by this specification are:109* <dl>110* <dt>111* <code>"check-character-normalization-failure" [error]</code> </dt>112* <dd> Raised if113* the parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-check-character-normalization'>114* check-character-normalization</a>" is set to true and a string is encountered that fails normalization115* checking. </dd>116* <dt><code>"doctype-not-allowed" [fatal]</code></dt>117* <dd> Raised if the118* configuration parameter "disallow-doctype" is set to <code>true</code>119* and a doctype is encountered. </dd>120* <dt><code>"no-input-specified" [fatal]</code></dt>121* <dd>122* Raised when loading a document and no input is specified in the123* <code>LSInput</code> object. </dd>124* <dt>125* <code>"pi-base-uri-not-preserved" [warning]</code></dt>126* <dd> Raised if a processing127* instruction is encountered in a location where the base URI of the128* processing instruction can not be preserved. One example of a case where129* this warning will be raised is if the configuration parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-entities'>130* entities</a>" is set to <code>false</code> and the following XML file is parsed:131* <pre>132* <!DOCTYPE root [ <!ENTITY e SYSTEM 'subdir/myentity.ent' ]>133* <root> &e; </root></pre>134* And <code>subdir/myentity.ent</code>135* contains:136* <pre><one> <two/> </one> <?pi 3.14159?>137* <more/></pre>138* </dd>139* <dt><code>"unbound-prefix-in-entity" [warning]</code></dt>140* <dd> An141* implementation dependent warning that may be raised if the configuration142* parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-namespaces'>143* namespaces</a>" is set to <code>true</code> and an unbound namespace prefix is144* encountered in an entity's replacement text. Raising this warning is not145* enforced since some existing parsers may not recognize unbound namespace146* prefixes in the replacement text of entities. </dd>147* <dt>148* <code>"unknown-character-denormalization" [fatal]</code></dt>149* <dd> Raised if the150* configuration parameter "ignore-unknown-character-denormalizations" is151* set to <code>false</code> and a character is encountered for which the152* processor cannot determine the normalization properties. </dd>153* <dt>154* <code>"unsupported-encoding" [fatal]</code></dt>155* <dd> Raised if an unsupported156* encoding is encountered. </dd>157* <dt><code>"unsupported-media-type" [fatal]</code></dt>158* <dd>159* Raised if the configuration parameter "supported-media-types-only" is set160* to <code>true</code> and an unsupported media type is encountered. </dd>161* </dl>162* <p> In addition to raising the defined errors and warnings, implementations163* are expected to raise implementation specific errors and warnings for any164* other error and warning cases such as IO errors (file not found,165* permission denied,...), XML well-formedness errors, and so on.166* <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>Document Object Model (DOM) Level 3 Load167and Save Specification</a>.168*/169public interface LSParser {170/**171* The <code>DOMConfiguration</code> object used when parsing an input172* source. This <code>DOMConfiguration</code> is specific to the parse173* operation. No parameter values from this <code>DOMConfiguration</code>174* object are passed automatically to the <code>DOMConfiguration</code>175* object on the <code>Document</code> that is created, or used, by the176* parse operation. The DOM application is responsible for passing any177* needed parameter values from this <code>DOMConfiguration</code>178* object to the <code>DOMConfiguration</code> object referenced by the179* <code>Document</code> object.180* <br> In addition to the parameters recognized in on the <a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#DOMConfiguration'>181* DOMConfiguration</a> interface defined in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]182* , the <code>DOMConfiguration</code> objects for <code>LSParser</code>183* add or modify the following parameters:184* <dl>185* <dt>186* <code>"charset-overrides-xml-encoding"</code></dt>187* <dd>188* <dl>189* <dt><code>true</code></dt>190* <dd>[<em>optional</em>] (<em>default</em>) If a higher level protocol such as HTTP [<a href='http://www.ietf.org/rfc/rfc2616.txt'>IETF RFC 2616</a>] provides an191* indication of the character encoding of the input stream being192* processed, that will override any encoding specified in the XML193* declaration or the Text declaration (see also section 4.3.3,194* "Character Encoding in Entities", in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]).195* Explicitly setting an encoding in the <code>LSInput</code> overrides196* any encoding from the protocol. </dd>197* <dt><code>false</code></dt>198* <dd>[<em>required</em>] The parser ignores any character set encoding information from199* higher-level protocols. </dd>200* </dl></dd>201* <dt><code>"disallow-doctype"</code></dt>202* <dd>203* <dl>204* <dt>205* <code>true</code></dt>206* <dd>[<em>optional</em>] Throw a fatal <b>"doctype-not-allowed"</b> error if a doctype node is found while parsing the document. This is207* useful when dealing with things like SOAP envelopes where doctype208* nodes are not allowed. </dd>209* <dt><code>false</code></dt>210* <dd>[<em>required</em>] (<em>default</em>) Allow doctype nodes in the document. </dd>211* </dl></dd>212* <dt>213* <code>"ignore-unknown-character-denormalizations"</code></dt>214* <dd>215* <dl>216* <dt>217* <code>true</code></dt>218* <dd>[<em>required</em>] (<em>default</em>) If, while verifying full normalization when [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>] is219* supported, a processor encounters characters for which it cannot220* determine the normalization properties, then the processor will221* ignore any possible denormalizations caused by these characters.222* This parameter is ignored for [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. </dd>223* <dt>224* <code>false</code></dt>225* <dd>[<em>optional</em>] Report an fatal <b>"unknown-character-denormalization"</b> error if a character is encountered for which the processor cannot226* determine the normalization properties. </dd>227* </dl></dd>228* <dt><code>"infoset"</code></dt>229* <dd> See230* the definition of <code>DOMConfiguration</code> for a description of231* this parameter. Unlike in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]232* , this parameter will default to <code>true</code> for233* <code>LSParser</code>. </dd>234* <dt><code>"namespaces"</code></dt>235* <dd>236* <dl>237* <dt><code>true</code></dt>238* <dd>[<em>required</em>] (<em>default</em>) Perform the namespace processing as defined in [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]239* and [<a href='http://www.w3.org/TR/2004/REC-xml-names11-20040204/'>XML Namespaces 1.1</a>]240* . </dd>241* <dt><code>false</code></dt>242* <dd>[<em>optional</em>] Do not perform the namespace processing. </dd>243* </dl></dd>244* <dt>245* <code>"resource-resolver"</code></dt>246* <dd>[<em>required</em>] A reference to a <code>LSResourceResolver</code> object, or null. If247* the value of this parameter is not null when an external resource248* (such as an external XML entity or an XML schema location) is249* encountered, the implementation will request that the250* <code>LSResourceResolver</code> referenced in this parameter resolves251* the resource. </dd>252* <dt><code>"supported-media-types-only"</code></dt>253* <dd>254* <dl>255* <dt>256* <code>true</code></dt>257* <dd>[<em>optional</em>] Check that the media type of the parsed resource is a supported media258* type. If an unsupported media type is encountered, a fatal error of259* type <b>"unsupported-media-type"</b> will be raised. The media types defined in [<a href='http://www.ietf.org/rfc/rfc3023.txt'>IETF RFC 3023</a>] must always260* be accepted. </dd>261* <dt><code>false</code></dt>262* <dd>[<em>required</em>] (<em>default</em>) Accept any media type. </dd>263* </dl></dd>264* <dt><code>"validate"</code></dt>265* <dd> See the definition of266* <code>DOMConfiguration</code> for a description of this parameter.267* Unlike in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]268* , the processing of the internal subset is always accomplished, even269* if this parameter is set to <code>false</code>. </dd>270* <dt>271* <code>"validate-if-schema"</code></dt>272* <dd> See the definition of273* <code>DOMConfiguration</code> for a description of this parameter.274* Unlike in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]275* , the processing of the internal subset is always accomplished, even276* if this parameter is set to <code>false</code>. </dd>277* <dt>278* <code>"well-formed"</code></dt>279* <dd> See the definition of280* <code>DOMConfiguration</code> for a description of this parameter.281* Unlike in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]282* , this parameter cannot be set to <code>false</code>. </dd>283* </dl>284*/285public DOMConfiguration getDomConfig();286287/**288* When a filter is provided, the implementation will call out to the289* filter as it is constructing the DOM tree structure. The filter can290* choose to remove elements from the document being constructed, or to291* terminate the parsing early.292* <br> The filter is invoked after the operations requested by the293* <code>DOMConfiguration</code> parameters have been applied. For294* example, if "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-validate'>295* validate</a>" is set to <code>true</code>, the validation is done before invoking the296* filter.297*/298public LSParserFilter getFilter();299/**300* When a filter is provided, the implementation will call out to the301* filter as it is constructing the DOM tree structure. The filter can302* choose to remove elements from the document being constructed, or to303* terminate the parsing early.304* <br> The filter is invoked after the operations requested by the305* <code>DOMConfiguration</code> parameters have been applied. For306* example, if "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-validate'>307* validate</a>" is set to <code>true</code>, the validation is done before invoking the308* filter.309*/310public void setFilter(LSParserFilter filter);311312/**313* <code>true</code> if the <code>LSParser</code> is asynchronous,314* <code>false</code> if it is synchronous.315*/316public boolean getAsync();317318/**319* <code>true</code> if the <code>LSParser</code> is currently busy320* loading a document, otherwise <code>false</code>.321*/322public boolean getBusy();323324/**325* Parse an XML document from a resource identified by a326* <code>LSInput</code>.327* @param input The <code>LSInput</code> from which the source of the328* document is to be read.329* @return If the <code>LSParser</code> is a synchronous330* <code>LSParser</code>, the newly created and populated331* <code>Document</code> is returned. If the <code>LSParser</code> is332* asynchronous, <code>null</code> is returned since the document333* object may not yet be constructed when this method returns.334* @exception DOMException335* INVALID_STATE_ERR: Raised if the <code>LSParser</code>'s336* <code>LSParser.busy</code> attribute is <code>true</code>.337* @exception LSException338* PARSE_ERR: Raised if the <code>LSParser</code> was unable to load339* the XML document. DOM applications should attach a340* <code>DOMErrorHandler</code> using the parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-error-handler'>341* error-handler</a>" if they wish to get details on the error.342*/343public Document parse(LSInput input)344throws DOMException, LSException;345346/**347* Parse an XML document from a location identified by a URI reference [<a href='http://www.ietf.org/rfc/rfc2396.txt'>IETF RFC 2396</a>]. If the URI348* contains a fragment identifier (see section 4.1 in [<a href='http://www.ietf.org/rfc/rfc2396.txt'>IETF RFC 2396</a>]), the349* behavior is not defined by this specification, future versions of350* this specification may define the behavior.351* @param uri The location of the XML document to be read.352* @return If the <code>LSParser</code> is a synchronous353* <code>LSParser</code>, the newly created and populated354* <code>Document</code> is returned, or <code>null</code> if an error355* occured. If the <code>LSParser</code> is asynchronous,356* <code>null</code> is returned since the document object may not yet357* be constructed when this method returns.358* @exception DOMException359* INVALID_STATE_ERR: Raised if the <code>LSParser.busy</code>360* attribute is <code>true</code>.361* @exception LSException362* PARSE_ERR: Raised if the <code>LSParser</code> was unable to load363* the XML document. DOM applications should attach a364* <code>DOMErrorHandler</code> using the parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-error-handler'>365* error-handler</a>" if they wish to get details on the error.366*/367public Document parseURI(String uri)368throws DOMException, LSException;369370// ACTION_TYPES371/**372* Append the result of the parse operation as children of the context373* node. For this action to work, the context node must be an374* <code>Element</code> or a <code>DocumentFragment</code>.375*/376public static final short ACTION_APPEND_AS_CHILDREN = 1;377/**378* Replace all the children of the context node with the result of the379* parse operation. For this action to work, the context node must be an380* <code>Element</code>, a <code>Document</code>, or a381* <code>DocumentFragment</code>.382*/383public static final short ACTION_REPLACE_CHILDREN = 2;384/**385* Insert the result of the parse operation as the immediately preceding386* sibling of the context node. For this action to work the context387* node's parent must be an <code>Element</code> or a388* <code>DocumentFragment</code>.389*/390public static final short ACTION_INSERT_BEFORE = 3;391/**392* Insert the result of the parse operation as the immediately following393* sibling of the context node. For this action to work the context394* node's parent must be an <code>Element</code> or a395* <code>DocumentFragment</code>.396*/397public static final short ACTION_INSERT_AFTER = 4;398/**399* Replace the context node with the result of the parse operation. For400* this action to work, the context node must have a parent, and the401* parent must be an <code>Element</code> or a402* <code>DocumentFragment</code>.403*/404public static final short ACTION_REPLACE = 5;405406/**407* Parse an XML fragment from a resource identified by a408* <code>LSInput</code> and insert the content into an existing document409* at the position specified with the <code>context</code> and410* <code>action</code> arguments. When parsing the input stream, the411* context node (or its parent, depending on where the result will be412* inserted) is used for resolving unbound namespace prefixes. The413* context node's <code>ownerDocument</code> node (or the node itself if414* the node of type <code>DOCUMENT_NODE</code>) is used to resolve415* default attributes and entity references.416* <br> As the new data is inserted into the document, at least one417* mutation event is fired per new immediate child or sibling of the418* context node.419* <br> If the context node is a <code>Document</code> node and the action420* is <code>ACTION_REPLACE_CHILDREN</code>, then the document that is421* passed as the context node will be changed such that its422* <code>xmlEncoding</code>, <code>documentURI</code>,423* <code>xmlVersion</code>, <code>inputEncoding</code>,424* <code>xmlStandalone</code>, and all other such attributes are set to425* what they would be set to if the input source was parsed using426* <code>LSParser.parse()</code>.427* <br> This method is always synchronous, even if the428* <code>LSParser</code> is asynchronous (<code>LSParser.async</code> is429* <code>true</code>).430* <br> If an error occurs while parsing, the caller is notified through431* the <code>ErrorHandler</code> instance associated with the "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-error-handler'>432* error-handler</a>" parameter of the <code>DOMConfiguration</code>.433* <br> When calling <code>parseWithContext</code>, the values of the434* following configuration parameters will be ignored and their default435* values will always be used instead: "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-validate'>436* validate</a>", "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-validate-if-schema'>437* validate-if-schema</a>", and "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-element-content-whitespace'>438* element-content-whitespace</a>". Other parameters will be treated normally, and the parser is expected439* to call the <code>LSParserFilter</code> just as if a whole document440* was parsed.441* @param input The <code>LSInput</code> from which the source document442* is to be read. The source document must be an XML fragment, i.e.443* anything except a complete XML document (except in the case where444* the context node of type <code>DOCUMENT_NODE</code>, and the action445* is <code>ACTION_REPLACE_CHILDREN</code>), a DOCTYPE (internal446* subset), entity declaration(s), notation declaration(s), or XML or447* text declaration(s).448* @param contextArg The node that is used as the context for the data449* that is being parsed. This node must be a <code>Document</code>450* node, a <code>DocumentFragment</code> node, or a node of a type451* that is allowed as a child of an <code>Element</code> node, e.g. it452* cannot be an <code>Attribute</code> node.453* @param action This parameter describes which action should be taken454* between the new set of nodes being inserted and the existing455* children of the context node. The set of possible actions is456* defined in <code>ACTION_TYPES</code> above.457* @return Return the node that is the result of the parse operation. If458* the result is more than one top-level node, the first one is459* returned.460* @exception DOMException461* HIERARCHY_REQUEST_ERR: Raised if the content cannot replace, be462* inserted before, after, or as a child of the context node (see also463* <code>Node.insertBefore</code> or <code>Node.replaceChild</code> in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>DOM Level 3 Core</a>]464* ).465* <br> NOT_SUPPORTED_ERR: Raised if the <code>LSParser</code> doesn't466* support this method, or if the context node is of type467* <code>Document</code> and the DOM implementation doesn't support468* the replacement of the <code>DocumentType</code> child or469* <code>Element</code> child.470* <br> NO_MODIFICATION_ALLOWED_ERR: Raised if the context node is a471* read only node and the content is being appended to its child list,472* or if the parent node of the context node is read only node and the473* content is being inserted in its child list.474* <br> INVALID_STATE_ERR: Raised if the <code>LSParser.busy</code>475* attribute is <code>true</code>.476* @exception LSException477* PARSE_ERR: Raised if the <code>LSParser</code> was unable to load478* the XML fragment. DOM applications should attach a479* <code>DOMErrorHandler</code> using the parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-error-handler'>480* error-handler</a>" if they wish to get details on the error.481*/482public Node parseWithContext(LSInput input,483Node contextArg,484short action)485throws DOMException, LSException;486487/**488* Abort the loading of the document that is currently being loaded by489* the <code>LSParser</code>. If the <code>LSParser</code> is currently490* not busy, a call to this method does nothing.491*/492public void abort();493494}495496497