1. /*
  2. * Copyright (c) 2004 World Wide Web Consortium,
  3. *
  4. * (Massachusetts Institute of Technology, European Research Consortium for
  5. * Informatics and Mathematics, Keio University). All Rights Reserved. This
  6. * work is distributed under the W3C(r) Software License [1] in the hope that
  7. * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  8. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *
  10. * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
  11. */
  12. package org.w3c.dom;
  13. /**
  14. * The <code>DOMConfiguration</code> interface represents the configuration
  15. * of a document and maintains a table of recognized parameters. Using the
  16. * configuration, it is possible to change
  17. * <code>Document.normalizeDocument()</code> behavior, such as replacing the
  18. * <code>CDATASection</code> nodes with <code>Text</code> nodes or
  19. * specifying the type of the schema that must be used when the validation
  20. * of the <code>Document</code> is requested. <code>DOMConfiguration</code>
  21. * 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>]
  22. * in the <code>DOMParser</code> and <code>DOMSerializer</code> interfaces.
  23. * <p> The parameter names used by the <code>DOMConfiguration</code> object
  24. * are defined throughout the DOM Level 3 specifications. Names are
  25. * case-insensitive. To avoid possible conflicts, as a convention, names
  26. * referring to parameters defined outside the DOM specification should be
  27. * made unique. Because parameters are exposed as properties in the , names
  28. * are recommended to follow the section 5.16 Identifiers of [Unicode] with the addition of the character '-' (HYPHEN-MINUS) but it is not
  29. * enforced by the DOM implementation. DOM Level 3 Core Implementations are
  30. * required to recognize all parameters defined in this specification. Some
  31. * parameter values may also be required to be supported by the
  32. * implementation. Refer to the definition of the parameter to know if a
  33. * value must be supported or not.
  34. * <p ><b>Note:</b> Parameters are similar to features and properties used in
  35. * SAX2 [<a href='http://www.saxproject.org/'>SAX</a>].
  36. * <p> The following list of parameters defined in the DOM:
  37. * <dl>
  38. * <dt>
  39. * <code>"canonical-form"</code></dt>
  40. * <dd>
  41. * <dl>
  42. * <dt><code>true</code></dt>
  43. * <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>],
  44. * such as removing the <code>DocumentType</code> node (if any) from the
  45. * tree, or removing superfluous namespace declarations from each element.
  46. * Note that this is limited to what can be represented in the DOM; in
  47. * particular, there is no way to specify the order of the attributes in the
  48. * DOM. In addition, Setting this parameter to <code>true</code> will also
  49. * set the state of the parameters listed below. Later changes to the state
  50. * of one of those parameters will revert "canonical-form" back to
  51. * <code>false</code>. Parameters set to <code>false</code>: "entities", "
  52. * normalize-characters", "cdata-sections". Parameters set to
  53. * <code>true</code>: "namespaces", "namespace-declarations", "well-formed",
  54. * "element-content-whitespace". Other parameters are not changed unless
  55. * explicitly specified in the description of the parameters.</dd>
  56. * <dt>
  57. * <code>false</code></dt>
  58. * <dd>[<em>required</em>] (<em>default</em>)Do not canonicalize the document.</dd>
  59. * </dl></dd>
  60. * <dt><code>"cdata-sections"</code></dt>
  61. * <dd>
  62. * <dl>
  63. * <dt>
  64. * <code>true</code></dt>
  65. * <dd>[<em>required</em>] (<em>default</em>)Keep <code>CDATASection</code> nodes in the document.</dd>
  66. * <dt><code>false</code></dt>
  67. * <dd>[<em>required</em>]Transform <code>CDATASection</code> nodes in the document into
  68. * <code>Text</code> nodes. The new <code>Text</code> node is then combined
  69. * with any adjacent <code>Text</code> node.</dd>
  70. * </dl></dd>
  71. * <dt>
  72. * <code>"check-character-normalization"</code></dt>
  73. * <dd>
  74. * <dl>
  75. * <dt><code>true</code></dt>
  76. * <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'>fully
  77. * normalized</a>, as defined in appendix B of [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. When a
  78. * sequence of characters is encountered that fails normalization checking,
  79. * an error with the <code>DOMError.type</code> equals to
  80. * "check-character-normalization-failure" is issued. </dd>
  81. * <dt><code>false</code></dt>
  82. * <dd>[<em>required</em>] (<em>default</em>)Do not check if characters are normalized.</dd>
  83. * </dl></dd>
  84. * <dt><code>"comments"</code></dt>
  85. * <dd>
  86. * <dl>
  87. * <dt>
  88. * <code>true</code></dt>
  89. * <dd>[<em>required</em>] (<em>default</em>)Keep <code>Comment</code> nodes in the document.</dd>
  90. * <dt><code>false</code></dt>
  91. * <dd>[<em>required</em>]Discard <code>Comment</code> nodes in the document.</dd>
  92. * </dl></dd>
  93. * <dt>
  94. * <code>"datatype-normalization"</code></dt>
  95. * <dd>
  96. * <dl>
  97. * <dt><code>true</code></dt>
  98. * <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'>XML
  99. * Schema normalized values</a> in the case of XML Schema. Since this parameter requires to have schema
  100. * information, the "validate" parameter will also be set to
  101. * <code>true</code>. Having this parameter activated when "validate" is
  102. * <code>false</code> has no effect and no schema-normalization will happen.
  103. * <p ><b>Note:</b> Since the document contains the result of the XML 1.0
  104. * processing, this parameter does not apply to attribute value
  105. * 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 only
  106. * meant for schema languages other than Document Type Definition (DTD). </dd>
  107. * <dt>
  108. * <code>false</code></dt>
  109. * <dd>[<em>required</em>] (<em>default</em>) Do not perform schema normalization on the tree. </dd>
  110. * </dl></dd>
  111. * <dt>
  112. * <code>"element-content-whitespace"</code></dt>
  113. * <dd>
  114. * <dl>
  115. * <dt><code>true</code></dt>
  116. * <dd>[<em>required</em>] (<em>default</em>)Keep all whitespaces in the document.</dd>
  117. * <dt><code>false</code></dt>
  118. * <dd>[<em>optional</em>] Discard all <code>Text</code> nodes that contain whitespaces in element
  119. * content, as described in <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>
  120. * [element content whitespace]</a>. The implementation is expected to use the attribute
  121. * <code>Text.isElementContentWhitespace</code> to determine if a
  122. * <code>Text</code> node should be discarded or not.</dd>
  123. * </dl></dd>
  124. * <dt><code>"entities"</code></dt>
  125. * <dd>
  126. * <dl>
  127. * <dt>
  128. * <code>true</code></dt>
  129. * <dd>[<em>required</em>] (<em>default</em>)Keep <code>EntityReference</code> nodes in the document.</dd>
  130. * <dt>
  131. * <code>false</code></dt>
  132. * <dd>[<em>required</em>] Remove all <code>EntityReference</code> nodes from the document,
  133. * putting the entity expansions directly in their place. <code>Text</code>
  134. * 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'>
  135. * unexpanded entity references</a> are kept in the document. </dd>
  136. * </dl>
  137. * <p ><b>Note:</b> This parameter does not affect <code>Entity</code> nodes. </dd>
  138. * <dt>
  139. * <code>"error-handler"</code></dt>
  140. * <dd>[<em>required</em>] Contains a <code>DOMErrorHandler</code> object. If an error is
  141. * encountered in the document, the implementation will call back the
  142. * <code>DOMErrorHandler</code> registered using this parameter. The
  143. * implementation may provide a default <code>DOMErrorHandler</code> object.
  144. * When called, <code>DOMError.relatedData</code> will contain the closest
  145. * node to where the error occurred. If the implementation is unable to
  146. * determine the node where the error occurs,
  147. * <code>DOMError.relatedData</code> will contain the <code>Document</code>
  148. * node. Mutations to the document from within an error handler will result
  149. * in implementation dependent behavior. </dd>
  150. * <dt><code>"infoset"</code></dt>
  151. * <dd>
  152. * <dl>
  153. * <dt>
  154. * <code>true</code></dt>
  155. * <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>]
  156. * .This forces the following parameters to <code>false</code>: "
  157. * validate-if-schema", "entities", "datatype-normalization", "cdata-sections
  158. * ".This forces the following parameters to <code>true</code>: "
  159. * namespace-declarations", "well-formed", "element-content-whitespace", "
  160. * comments", "namespaces".Other parameters are not changed unless
  161. * explicitly specified in the description of the parameters. Note that
  162. * querying this parameter with <code>getParameter</code> returns
  163. * <code>true</code> only if the individual parameters specified above are
  164. * appropriately set.</dd>
  165. * <dt><code>false</code></dt>
  166. * <dd>Setting <code>infoset</code> to
  167. * <code>false</code> has no effect.</dd>
  168. * </dl></dd>
  169. * <dt><code>"namespaces"</code></dt>
  170. * <dd>
  171. * <dl>
  172. * <dt>
  173. * <code>true</code></dt>
  174. * <dd>[<em>required</em>] (<em>default</em>) Perform the namespace processing as defined in . </dd>
  175. * <dt><code>false</code></dt>
  176. * <dd>[<em>optional</em>] Do not perform the namespace processing. </dd>
  177. * </dl></dd>
  178. * <dt>
  179. * <code>"namespace-declarations"</code></dt>
  180. * <dd> This parameter has no effect if the
  181. * parameter "namespaces" is set to <code>false</code>.
  182. * <dl>
  183. * <dt><code>true</code></dt>
  184. * <dd>[<em>required</em>] (<em>default</em>) Include namespace declaration attributes, specified or defaulted from
  185. * the schema, in the document. See also the sections "Declaring Namespaces"
  186. * in [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
  187. * and [<a href='http://www.w3.org/TR/2004/REC-xml-names11-20040204/'>XML Namespaces 1.1</a>]
  188. * .</dd>
  189. * <dt><code>false</code></dt>
  190. * <dd>[<em>required</em>]Discard all namespace declaration attributes. The namespace prefixes (
  191. * <code>Node.prefix</code>) are retained even if this parameter is set to
  192. * <code>false</code>.</dd>
  193. * </dl></dd>
  194. * <dt><code>"normalize-characters"</code></dt>
  195. * <dd>
  196. * <dl>
  197. * <dt><code>true</code></dt>
  198. * <dd>[<em>optional</em>] <a href='http://www.w3.org/TR/2004/REC-xml11-20040204/#dt-fullnorm'>Fully
  199. * 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>
  200. * <dt>
  201. * <code>false</code></dt>
  202. * <dd>[<em>required</em>] (<em>default</em>)Do not perform character normalization.</dd>
  203. * </dl></dd>
  204. * <dt><code>"schema-location"</code></dt>
  205. * <dd>[<em>optional</em>] Represent a <code>DOMString</code> object containing a list of URIs,
  206. * separated by whitespaces (characters matching the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-S'>nonterminal
  207. * production S</a> defined in section 2.3 [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]), that
  208. * represents the schemas against which validation should occur, i.e. the
  209. * current schema. The types of schemas referenced in this list must match
  210. * the type specified with <code>schema-type</code>, otherwise the behavior
  211. * of an implementation is undefined. The schemas specified using this
  212. * property take precedence to the schema information specified in the
  213. * document itself. For namespace aware schema, if a schema specified using
  214. * this property and a schema specified in the document instance (i.e. using
  215. * the <code>schemaLocation</code> attribute) in a schema document (i.e.
  216. * using schema <code>import</code> mechanisms) share the same
  217. * <code>targetNamespace</code>, the schema specified by the user using this
  218. * property will be used. If two schemas specified using this property share
  219. * the same <code>targetNamespace</code> or have no namespace, the behavior
  220. * is implementation dependent. If no location has been provided, this
  221. * parameter is <code>null</code>.
  222. * <p ><b>Note:</b> The <code>"schema-location"</code> parameter is ignored
  223. * unless the "schema-type" parameter value is set. It is strongly
  224. * recommended that <code>Document.documentURI</code> will be set so that an
  225. * implementation can successfully resolve any external entities referenced. </dd>
  226. * <dt>
  227. * <code>"schema-type"</code></dt>
  228. * <dd>[<em>optional</em>] Represent a <code>DOMString</code> object containing an absolute URI
  229. * and representing the type of the schema language used to validate a
  230. * document against. Note that no lexical checking is done on the absolute
  231. * URI. If this parameter is not set, a default value may be provided by
  232. * the implementation, based on the schema languages supported and on the
  233. * schema language used at load time. If no value is provided, this
  234. * parameter is <code>null</code>.
  235. * <p ><b>Note:</b> For XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
  236. * , applications must use the value
  237. * <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>],
  238. * applications must use the value
  239. * <code>"http://www.w3.org/TR/REC-xml"</code>. Other schema languages are
  240. * outside the scope of the W3C and therefore should recommend an absolute
  241. * URI in order to use this method. </dd>
  242. * <dt><code>"split-cdata-sections"</code></dt>
  243. * <dd>
  244. * <dl>
  245. * <dt>
  246. * <code>true</code></dt>
  247. * <dd>[<em>required</em>] (<em>default</em>)Split CDATA sections containing the CDATA section termination marker
  248. * ']]>'. When a CDATA section is split a warning is issued with a
  249. * <code>DOMError.type</code> equals to
  250. * <code>"cdata-sections-splitted"</code> and
  251. * <code>DOMError.relatedData</code> equals to the first
  252. * <code>CDATASection</code> node in document order resulting from the split.</dd>
  253. * <dt>
  254. * <code>false</code></dt>
  255. * <dd>[<em>required</em>]Signal an error if a <code>CDATASection</code> contains an
  256. * unrepresentable character.</dd>
  257. * </dl></dd>
  258. * <dt><code>"validate"</code></dt>
  259. * <dd>
  260. * <dl>
  261. * <dt><code>true</code></dt>
  262. * <dd>[<em>optional</em>] Require the validation against a schema (i.e. XML schema, DTD, any
  263. * other type or representation of schema) of the document as it is being
  264. * normalized as defined by [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. If
  265. * validation errors are found, or no schema was found, the error handler is
  266. * notified. Schema-normalized values will not be exposed according to the
  267. * schema in used unless the parameter "datatype-normalization" is
  268. * <code>true</code>. This parameter will reevaluate:
  269. * <ul>
  270. * <li> Attribute nodes with
  271. * <code>Attr.specified</code> equals to <code>false</code>, as specified in
  272. * the description of the <code>Attr</code> interface;
  273. * </li>
  274. * <li> The value of the
  275. * attribute <code>Text.isElementContentWhitespace</code> for all
  276. * <code>Text</code> nodes;
  277. * </li>
  278. * <li> The value of the attribute
  279. * <code>Attr.isId</code> for all <code>Attr</code> nodes;
  280. * </li>
  281. * <li> The attributes
  282. * <code>Element.schemaTypeInfo</code> and <code>Attr.schemaTypeInfo</code>.
  283. * </li>
  284. * </ul>
  285. * <p ><b>Note:</b> "validate-if-schema" and "validate" are mutually
  286. * exclusive, setting one of them to <code>true</code> will set the other
  287. * one to <code>false</code>. Applications should also consider setting the
  288. * parameter "well-formed" to <code>true</code>, which is the default for
  289. * that option, when validating the document. </dd>
  290. * <dt><code>false</code></dt>
  291. * <dd>[<em>required</em>] (<em>default</em>) Do not accomplish schema processing, including the internal subset
  292. * processing. Default attribute values information are kept. Note that
  293. * validation might still happen if "validate-if-schema" is <code>true</code>
  294. * . </dd>
  295. * </dl></dd>
  296. * <dt><code>"validate-if-schema"</code></dt>
  297. * <dd>
  298. * <dl>
  299. * <dt><code>true</code></dt>
  300. * <dd>[<em>optional</em>]Enable validation only if a declaration for the document element can be
  301. * found in a schema (independently of where it is found, i.e. XML schema,
  302. * DTD, or any other type or representation of schema). If validation is
  303. * enabled, this parameter has the same behavior as the parameter "validate"
  304. * set to <code>true</code>.
  305. * <p ><b>Note:</b> "validate-if-schema" and "validate" are mutually
  306. * exclusive, setting one of them to <code>true</code> will set the other
  307. * one to <code>false</code>. </dd>
  308. * <dt><code>false</code></dt>
  309. * <dd>[<em>required</em>] (<em>default</em>) No schema processing should be performed if the document has a schema,
  310. * including internal subset processing. Default attribute values
  311. * information are kept. Note that validation must still happen if "validate
  312. * " is <code>true</code>. </dd>
  313. * </dl></dd>
  314. * <dt><code>"well-formed"</code></dt>
  315. * <dd>
  316. * <dl>
  317. * <dt><code>true</code></dt>
  318. * <dd>[<em>required</em>] (<em>default</em>) Check if all nodes are XML well formed according to the XML version in
  319. * use in <code>Document.xmlVersion</code>:
  320. * <ul>
  321. * <li> check if the attribute
  322. * <code>Node.nodeName</code> contains invalid characters according to its
  323. * node type and generate a <code>DOMError</code> of type
  324. * <code>"wf-invalid-character-in-node-name"</code>, with a
  325. * <code>DOMError.SEVERITY_ERROR</code> severity, if necessary;
  326. * </li>
  327. * <li> check if
  328. * the text content inside <code>Attr</code>, <code>Element</code>,
  329. * <code>Comment</code>, <code>Text</code>, <code>CDATASection</code> nodes
  330. * for invalid characters and generate a <code>DOMError</code> of type
  331. * <code>"wf-invalid-character"</code>, with a
  332. * <code>DOMError.SEVERITY_ERROR</code> severity, if necessary;
  333. * </li>
  334. * <li> check if
  335. * the data inside <code>ProcessingInstruction</code> nodes for invalid
  336. * characters and generate a <code>DOMError</code> of type
  337. * <code>"wf-invalid-character"</code>, with a
  338. * <code>DOMError.SEVERITY_ERROR</code> severity, if necessary;
  339. * </li>
  340. * </ul></dd>
  341. * <dt>
  342. * <code>false</code></dt>
  343. * <dd>[<em>optional</em>] Do not check for XML well-formedness. </dd>
  344. * </dl></dd>
  345. * </dl>
  346. * <p> The resolution of the system identifiers associated with entities is
  347. * done using <code>Document.documentURI</code>. However, when the feature
  348. * "LS" defined in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>DOM Level 3 Load and Save</a>]
  349. * is supported by the DOM implementation, the parameter
  350. * "resource-resolver" can also be used on <code>DOMConfiguration</code>
  351. * objects attached to <code>Document</code> nodes. If this parameter is
  352. * set, <code>Document.normalizeDocument()</code> will invoke the resource
  353. * resolver instead of using <code>Document.documentURI</code>.
  354. * <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>.
  355. * @since DOM Level 3
  356. */
  357. public interface DOMConfiguration {
  358. /**
  359. * Set the value of a parameter.
  360. * @param name The name of the parameter to set.
  361. * @param value The new value or <code>null</code> if the user wishes to
  362. * unset the parameter. While the type of the value parameter is
  363. * defined as <code>DOMUserData</code>, the object type must match the
  364. * type defined by the definition of the parameter. For example, if
  365. * the parameter is "error-handler", the value must be of type
  366. * <code>DOMErrorHandler</code>.
  367. * @exception DOMException
  368. * NOT_FOUND_ERR: Raised when the parameter name is not recognized.
  369. * <br> NOT_SUPPORTED_ERR: Raised when the parameter name is recognized
  370. * but the requested value cannot be set.
  371. * <br> TYPE_MISMATCH_ERR: Raised if the value type for this parameter
  372. * name is incompatible with the expected value type.
  373. */
  374. public void setParameter(String name,
  375. Object value)
  376. throws DOMException;
  377. /**
  378. * Return the value of a parameter if known.
  379. * @param name The name of the parameter.
  380. * @return The current object associated with the specified parameter or
  381. * <code>null</code> if no object has been associated or if the
  382. * parameter is not supported.
  383. * @exception DOMException
  384. * NOT_FOUND_ERR: Raised when the parameter name is not recognized.
  385. */
  386. public Object getParameter(String name)
  387. throws DOMException;
  388. /**
  389. * Check if setting a parameter to a specific value is supported.
  390. * @param name The name of the parameter to check.
  391. * @param value An object. if <code>null</code>, the returned value is
  392. * <code>true</code>.
  393. * @return <code>true</code> if the parameter could be successfully set
  394. * to the specified value, or <code>false</code> if the parameter is
  395. * not recognized or the requested value is not supported. This does
  396. * not change the current value of the parameter itself.
  397. */
  398. public boolean canSetParameter(String name,
  399. Object value);
  400. /**
  401. * The list of the parameters supported by this
  402. * <code>DOMConfiguration</code> object and for which at least one value
  403. * can be set by the application. Note that this list can also contain
  404. * parameter names defined outside this specification.
  405. */
  406. public DOMStringList getParameterNames();
  407. }