Path: blob/master/src/java.xml/share/classes/org/w3c/dom/DOMConfiguration.java
40948 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;4243/**44* The <code>DOMConfiguration</code> interface represents the configuration45* of a document and maintains a table of recognized parameters. Using the46* configuration, it is possible to change47* <code>Document.normalizeDocument()</code> behavior, such as replacing the48* <code>CDATASection</code> nodes with <code>Text</code> nodes or49* specifying the type of the schema that must be used when the validation50* of the <code>Document</code> is requested. <code>DOMConfiguration</code>51* objects are also used in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>DOM Level 3 Load and Save</a>]52* in the <code>DOMParser</code> and <code>DOMSerializer</code> interfaces.53* <p> The parameter names used by the <code>DOMConfiguration</code> object54* are defined throughout the DOM Level 3 specifications. Names are55* case-insensitive. To avoid possible conflicts, as a convention, names56* referring to parameters defined outside the DOM specification should be57* made unique. Because parameters are exposed as properties in names58* are recommended to follow the section 5.16 Identifiers of [Unicode] with the addition of the character '-' (HYPHEN-MINUS) but it is not59* enforced by the DOM implementation. DOM Level 3 Core Implementations are60* required to recognize all parameters defined in this specification. Some61* parameter values may also be required to be supported by the62* implementation. Refer to the definition of the parameter to know if a63* value must be supported or not.64* <p ><b>Note:</b> Parameters are similar to features and properties used in65* SAX2 [<a href='http://www.saxproject.org/'>SAX</a>].66* <p> The following list of parameters defined in the DOM:67* <dl>68* <dt>69* <code>"canonical-form"</code></dt>70* <dd>71* <dl>72* <dt><code>true</code></dt>73* <dd>[<em>optional</em>] Canonicalize the document according to the rules specified in [<a href='http://www.w3.org/TR/2001/REC-xml-c14n-20010315'>Canonical XML</a>],74* such as removing the <code>DocumentType</code> node (if any) from the75* tree, or removing superfluous namespace declarations from each element.76* Note that this is limited to what can be represented in the DOM; in77* particular, there is no way to specify the order of the attributes in the78* DOM. In addition, Setting this parameter to <code>true</code> will also79* set the state of the parameters listed below. Later changes to the state80* of one of those parameters will revert "canonical-form" back to81* <code>false</code>. Parameters set to <code>false</code>: "entities", "82* normalize-characters", "cdata-sections". Parameters set to83* <code>true</code>: "namespaces", "namespace-declarations", "well-formed",84* "element-content-whitespace". Other parameters are not changed unless85* explicitly specified in the description of the parameters.</dd>86* <dt>87* <code>false</code></dt>88* <dd>[<em>required</em>] (<em>default</em>)Do not canonicalize the document.</dd>89* </dl></dd>90* <dt><code>"cdata-sections"</code></dt>91* <dd>92* <dl>93* <dt>94* <code>true</code></dt>95* <dd>[<em>required</em>] (<em>default</em>)Keep <code>CDATASection</code> nodes in the document.</dd>96* <dt><code>false</code></dt>97* <dd>[<em>required</em>]Transform <code>CDATASection</code> nodes in the document into98* <code>Text</code> nodes. The new <code>Text</code> node is then combined99* with any adjacent <code>Text</code> node.</dd>100* </dl></dd>101* <dt>102* <code>"check-character-normalization"</code></dt>103* <dd>104* <dl>105* <dt><code>true</code></dt>106* <dd>[<em>optional</em>] Check if the characters in the document are <a href='http://www.w3.org/TR/2004/REC-xml11-20040204/#dt-fullnorm'>fully107* normalized</a>, as defined in appendix B of [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. When a108* sequence of characters is encountered that fails normalization checking,109* an error with the <code>DOMError.type</code> equals to110* "check-character-normalization-failure" is issued. </dd>111* <dt><code>false</code></dt>112* <dd>[<em>required</em>] (<em>default</em>)Do not check if characters are normalized.</dd>113* </dl></dd>114* <dt><code>"comments"</code></dt>115* <dd>116* <dl>117* <dt>118* <code>true</code></dt>119* <dd>[<em>required</em>] (<em>default</em>)Keep <code>Comment</code> nodes in the document.</dd>120* <dt><code>false</code></dt>121* <dd>[<em>required</em>]Discard <code>Comment</code> nodes in the document.</dd>122* </dl></dd>123* <dt>124* <code>"datatype-normalization"</code></dt>125* <dd>126* <dl>127* <dt><code>true</code></dt>128* <dd>[<em>optional</em>] Expose schema normalized values in the tree, such as <a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#key-nv'>XML129* Schema normalized values</a> in the case of XML Schema. Since this parameter requires to have schema130* information, the "validate" parameter will also be set to131* <code>true</code>. Having this parameter activated when "validate" is132* <code>false</code> has no effect and no schema-normalization will happen.133* <p ><b>Note:</b> Since the document contains the result of the XML 1.0134* processing, this parameter does not apply to attribute value135* normalization as defined in section 3.3.3 of [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>] and is only136* meant for schema languages other than Document Type Definition (DTD). </dd>137* <dt>138* <code>false</code></dt>139* <dd>[<em>required</em>] (<em>default</em>) Do not perform schema normalization on the tree. </dd>140* </dl></dd>141* <dt>142* <code>"element-content-whitespace"</code></dt>143* <dd>144* <dl>145* <dt><code>true</code></dt>146* <dd>[<em>required</em>] (<em>default</em>)Keep all whitespaces in the document.</dd>147* <dt><code>false</code></dt>148* <dd>[<em>optional</em>] Discard all <code>Text</code> nodes that contain whitespaces in element149* content, as described in <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>150* [element content whitespace]</a>. The implementation is expected to use the attribute151* <code>Text.isElementContentWhitespace</code> to determine if a152* <code>Text</code> node should be discarded or not.</dd>153* </dl></dd>154* <dt><code>"entities"</code></dt>155* <dd>156* <dl>157* <dt>158* <code>true</code></dt>159* <dd>[<em>required</em>] (<em>default</em>)Keep <code>EntityReference</code> nodes in the document.</dd>160* <dt>161* <code>false</code></dt>162* <dd>[<em>required</em>] Remove all <code>EntityReference</code> nodes from the document,163* putting the entity expansions directly in their place. <code>Text</code>164* nodes are normalized, as defined in <code>Node.normalize</code>. Only <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204/#infoitem.rse'>165* unexpanded entity references</a> are kept in the document. </dd>166* </dl>167* <p ><b>Note:</b> This parameter does not affect <code>Entity</code> nodes. </dd>168* <dt>169* <code>"error-handler"</code></dt>170* <dd>[<em>required</em>] Contains a <code>DOMErrorHandler</code> object. If an error is171* encountered in the document, the implementation will call back the172* <code>DOMErrorHandler</code> registered using this parameter. The173* implementation may provide a default <code>DOMErrorHandler</code> object.174* When called, <code>DOMError.relatedData</code> will contain the closest175* node to where the error occurred. If the implementation is unable to176* determine the node where the error occurs,177* <code>DOMError.relatedData</code> will contain the <code>Document</code>178* node. Mutations to the document from within an error handler will result179* in implementation dependent behavior. </dd>180* <dt><code>"infoset"</code></dt>181* <dd>182* <dl>183* <dt>184* <code>true</code></dt>185* <dd>[<em>required</em>]Keep in the document the information defined in the XML Information Set [<a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204/'>XML Information Set</a>]186* .This forces the following parameters to <code>false</code>: "187* validate-if-schema", "entities", "datatype-normalization", "cdata-sections188* ".This forces the following parameters to <code>true</code>: "189* namespace-declarations", "well-formed", "element-content-whitespace", "190* comments", "namespaces".Other parameters are not changed unless191* explicitly specified in the description of the parameters. Note that192* querying this parameter with <code>getParameter</code> returns193* <code>true</code> only if the individual parameters specified above are194* appropriately set.</dd>195* <dt><code>false</code></dt>196* <dd>Setting <code>infoset</code> to197* <code>false</code> has no effect.</dd>198* </dl></dd>199* <dt><code>"namespaces"</code></dt>200* <dd>201* <dl>202* <dt>203* <code>true</code></dt>204* <dd>[<em>required</em>] (<em>default</em>) Perform the namespace processing as defined in . </dd>205* <dt><code>false</code></dt>206* <dd>[<em>optional</em>] Do not perform the namespace processing. </dd>207* </dl></dd>208* <dt>209* <code>"namespace-declarations"</code></dt>210* <dd> This parameter has no effect if the211* parameter "namespaces" is set to <code>false</code>.212* <dl>213* <dt><code>true</code></dt>214* <dd>[<em>required</em>] (<em>default</em>) Include namespace declaration attributes, specified or defaulted from215* the schema, in the document. See also the sections "Declaring Namespaces"216* in [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]217* and [<a href='http://www.w3.org/TR/2004/REC-xml-names11-20040204/'>XML Namespaces 1.1</a>]218* .</dd>219* <dt><code>false</code></dt>220* <dd>[<em>required</em>]Discard all namespace declaration attributes. The namespace prefixes (221* <code>Node.prefix</code>) are retained even if this parameter is set to222* <code>false</code>.</dd>223* </dl></dd>224* <dt><code>"normalize-characters"</code></dt>225* <dd>226* <dl>227* <dt><code>true</code></dt>228* <dd>[<em>optional</em>] <a href='http://www.w3.org/TR/2004/REC-xml11-20040204/#dt-fullnorm'>Fully229* normalized</a> the characters in the document as defined in appendix B of [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. </dd>230* <dt>231* <code>false</code></dt>232* <dd>[<em>required</em>] (<em>default</em>)Do not perform character normalization.</dd>233* </dl></dd>234* <dt><code>"schema-location"</code></dt>235* <dd>[<em>optional</em>] Represent a <code>DOMString</code> object containing a list of URIs,236* separated by whitespaces (characters matching the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-S'>nonterminal237* production S</a> defined in section 2.3 [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]), that238* represents the schemas against which validation should occur, i.e. the239* current schema. The types of schemas referenced in this list must match240* the type specified with <code>schema-type</code>, otherwise the behavior241* of an implementation is undefined. The schemas specified using this242* property take precedence to the schema information specified in the243* document itself. For namespace aware schema, if a schema specified using244* this property and a schema specified in the document instance (i.e. using245* the <code>schemaLocation</code> attribute) in a schema document (i.e.246* using schema <code>import</code> mechanisms) share the same247* <code>targetNamespace</code>, the schema specified by the user using this248* property will be used. If two schemas specified using this property share249* the same <code>targetNamespace</code> or have no namespace, the behavior250* is implementation dependent. If no location has been provided, this251* parameter is <code>null</code>.252* <p ><b>Note:</b> The <code>"schema-location"</code> parameter is ignored253* unless the "schema-type" parameter value is set. It is strongly254* recommended that <code>Document.documentURI</code> will be set so that an255* implementation can successfully resolve any external entities referenced. </dd>256* <dt>257* <code>"schema-type"</code></dt>258* <dd>[<em>optional</em>] Represent a <code>DOMString</code> object containing an absolute URI259* and representing the type of the schema language used to validate a260* document against. Note that no lexical checking is done on the absolute261* URI. If this parameter is not set, a default value may be provided by262* the implementation, based on the schema languages supported and on the263* schema language used at load time. If no value is provided, this264* parameter is <code>null</code>.265* <p ><b>Note:</b> For XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]266* , applications must use the value267* <code>"http://www.w3.org/2001/XMLSchema"</code>. For XML DTD [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>],268* applications must use the value269* <code>"http://www.w3.org/TR/REC-xml"</code>. Other schema languages are270* outside the scope of the W3C and therefore should recommend an absolute271* URI in order to use this method. </dd>272* <dt><code>"split-cdata-sections"</code></dt>273* <dd>274* <dl>275* <dt>276* <code>true</code></dt>277* <dd>[<em>required</em>] (<em>default</em>)Split CDATA sections containing the CDATA section termination marker278* ']]>'. When a CDATA section is split a warning is issued with a279* <code>DOMError.type</code> equals to280* <code>"cdata-sections-splitted"</code> and281* <code>DOMError.relatedData</code> equals to the first282* <code>CDATASection</code> node in document order resulting from the split.</dd>283* <dt>284* <code>false</code></dt>285* <dd>[<em>required</em>]Signal an error if a <code>CDATASection</code> contains an286* unrepresentable character.</dd>287* </dl></dd>288* <dt><code>"validate"</code></dt>289* <dd>290* <dl>291* <dt><code>true</code></dt>292* <dd>[<em>optional</em>] Require the validation against a schema (i.e. XML schema, DTD, any293* other type or representation of schema) of the document as it is being294* normalized as defined by [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. If295* validation errors are found, or no schema was found, the error handler is296* notified. Schema-normalized values will not be exposed according to the297* schema in used unless the parameter "datatype-normalization" is298* <code>true</code>. This parameter will reevaluate:299* <ul>300* <li> Attribute nodes with301* <code>Attr.specified</code> equals to <code>false</code>, as specified in302* the description of the <code>Attr</code> interface;303* </li>304* <li> The value of the305* attribute <code>Text.isElementContentWhitespace</code> for all306* <code>Text</code> nodes;307* </li>308* <li> The value of the attribute309* <code>Attr.isId</code> for all <code>Attr</code> nodes;310* </li>311* <li> The attributes312* <code>Element.schemaTypeInfo</code> and <code>Attr.schemaTypeInfo</code>.313* </li>314* </ul>315* <p ><b>Note:</b> "validate-if-schema" and "validate" are mutually316* exclusive, setting one of them to <code>true</code> will set the other317* one to <code>false</code>. Applications should also consider setting the318* parameter "well-formed" to <code>true</code>, which is the default for319* that option, when validating the document. </dd>320* <dt><code>false</code></dt>321* <dd>[<em>required</em>] (<em>default</em>) Do not accomplish schema processing, including the internal subset322* processing. Default attribute values information are kept. Note that323* validation might still happen if "validate-if-schema" is <code>true</code>324* . </dd>325* </dl></dd>326* <dt><code>"validate-if-schema"</code></dt>327* <dd>328* <dl>329* <dt><code>true</code></dt>330* <dd>[<em>optional</em>]Enable validation only if a declaration for the document element can be331* found in a schema (independently of where it is found, i.e. XML schema,332* DTD, or any other type or representation of schema). If validation is333* enabled, this parameter has the same behavior as the parameter "validate"334* set to <code>true</code>.335* <p ><b>Note:</b> "validate-if-schema" and "validate" are mutually336* exclusive, setting one of them to <code>true</code> will set the other337* one to <code>false</code>. </dd>338* <dt><code>false</code></dt>339* <dd>[<em>required</em>] (<em>default</em>) No schema processing should be performed if the document has a schema,340* including internal subset processing. Default attribute values341* information are kept. Note that validation must still happen if "validate342* " is <code>true</code>. </dd>343* </dl></dd>344* <dt><code>"well-formed"</code></dt>345* <dd>346* <dl>347* <dt><code>true</code></dt>348* <dd>[<em>required</em>] (<em>default</em>) Check if all nodes are XML well formed according to the XML version in349* use in <code>Document.xmlVersion</code>:350* <ul>351* <li> check if the attribute352* <code>Node.nodeName</code> contains invalid characters according to its353* node type and generate a <code>DOMError</code> of type354* <code>"wf-invalid-character-in-node-name"</code>, with a355* <code>DOMError.SEVERITY_ERROR</code> severity, if necessary;356* </li>357* <li> check if358* the text content inside <code>Attr</code>, <code>Element</code>,359* <code>Comment</code>, <code>Text</code>, <code>CDATASection</code> nodes360* for invalid characters and generate a <code>DOMError</code> of type361* <code>"wf-invalid-character"</code>, with a362* <code>DOMError.SEVERITY_ERROR</code> severity, if necessary;363* </li>364* <li> check if365* the data inside <code>ProcessingInstruction</code> nodes for invalid366* characters and generate a <code>DOMError</code> of type367* <code>"wf-invalid-character"</code>, with a368* <code>DOMError.SEVERITY_ERROR</code> severity, if necessary;369* </li>370* </ul></dd>371* <dt>372* <code>false</code></dt>373* <dd>[<em>optional</em>] Do not check for XML well-formedness. </dd>374* </dl></dd>375* </dl>376* <p> The resolution of the system identifiers associated with entities is377* done using <code>Document.documentURI</code>. However, when the feature378* "LS" defined in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>DOM Level 3 Load and Save</a>]379* is supported by the DOM implementation, the parameter380* "resource-resolver" can also be used on <code>DOMConfiguration</code>381* objects attached to <code>Document</code> nodes. If this parameter is382* set, <code>Document.normalizeDocument()</code> will invoke the resource383* resolver instead of using <code>Document.documentURI</code>.384* <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407'>Document Object Model (DOM) Level 3 Core Specification</a>.385* @since 1.5, DOM Level 3386*/387public interface DOMConfiguration {388/**389* Set the value of a parameter.390* @param name The name of the parameter to set.391* @param value The new value or <code>null</code> if the user wishes to392* unset the parameter. While the type of the value parameter is393* defined as <code>DOMUserData</code>, the object type must match the394* type defined by the definition of the parameter. For example, if395* the parameter is "error-handler", the value must be of type396* <code>DOMErrorHandler</code>.397* @exception DOMException398* NOT_FOUND_ERR: Raised when the parameter name is not recognized.399* <br> NOT_SUPPORTED_ERR: Raised when the parameter name is recognized400* but the requested value cannot be set.401* <br> TYPE_MISMATCH_ERR: Raised if the value type for this parameter402* name is incompatible with the expected value type.403*/404public void setParameter(String name,405Object value)406throws DOMException;407408/**409* Return the value of a parameter if known.410* @param name The name of the parameter.411* @return The current object associated with the specified parameter or412* <code>null</code> if no object has been associated or if the413* parameter is not supported.414* @exception DOMException415* NOT_FOUND_ERR: Raised when the parameter name is not recognized.416*/417public Object getParameter(String name)418throws DOMException;419420/**421* Check if setting a parameter to a specific value is supported.422* @param name The name of the parameter to check.423* @param value An object. if <code>null</code>, the returned value is424* <code>true</code>.425* @return <code>true</code> if the parameter could be successfully set426* to the specified value, or <code>false</code> if the parameter is427* not recognized or the requested value is not supported. This does428* not change the current value of the parameter itself.429*/430public boolean canSetParameter(String name,431Object value);432433/**434* The list of the parameters supported by this435* <code>DOMConfiguration</code> object and for which at least one value436* can be set by the application. Note that this list can also contain437* parameter names defined outside this specification.438*/439public DOMStringList getParameterNames();440441}442443444