Save This Page
Home » openjdk-7 » com.sun.org.apache.xerces.internal » dom » [javadoc | source]
    1   /*
    2    * reserved comment block
    3    * DO NOT REMOVE OR ALTER!
    4    */
    5   /*
    6    * Copyright 1999-2002,2004 The Apache Software Foundation.
    7    *
    8    * Licensed under the Apache License, Version 2.0 (the "License");
    9    * you may not use this file except in compliance with the License.
   10    * You may obtain a copy of the License at
   11    *
   12    *      http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing, software
   15    * distributed under the License is distributed on an "AS IS" BASIS,
   16    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   17    * See the License for the specific language governing permissions and
   18    * limitations under the License.
   19    */
   20   
   21   package com.sun.org.apache.xerces.internal.dom;
   22   
   23   import org.w3c.dom.Entity;
   24   import org.w3c.dom.Node;
   25   import org.w3c.dom.DOMException;
   26   
   27   /**
   28    * Entity nodes hold the reference data for an XML Entity -- either
   29    * parsed or unparsed. The nodeName (inherited from Node) will contain
   30    * the name (if any) of the Entity. Its data will be contained in the
   31    * Entity's children, in exactly the structure which an
   32    * EntityReference to this name will present within the document's
   33    * body.
   34    * <P>
   35    * Note that this object models the actual entity, _not_ the entity
   36    * declaration or the entity reference.
   37    * <P>
   38    * An XML processor may choose to completely expand entities before
   39    * the structure model is passed to the DOM; in this case, there will
   40    * be no EntityReferences in the DOM tree.
   41    * <P>
   42    * Quoting the 10/01 DOM Proposal,
   43    * <BLOCKQUOTE>
   44    * "The DOM Level 1 does not support editing Entity nodes; if a user
   45    * wants to make changes to the contents of an Entity, every related
   46    * EntityReference node has to be replaced in the structure model by
   47    * a clone of the Entity's contents, and then the desired changes
   48    * must be made to each of those clones instead. All the
   49    * descendants of an Entity node are readonly."
   50    * </BLOCKQUOTE>
   51    * I'm interpreting this as: It is the parser's responsibilty to call
   52    * the non-DOM operation setReadOnly(true,true) after it constructs
   53    * the Entity. Since the DOM explicitly decided not to deal with this,
   54    * _any_ answer will involve a non-DOM operation, and this is the
   55    * simplest solution.
   56    *
   57    * @xerces.internal
   58    *
   59    * @author Elena Litani, IBM
   60    * @since PR-DOM-Level-1-19980818.
   61    */
   62   public class EntityImpl
   63       extends ParentNode
   64       implements Entity {
   65   
   66       //
   67       // Constants
   68       //
   69   
   70       /** Serialization version. */
   71       static final long serialVersionUID = -3575760943444303423L;
   72   
   73       //
   74       // Data
   75       //
   76   
   77       /** Entity name. */
   78       protected String name;
   79   
   80       /** Public identifier. */
   81       protected String publicId;
   82   
   83       /** System identifier. */
   84       protected String systemId;
   85   
   86       /** Encoding */
   87       protected String encoding;
   88   
   89   
   90       /** Input Encoding */
   91       protected String inputEncoding;
   92   
   93       /** Version */
   94       protected String version;
   95   
   96   
   97       /** Notation name. */
   98       protected String notationName;
   99   
  100       /** base uri*/
  101       protected String baseURI;
  102   
  103       //
  104       // Constructors
  105       //
  106   
  107       /** Factory constructor. */
  108       public EntityImpl(CoreDocumentImpl ownerDoc, String name) {
  109           super(ownerDoc);
  110           this.name = name;
  111           isReadOnly(true);
  112       }
  113   
  114       //
  115       // Node methods
  116       //
  117   
  118       /**
  119        * A short integer indicating what type of node this is. The named
  120        * constants for this value are defined in the org.w3c.dom.Node interface.
  121        */
  122       public short getNodeType() {
  123           return Node.ENTITY_NODE;
  124       }
  125   
  126       /**
  127        * Returns the entity name
  128        */
  129       public String getNodeName() {
  130           if (needsSyncData()) {
  131               synchronizeData();
  132           }
  133           return name;
  134       }
  135       /**
  136        * Sets the node value.
  137        * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
  138        */
  139       public void setNodeValue(String x)
  140           throws DOMException {
  141           if (ownerDocument.errorChecking && isReadOnly()) {
  142               String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
  143               throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
  144           }
  145       }
  146       /**
  147        * The namespace prefix of this node
  148        * @exception DOMException
  149        *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
  150        */
  151   
  152       public void setPrefix(String prefix)
  153           throws DOMException
  154       {
  155           if (ownerDocument.errorChecking && isReadOnly()) {
  156               throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  157                     DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
  158                       "NO_MODIFICATION_ALLOWED_ERR", null));
  159           }
  160       }
  161       /** Clone node. */
  162       public Node cloneNode(boolean deep) {
  163           EntityImpl newentity = (EntityImpl)super.cloneNode(deep);
  164           newentity.setReadOnly(true, deep);
  165           return newentity;
  166       }
  167   
  168       //
  169       // Entity methods
  170       //
  171   
  172       /**
  173        * The public identifier associated with the entity. If not specified,
  174        * this will be null.
  175        */
  176       public String getPublicId() {
  177   
  178           if (needsSyncData()) {
  179               synchronizeData();
  180           }
  181           return publicId;
  182   
  183       } // getPublicId():String
  184   
  185       /**
  186        * The system identifier associated with the entity. If not specified,
  187        * this will be null.
  188        */
  189       public String getSystemId() {
  190   
  191           if (needsSyncData()) {
  192               synchronizeData();
  193           }
  194           return systemId;
  195   
  196       } // getSystemId():String
  197   
  198       /**
  199         * DOM Level 3 WD - experimental
  200         * the version number of this entity, when it is an external parsed entity.
  201         */
  202       public String getXmlVersion() {
  203   
  204          if (needsSyncData()) {
  205              synchronizeData();
  206          }
  207          return version;
  208   
  209      } // getVersion():String
  210   
  211   
  212       /**
  213        * DOM Level 3 WD - experimental
  214        * the encoding of this entity, when it is an external parsed entity.
  215        */
  216       public String getXmlEncoding() {
  217   
  218          if (needsSyncData()) {
  219              synchronizeData();
  220          }
  221   
  222          return encoding;
  223   
  224      } // getVersion():String
  225   
  226   
  227   
  228   
  229   
  230       /**
  231        * Unparsed entities -- which contain non-XML data -- have a
  232        * "notation name" which tells applications how to deal with them.
  233        * Parsed entities, which <em>are</em> in XML format, don't need this and
  234        * set it to null.
  235        */
  236       public String getNotationName() {
  237   
  238           if (needsSyncData()) {
  239               synchronizeData();
  240           }
  241           return notationName;
  242   
  243       } // getNotationName():String
  244   
  245       //
  246       // Public methods
  247       //
  248   
  249       /**
  250        * DOM Level 2: The public identifier associated with the entity. If not specified,
  251        * this will be null. */
  252       public void setPublicId(String id) {
  253   
  254           if (needsSyncData()) {
  255               synchronizeData();
  256           }
  257           publicId = id;
  258   
  259       } // setPublicId(String)
  260   
  261       /**
  262        * NON-DOM
  263        * encoding - An attribute specifying, as part of the text declaration,
  264        * the encoding of this entity, when it is an external parsed entity.
  265        * This is null otherwise
  266        *
  267        */
  268       public void setXmlEncoding(String value) {
  269           if (needsSyncData()) {
  270               synchronizeData();
  271           }
  272           encoding = value;
  273       } // setEncoding (String)
  274   
  275   
  276       /**
  277        * An attribute specifying the encoding used for this entity at the tiome
  278        * of parsing, when it is an external parsed entity. This is
  279        * <code>null</code> if it an entity from the internal subset or if it
  280        * is not known..
  281        * @since DOM Level 3
  282        */
  283       public String getInputEncoding(){
  284           if (needsSyncData()) {
  285               synchronizeData();
  286           }
  287           return inputEncoding;
  288       }
  289   
  290       /**
  291        * NON-DOM, used to set the input encoding.
  292        */
  293       public void setInputEncoding(String inputEncoding){
  294           if (needsSyncData()) {
  295               synchronizeData();
  296           }
  297           this.inputEncoding = inputEncoding;
  298       }
  299   
  300       /**
  301         * NON-DOM
  302         * version - An attribute specifying, as part of the text declaration,
  303         * the version number of this entity, when it is an external parsed entity.
  304         * This is null otherwise
  305         */
  306       public void setXmlVersion(String value) {
  307           if (needsSyncData()) {
  308               synchronizeData();
  309           }
  310           version = value;
  311       } // setVersion (String)
  312   
  313   
  314       /**
  315        * DOM Level 2: The system identifier associated with the entity. If not
  316        * specified, this will be null.
  317        */
  318       public void setSystemId(String id) {
  319           if (needsSyncData()) {
  320               synchronizeData();
  321           }
  322           systemId = id;
  323   
  324       } // setSystemId(String)
  325   
  326       /**
  327        * DOM Level 2: Unparsed entities -- which contain non-XML data -- have a
  328        * "notation name" which tells applications how to deal with them.
  329        * Parsed entities, which <em>are</em> in XML format, don't need this and
  330        * set it to null.
  331        */
  332       public void setNotationName(String name) {
  333           if (needsSyncData()) {
  334               synchronizeData();
  335           }
  336           notationName = name;
  337   
  338       } // setNotationName(String)
  339   
  340   
  341   
  342       /**
  343        * Returns the absolute base URI of this node or null if the implementation
  344        * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
  345        * null is returned.
  346        *
  347        * @return The absolute base URI of this node or null.
  348        * @since DOM Level 3
  349        */
  350       public String getBaseURI() {
  351   
  352           if (needsSyncData()) {
  353               synchronizeData();
  354           }
  355           return (baseURI!=null)?baseURI:((CoreDocumentImpl)getOwnerDocument()).getBaseURI();
  356       }
  357   
  358       /** NON-DOM: set base uri*/
  359       public void setBaseURI(String uri){
  360           if (needsSyncData()) {
  361               synchronizeData();
  362           }
  363           baseURI = uri;
  364       }
  365   
  366   
  367   
  368   } // class EntityImpl

Save This Page
Home » openjdk-7 » com.sun.org.apache.xerces.internal » dom » [javadoc | source]