View Javadoc
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.Node;
24  import org.w3c.dom.ProcessingInstruction;
25  
26  /**
27   * Processing Instructions (PIs) permit documents to carry
28   * processor-specific information alongside their actual content. PIs
29   * are most common in XML, but they are supported in HTML as well.
30   *
31   * This class inherits from CharacterDataImpl to reuse its setNodeValue method.
32   *
33   * @xerces.internal
34   *
35   * @since  PR-DOM-Level-1-19980818.
36   */
37  public class ProcessingInstructionImpl
38      extends CharacterDataImpl
39      implements ProcessingInstruction {
40  
41      //
42      // Constants
43      //
44  
45      /** Serialization version. */
46      static final long serialVersionUID = 7554435174099981510L;
47  
48      //
49      // Data
50      //
51  
52      protected String target;
53  
54      //
55      // Constructors
56      //
57  
58      /** Factory constructor. */
59      public ProcessingInstructionImpl(CoreDocumentImpl ownerDoc,
60                                       String target, String data) {
61          super(ownerDoc, data);
62          this.target = target;
63      }
64  
65      //
66      // Node methods
67      //
68  
69      /**
70       * A short integer indicating what type of node this is. The named
71       * constants for this value are defined in the org.w3c.dom.Node interface.
72       */
73      public short getNodeType() {
74          return Node.PROCESSING_INSTRUCTION_NODE;
75      }
76  
77      /**
78       * Returns the target
79       */
80      public String getNodeName() {
81          if (needsSyncData()) {
82              synchronizeData();
83          }
84          return target;
85      }
86  
87      //
88      // ProcessingInstruction methods
89      //
90  
91      /**
92       * A PI's "target" states what processor channel the PI's data
93       * should be directed to. It is defined differently in HTML and XML.
94       * <p>
95       * In XML, a PI's "target" is the first (whitespace-delimited) token
96       * following the "<?" token that begins the PI.
97       * <p>
98       * In HTML, target is always null.
99       * <p>
100      * Note that getNodeName is aliased to getTarget.
101      */
102     public String getTarget() {
103         if (needsSyncData()) {
104             synchronizeData();
105         }
106         return target;
107 
108     } // getTarget():String
109 
110     /**
111      * A PI's data content tells the processor what we actually want it
112      * to do.  It is defined slightly differently in HTML and XML.
113      * <p>
114      * In XML, the data begins with the non-whitespace character
115      * immediately after the target -- @see getTarget().
116      * <p>
117      * In HTML, the data begins with the character immediately after the
118      * "&lt;?" token that begins the PI.
119      * <p>
120      * Note that getNodeValue is aliased to getData
121      */
122     public String getData() {
123         if (needsSyncData()) {
124             synchronizeData();
125         }
126         return data;
127 
128     } // getData():String
129 
130     /**
131      * Change the data content of this PI.
132      * Note that setData is aliased to setNodeValue.
133      * @see #getData().
134      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
135      */
136     public void setData(String data) {
137         // Hand off to setNodeValue for code-reuse reasons (mutation
138         // events, readonly protection, synchronizing, etc.)
139         setNodeValue(data);
140     } // setData(String)
141 
142 
143 
144    /**
145      * Returns the absolute base URI of this node or null if the implementation
146      * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
147      * null is returned.
148      *
149      * @return The absolute base URI of this node or null.
150      * @since DOM Level 3
151      */
152     public String getBaseURI() {
153 
154         if (needsSyncData()) {
155             synchronizeData();
156         }
157         return ownerNode.getBaseURI();
158     }
159 
160 
161 } // class ProcessingInstructionImpl