alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (DOMConfiguration.java)

This example Java source code file (DOMConfiguration.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

domconfiguration, domexception, domstringlist, object

The DOMConfiguration.java Java example source code

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * This file is available under and governed by the GNU General Public
 * License version 2 only, as published by the Free Software Foundation.
 * However, the following notice accompanied the original version of this
 * file and, per its terms, should not be removed:
 *
 * Copyright (c) 2004 World Wide Web Consortium,
 *
 * (Massachusetts Institute of Technology, European Research Consortium for
 * Informatics and Mathematics, Keio University). All Rights Reserved. This
 * work is distributed under the W3C(r) Software License [1] in the hope that
 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
 */

package org.w3c.dom;

/**
 *  The <code>DOMConfiguration interface represents the configuration
 * of a document and maintains a table of recognized parameters. Using the
 * configuration, it is possible to change
 * <code>Document.normalizeDocument() behavior, such as replacing the
 * <code>CDATASection nodes with Text nodes or
 * specifying the type of the schema that must be used when the validation
 * of the <code>Document is requested. DOMConfiguration
 * 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]
 *  in the <code>DOMParser and DOMSerializer interfaces.
 * <p> The parameter names used by the DOMConfiguration object
 * are defined throughout the DOM Level 3 specifications. Names are
 * case-insensitive. To avoid possible conflicts, as a convention, names
 * referring to parameters defined outside the DOM specification should be
 * made unique. Because parameters are exposed as properties in names
 * are recommended to follow the section 5.16 Identifiers of [Unicode] with the addition of the character '-' (HYPHEN-MINUS) but it is not
 * enforced by the DOM implementation. DOM Level 3 Core Implementations are
 * required to recognize all parameters defined in this specification. Some
 * parameter values may also be required to be supported by the
 * implementation. Refer to the definition of the parameter to know if a
 * value must be supported or not.
 * <p >Note:  Parameters are similar to features and properties used in
 * SAX2 [<a href='http://www.saxproject.org/'>SAX].
 * <p> The following list of parameters defined in the DOM:
 * <dl>
 * <dt>
 * <code>"canonical-form"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[optional] Canonicalize the document according to the rules specified in [Canonical XML],
 * such as removing the <code>DocumentType node (if any) from the
 * tree, or removing superfluous namespace declarations from each element.
 * Note that this is limited to what can be represented in the DOM; in
 * particular, there is no way to specify the order of the attributes in the
 * DOM. In addition,  Setting this parameter to <code>true will also
 * set the state of the parameters listed below. Later changes to the state
 * of one of those parameters will revert "canonical-form" back to
 * <code>false. Parameters set to false: "entities", "
 * normalize-characters", "cdata-sections". Parameters set to
 * <code>true: "namespaces", "namespace-declarations", "well-formed",
 * "element-content-whitespace". Other parameters are not changed unless
 * explicitly specified in the description of the parameters.</dd>
 * <dt>
 * <code>false
 * <dd>[required] (default)Do not canonicalize the document.
 * </dl>
 * <dt>"cdata-sections"
 * <dd>
 * <dl>
 * <dt>
 * <code>true
 * <dd>[required] (default)Keep CDATASection nodes in the document.
 * <dt>false
 * <dd>[required]Transform CDATASection nodes in the document into
 * <code>Text nodes. The new Text node is then combined
 * with any adjacent <code>Text node.
 * </dl>
 * <dt>
 * <code>"check-character-normalization"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[optional] Check if the characters in the document are fully
 * normalized</a>, as defined in appendix B of [XML 1.1]. When a
 * sequence of characters is encountered that fails normalization checking,
 * an error with the <code>DOMError.type equals to
 * "check-character-normalization-failure" is issued. </dd>
 * <dt>false
 * <dd>[required] (default)Do not check if characters are normalized.
 * </dl>
 * <dt>"comments"
 * <dd>
 * <dl>
 * <dt>
 * <code>true
 * <dd>[required] (default)Keep Comment nodes in the document.
 * <dt>false
 * <dd>[required]Discard Comment nodes in the document.
 * </dl>
 * <dt>
 * <code>"datatype-normalization"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[optional] Expose schema normalized values in the tree, such as XML
 * Schema normalized values</a> in the case of XML Schema. Since this parameter requires to have schema
 * information, the "validate" parameter will also be set to
 * <code>true. Having this parameter activated when "validate" is
 * <code>false has no effect and no schema-normalization will happen.
 * <p >Note:  Since the document contains the result of the XML 1.0
 * processing, this parameter does not apply to attribute value
 * normalization as defined in section 3.3.3 of [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0] and is only
 * meant for schema languages other than Document Type Definition (DTD). </dd>
 * <dt>
 * <code>false
 * <dd>[required] (default) Do not perform schema normalization on the tree. 
 * </dl>
 * <dt>
 * <code>"element-content-whitespace"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[required] (default)Keep all whitespaces in the document.
 * <dt>false
 * <dd>[optional] Discard all Text nodes that contain whitespaces in element
 * content, as described in <a href='http://www.w3.org/TR/2004/REC-xml-infoset-20040204#infoitem.character'>
 * [element content whitespace]</a>. The implementation is expected to use the attribute
 * <code>Text.isElementContentWhitespace to determine if a
 * <code>Text node should be discarded or not.
 * </dl>
 * <dt>"entities"
 * <dd>
 * <dl>
 * <dt>
 * <code>true
 * <dd>[required] (default)Keep EntityReference nodes in the document.
 * <dt>
 * <code>false
 * <dd>[required] Remove all EntityReference nodes from the document,
 * putting the entity expansions directly in their place. <code>Text
 * nodes are normalized, as defined in <code>Node.normalize. Only 
 * unexpanded entity references</a> are kept in the document. 
 * </dl>
 * <p >Note:  This parameter does not affect Entity nodes. 
 * <dt>
 * <code>"error-handler"
 * <dd>[required] Contains a DOMErrorHandler object. If an error is
 * encountered in the document, the implementation will call back the
 * <code>DOMErrorHandler registered using this parameter. The
 * implementation may provide a default <code>DOMErrorHandler object.
 *  When called, <code>DOMError.relatedData will contain the closest
 * node to where the error occurred. If the implementation is unable to
 * determine the node where the error occurs,
 * <code>DOMError.relatedData will contain the Document
 * node. Mutations to the document from within an error handler will result
 * in implementation dependent behavior. </dd>
 * <dt>"infoset"
 * <dd>
 * <dl>
 * <dt>
 * <code>true
 * <dd>[required]Keep in the document the information defined in the XML Information Set [XML Information Set]
 * .This forces the following parameters to <code>false: "
 * validate-if-schema", "entities", "datatype-normalization", "cdata-sections
 * ".This forces the following parameters to <code>true: "
 * namespace-declarations", "well-formed", "element-content-whitespace", "
 * comments", "namespaces".Other parameters are not changed unless
 * explicitly specified in the description of the parameters. Note that
 * querying this parameter with <code>getParameter returns
 * <code>true only if the individual parameters specified above are
 * appropriately set.</dd>
 * <dt>false
 * <dd>Setting infoset to
 * <code>false has no effect.
 * </dl>
 * <dt>"namespaces"
 * <dd>
 * <dl>
 * <dt>
 * <code>true
 * <dd>[required] (default) Perform the namespace processing as defined in . 
 * <dt>false
 * <dd>[optional] Do not perform the namespace processing. 
 * </dl>
 * <dt>
 * <code>"namespace-declarations"
 * <dd> This parameter has no effect if the
 * parameter "namespaces" is set to <code>false.
 * <dl>
 * <dt>true
 * <dd>[required] (default) Include namespace declaration attributes, specified or defaulted from
 * the schema, in the document. See also the sections "Declaring Namespaces"
 * in [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces]
 *  and [<a href='http://www.w3.org/TR/2004/REC-xml-names11-20040204/'>XML Namespaces 1.1]
 * .</dd>
 * <dt>false
 * <dd>[required]Discard all namespace declaration attributes. The namespace prefixes (
 * <code>Node.prefix) are retained even if this parameter is set to
 * <code>false.
 * </dl>
 * <dt>"normalize-characters"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[optional] Fully
 * normalized</a> the characters in the document as defined in appendix B of [XML 1.1]. 
 * <dt>
 * <code>false
 * <dd>[required] (default)Do not perform character normalization.
 * </dl>
 * <dt>"schema-location"
 * <dd>[optional] Represent a DOMString object containing a list of URIs,
 * separated by whitespaces (characters matching the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-S'>nonterminal
 * production S</a> defined in section 2.3 [XML 1.0]), that
 * represents the schemas against which validation should occur, i.e. the
 * current schema. The types of schemas referenced in this list must match
 * the type specified with <code>schema-type, otherwise the behavior
 * of an implementation is undefined.  The schemas specified using this
 * property take precedence to the schema information specified in the
 * document itself. For namespace aware schema, if a schema specified using
 * this property and a schema specified in the document instance (i.e. using
 * the <code>schemaLocation attribute) in a schema document (i.e.
 * using schema <code>import mechanisms) share the same
 * <code>targetNamespace, the schema specified by the user using this
 * property will be used. If two schemas specified using this property share
 * the same <code>targetNamespace or have no namespace, the behavior
 * is implementation dependent.  If no location has been provided, this
 * parameter is <code>null.
 * <p >Note:  The "schema-location" parameter is ignored
 * unless the "schema-type" parameter value is set. It is strongly
 * recommended that <code>Document.documentURI will be set so that an
 * implementation can successfully resolve any external entities referenced. </dd>
 * <dt>
 * <code>"schema-type"
 * <dd>[optional] Represent a DOMString object containing an absolute URI
 * and representing the type of the schema language used to validate a
 * document against. Note that no lexical checking is done on the absolute
 * URI.  If this parameter is not set, a default value may be provided by
 * the implementation, based on the schema languages supported and on the
 * schema language used at load time. If no value is provided, this
 * parameter is <code>null.
 * <p >Note:  For XML Schema [XML Schema Part 1]
 * , applications must use the value
 * <code>"http://www.w3.org/2001/XMLSchema". For XML DTD [XML 1.0],
 * applications must use the value
 * <code>"http://www.w3.org/TR/REC-xml". Other schema languages are
 * outside the scope of the W3C and therefore should recommend an absolute
 * URI in order to use this method. </dd>
 * <dt>"split-cdata-sections"
 * <dd>
 * <dl>
 * <dt>
 * <code>true
 * <dd>[required] (default)Split CDATA sections containing the CDATA section termination marker
 * ']]>'. When a CDATA section is split a warning is issued with a
 * <code>DOMError.type equals to
 * <code>"cdata-sections-splitted" and
 * <code>DOMError.relatedData equals to the first
 * <code>CDATASection node in document order resulting from the split.
 * <dt>
 * <code>false
 * <dd>[required]Signal an error if a CDATASection contains an
 * unrepresentable character.</dd>
 * </dl>
 * <dt>"validate"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[optional] Require the validation against a schema (i.e. XML schema, DTD, any
 * other type or representation of schema) of the document as it is being
 * normalized as defined by [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0]. If
 * validation errors are found, or no schema was found, the error handler is
 * notified. Schema-normalized values will not be exposed according to the
 * schema in used unless the parameter "datatype-normalization" is
 * <code>true.  This parameter will reevaluate:
 * <ul>
 * <li> Attribute nodes with
 * <code>Attr.specified equals to false, as specified in
 * the description of the <code>Attr interface;
 * </li>
 * <li> The value of the
 * attribute <code>Text.isElementContentWhitespace for all
 * <code>Text nodes;
 * </li>
 * <li> The value of the attribute
 * <code>Attr.isId for all Attr nodes;
 * </li>
 * <li> The attributes
 * <code>Element.schemaTypeInfo and Attr.schemaTypeInfo.
 * </li>
 * </ul>
 * <p >Note:  "validate-if-schema" and "validate" are mutually
 * exclusive, setting one of them to <code>true will set the other
 * one to <code>false. Applications should also consider setting the
 * parameter "well-formed" to <code>true, which is the default for
 * that option, when validating the document. </dd>
 * <dt>false
 * <dd>[required] (default) Do not accomplish schema processing, including the internal subset
 * processing. Default attribute values information are kept. Note that
 * validation might still happen if "validate-if-schema" is <code>true
 * . </dd>
 * </dl>
 * <dt>"validate-if-schema"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[optional]Enable validation only if a declaration for the document element can be
 * found in a schema (independently of where it is found, i.e. XML schema,
 * DTD, or any other type or representation of schema). If validation is
 * enabled, this parameter has the same behavior as the parameter "validate"
 * set to <code>true.
 * <p >Note:  "validate-if-schema" and "validate" are mutually
 * exclusive, setting one of them to <code>true will set the other
 * one to <code>false. 
 * <dt>false
 * <dd>[required] (default) No schema processing should be performed if the document has a schema,
 * including internal subset processing. Default attribute values
 * information are kept. Note that validation must still happen if "validate
 * " is <code>true. 
 * </dl>
 * <dt>"well-formed"
 * <dd>
 * <dl>
 * <dt>true
 * <dd>[required] (default) Check if all nodes are XML well formed according to the XML version in
 * use in <code>Document.xmlVersion:
 * <ul>
 * <li> check if the attribute
 * <code>Node.nodeName contains invalid characters according to its
 * node type and generate a <code>DOMError of type
 * <code>"wf-invalid-character-in-node-name", with a
 * <code>DOMError.SEVERITY_ERROR severity, if necessary;
 * </li>
 * <li> check if
 * the text content inside <code>Attr, Element,
 * <code>Comment, Text, CDATASection nodes
 * for invalid characters and generate a <code>DOMError of type
 * <code>"wf-invalid-character", with a
 * <code>DOMError.SEVERITY_ERROR severity, if necessary;
 * </li>
 * <li> check if
 * the data inside <code>ProcessingInstruction nodes for invalid
 * characters and generate a <code>DOMError of type
 * <code>"wf-invalid-character", with a
 * <code>DOMError.SEVERITY_ERROR severity, if necessary;
 * </li>
 * </ul>
 * <dt>
 * <code>false
 * <dd>[optional] Do not check for XML well-formedness. 
 * </dl>
 * </dl>
 * <p> The resolution of the system identifiers associated with entities is
 * done using <code>Document.documentURI. However, when the feature
 * "LS" defined in [<a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>DOM Level 3 Load and Save]
 *  is supported by the DOM implementation, the parameter
 * "resource-resolver" can also be used on <code>DOMConfiguration
 * objects attached to <code>Document nodes. If this parameter is
 * set, <code>Document.normalizeDocument() will invoke the resource
 * resolver instead of using <code>Document.documentURI.
 * <p>See also the Document Object Model (DOM) Level 3 Core Specification.
 * @since DOM Level 3
 */
public interface DOMConfiguration {
    /**
     * Set the value of a parameter.
     * @param name The name of the parameter to set.
     * @param value  The new value or <code>null if the user wishes to
     *   unset the parameter. While the type of the value parameter is
     *   defined as <code>DOMUserData, the object type must match the
     *   type defined by the definition of the parameter. For example, if
     *   the parameter is "error-handler", the value must be of type
     *   <code>DOMErrorHandler.
     * @exception DOMException
     *    NOT_FOUND_ERR: Raised when the parameter name is not recognized.
     *   <br> NOT_SUPPORTED_ERR: Raised when the parameter name is recognized
     *   but the requested value cannot be set.
     *   <br> TYPE_MISMATCH_ERR: Raised if the value type for this parameter
     *   name is incompatible with the expected value type.
     */
    public void setParameter(String name,
                             Object value)
                             throws DOMException;

    /**
     *  Return the value of a parameter if known.
     * @param name  The name of the parameter.
     * @return  The current object associated with the specified parameter or
     *   <code>null if no object has been associated or if the
     *   parameter is not supported.
     * @exception DOMException
     *    NOT_FOUND_ERR: Raised when the parameter name is not recognized.
     */
    public Object getParameter(String name)
                               throws DOMException;

    /**
     * Check if setting a parameter to a specific value is supported.
     * @param name The name of the parameter to check.
     * @param value  An object. if <code>null, the returned value is
     *   <code>true.
     * @return  <code>true if the parameter could be successfully set
     *   to the specified value, or <code>false if the parameter is
     *   not recognized or the requested value is not supported. This does
     *   not change the current value of the parameter itself.
     */
    public boolean canSetParameter(String name,
                                   Object value);

    /**
     *  The list of the parameters supported by this
     * <code>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.
     */
    public DOMStringList getParameterNames();

}

Other Java examples (source code examples)

Here is a short list of links related to this Java DOMConfiguration.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.