001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.dom;
019:
020: import org.w3c.dom.Node;
021: import org.w3c.dom.ProcessingInstruction;
022:
023: /**
024: * Processing Instructions (PIs) permit documents to carry
025: * processor-specific information alongside their actual content. PIs
026: * are most common in XML, but they are supported in HTML as well.
027: *
028: * This class inherits from CharacterDataImpl to reuse its setNodeValue method.
029: *
030: * @xerces.internal
031: *
032: * @version $Id: ProcessingInstructionImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
033: * @since PR-DOM-Level-1-19980818.
034: */
035: public class ProcessingInstructionImpl extends CharacterDataImpl
036: implements ProcessingInstruction {
037:
038: //
039: // Constants
040: //
041:
042: /** Serialization version. */
043: static final long serialVersionUID = 7554435174099981510L;
044:
045: //
046: // Data
047: //
048:
049: protected String target;
050:
051: //
052: // Constructors
053: //
054:
055: /** Factory constructor. */
056: public ProcessingInstructionImpl(CoreDocumentImpl ownerDoc,
057: String target, String data) {
058: super (ownerDoc, data);
059: this .target = target;
060: }
061:
062: //
063: // Node methods
064: //
065:
066: /**
067: * A short integer indicating what type of node this is. The named
068: * constants for this value are defined in the org.w3c.dom.Node interface.
069: */
070: public short getNodeType() {
071: return Node.PROCESSING_INSTRUCTION_NODE;
072: }
073:
074: /**
075: * Returns the target
076: */
077: public String getNodeName() {
078: if (needsSyncData()) {
079: synchronizeData();
080: }
081: return target;
082: }
083:
084: //
085: // ProcessingInstruction methods
086: //
087:
088: /**
089: * A PI's "target" states what processor channel the PI's data
090: * should be directed to. It is defined differently in HTML and XML.
091: * <p>
092: * In XML, a PI's "target" is the first (whitespace-delimited) token
093: * following the "<?" token that begins the PI.
094: * <p>
095: * In HTML, target is always null.
096: * <p>
097: * Note that getNodeName is aliased to getTarget.
098: */
099: public String getTarget() {
100: if (needsSyncData()) {
101: synchronizeData();
102: }
103: return target;
104:
105: } // getTarget():String
106:
107: /**
108: * A PI's data content tells the processor what we actually want it
109: * to do. It is defined slightly differently in HTML and XML.
110: * <p>
111: * In XML, the data begins with the non-whitespace character
112: * immediately after the target -- @see getTarget().
113: * <p>
114: * In HTML, the data begins with the character immediately after the
115: * "<?" token that begins the PI.
116: * <p>
117: * Note that getNodeValue is aliased to getData
118: */
119: public String getData() {
120: if (needsSyncData()) {
121: synchronizeData();
122: }
123: return data;
124:
125: } // getData():String
126:
127: /**
128: * Change the data content of this PI.
129: * Note that setData is aliased to setNodeValue.
130: * @see #getData().
131: * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
132: */
133: public void setData(String data) {
134: // Hand off to setNodeValue for code-reuse reasons (mutation
135: // events, readonly protection, synchronizing, etc.)
136: setNodeValue(data);
137: } // setData(String)
138:
139: /**
140: * Returns the absolute base URI of this node or null if the implementation
141: * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
142: * null is returned.
143: *
144: * @return The absolute base URI of this node or null.
145: * @since DOM Level 3
146: */
147: public String getBaseURI() {
148:
149: if (needsSyncData()) {
150: synchronizeData();
151: }
152: return ownerNode.getBaseURI();
153: }
154:
155: } // class ProcessingInstructionImpl
|