jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/NotationImpl.java
author joehw
Thu, 28 Jul 2016 22:58:41 -0700
changeset 39907 db51759e3695
parent 25868 686eef1e7a79
child 44797 8b3b3b911b8a
permissions -rw-r--r--
8158084: Catalog API: JAXP XML Processor Support Reviewed-by: lancea, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2002,2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xerces.internal.dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
import com.sun.org.apache.xerces.internal.util.URI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import org.w3c.dom.DOMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import org.w3c.dom.Notation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * Notations are how the Document Type Description (DTD) records hints
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * about the format of an XML "unparsed entity" -- in other words,
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * non-XML data bound to this document type, which some applications
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * may wish to consult when manipulating the document. A Notation
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * represents a name-value pair, with its nodeName being set to the
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * declared name of the notation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * Notations are also used to formally declare the "targets" of
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * Processing Instructions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * Note that the Notation's data is non-DOM information; the DOM only
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * records what and where it is.
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * See the XML 1.0 spec, sections 4.7 and 2.6, for more info.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * Level 1 of the DOM does not support editing Notation contents.
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * @since  PR-DOM-Level-1-19980818.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
public class NotationImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    extends NodeImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    implements Notation {
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    // Constants
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    /** Serialization version. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    static final long serialVersionUID = -764632195890658402L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    /** Notation name. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    protected String name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /** Public identifier. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    protected String publicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    /** System identifier. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    protected String systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    /** Base URI*/
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    protected String baseURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    /** Factory constructor. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    public NotationImpl(CoreDocumentImpl ownerDoc, String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        super(ownerDoc);
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        this.name = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    // Node methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     * A short integer indicating what type of node this is. The named
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * constants for this value are defined in the org.w3c.dom.Node interface.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    public short getNodeType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        return Node.NOTATION_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     * Returns the notation name
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    public String getNodeName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
        return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    // Notation methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * The Public Identifier for this Notation. If no public identifier
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     * was specified, this will be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    public String getPublicId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        return publicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    } // getPublicId():String
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * The System Identifier for this Notation. If no system identifier
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * was specified, this will be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        return systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    } // getSystemId():String
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    // Public methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     * NON-DOM: The Public Identifier for this Notation. If no public
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     * identifier was specified, this will be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    public void setPublicId(String id) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
        if (isReadOnly()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                throw new DOMException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
                DOMException.NO_MODIFICATION_ALLOWED_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
                DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
        publicId = id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    } // setPublicId(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     * NON-DOM: The System Identifier for this Notation. If no system
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     * identifier was specified, this will be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    public void setSystemId(String id) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        if(isReadOnly()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                throw new DOMException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                DOMException.NO_MODIFICATION_ALLOWED_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
        systemId = id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    } // setSystemId(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     * Returns the absolute base URI of this node or null if the implementation
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     * null is returned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
     * @return The absolute base URI of this node or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * @since DOM Level 3
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    public String getBaseURI() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        if (baseURI != null && baseURI.length() != 0 ) {// attribute value is always empty string
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                return new URI(baseURI).toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
            catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException e){
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                // REVISIT: what should happen in this case?
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
        return baseURI;
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    /** NON-DOM: set base uri*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    public void setBaseURI(String uri){
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        baseURI = uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
} // class NotationImpl