001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.dom;
059:
060: import org.w3c.dom.Node;
061: import org.w3c.dom.ProcessingInstruction;
062:
063: /**
064: * Processing Instructions (PIs) permit documents to carry
065: * processor-specific information alongside their actual content. PIs
066: * are most common in XML, but they are supported in HTML as well.
067: *
068: * This class inherits from CharacterDataImpl to reuse its setNodeValue method.
069: *
070: * @version
071: * @since PR-DOM-Level-1-19980818.
072: */
073: public class ProcessingInstructionImpl extends CharacterDataImpl
074: implements ProcessingInstruction {
075:
076: //
077: // Constants
078: //
079:
080: /** Serialization version. */
081: static final long serialVersionUID = 7554435174099981510L;
082:
083: //
084: // Data
085: //
086:
087: protected String target;
088:
089: //
090: // Constructors
091: //
092:
093: /** Factory constructor. */
094: public ProcessingInstructionImpl(CoreDocumentImpl ownerDoc,
095: String target, String data) {
096: super (ownerDoc, data);
097: this .target = target;
098: }
099:
100: //
101: // Node methods
102: //
103:
104: /**
105: * A short integer indicating what type of node this is. The named
106: * constants for this value are defined in the org.w3c.dom.Node interface.
107: */
108: public short getNodeType() {
109: return Node.PROCESSING_INSTRUCTION_NODE;
110: }
111:
112: /**
113: * Returns the target
114: */
115: public String getNodeName() {
116: if (needsSyncData()) {
117: synchronizeData();
118: }
119: return target;
120: }
121:
122: //
123: // ProcessingInstruction methods
124: //
125:
126: /**
127: * A PI's "target" states what processor channel the PI's data
128: * should be directed to. It is defined differently in HTML and XML.
129: * <p>
130: * In XML, a PI's "target" is the first (whitespace-delimited) token
131: * following the "<?" token that begins the PI.
132: * <p>
133: * In HTML, target is always null.
134: * <p>
135: * Note that getNodeName is aliased to getTarget.
136: */
137: public String getTarget() {
138: if (needsSyncData()) {
139: synchronizeData();
140: }
141: return target;
142:
143: } // getTarget():String
144:
145: /**
146: * A PI's data content tells the processor what we actually want it
147: * to do. It is defined slightly differently in HTML and XML.
148: * <p>
149: * In XML, the data begins with the non-whitespace character
150: * immediately after the target -- @see getTarget().
151: * <p>
152: * In HTML, the data begins with the character immediately after the
153: * "<?" token that begins the PI.
154: * <p>
155: * Note that getNodeValue is aliased to getData
156: */
157: public String getData() {
158: if (needsSyncData()) {
159: synchronizeData();
160: }
161: return data;
162:
163: } // getData():String
164:
165: /**
166: * Change the data content of this PI.
167: * Note that setData is aliased to setNodeValue.
168: * @see #getData().
169: * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
170: */
171: public void setData(String data) {
172: // Hand off to setNodeValue for code-reuse reasons (mutation
173: // events, readonly protection, synchronizing, etc.)
174: setNodeValue(data);
175: } // setData(String)
176:
177: } // class ProcessingInstructionImpl
|