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