KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > syntax > dom > ProcessingInstructionImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.text.syntax.dom;
21
22 import org.w3c.dom.*;
23
24 import org.netbeans.editor.TokenItem;
25
26 import org.netbeans.modules.xml.spi.dom.*;
27 import org.netbeans.modules.xml.text.syntax.XMLSyntaxSupport;
28 import org.netbeans.modules.xml.text.api.XMLDefaultTokenContext;
29 /**
30  * Read-only PI DOM node.
31  *
32  * @author Petr Kuzel
33  */

34 public final class ProcessingInstructionImpl extends SyntaxNode {
35
36
37     /** Creates a new instance of ProcessingInstructionImpl */
38     public ProcessingInstructionImpl(XMLSyntaxSupport syntax, TokenItem from, int to) {
39         super(syntax, from, to);
40     }
41
42     /**
43      * A code representing the type of the underlying object, as defined above.
44      */

45     public short getNodeType() {
46         return Node.PROCESSING_INSTRUCTION_NODE;
47     }
48     
49     /**
50      * The target of this processing instruction. XML defines this as being
51      * the first token following the markup that begins the processing
52      * instruction.
53      * @return implementation may return "xml" as it consider it a PI
54      */

55     public String JavaDoc getTarget() {
56         TokenItem target = first.getNext();
57         if (target != null) {
58             return target.getImage();
59         } else {
60             return ""; //??? or null
61
}
62     }
63
64     public String JavaDoc getNodeName() {
65         return getTarget();
66     }
67     
68     /**
69      * The content of this processing instruction. This is from the first non
70      * white space character after the target to the character immediately
71      * preceding the <code>?&gt;</code>.
72      * @return may return ""
73      */

74     public String JavaDoc getData() {
75         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
76         TokenItem next = first.getNext();
77         while (next != null && next.getTokenID() != XMLDefaultTokenContext.PI_CONTENT) {
78             next = next.getNext();
79         }
80         if (next == null) return ""; //??? or null
81
do {
82             buf.append(next.getImage());
83             next = next.getNext();
84         } while (next != null && next.getTokenID() == XMLDefaultTokenContext.PI_CONTENT);
85         return buf.toString();
86     }
87
88     public String JavaDoc getNodeValue() {
89         return getData();
90     }
91     
92     /**
93      * Once again we are read-only implemetation!
94      */

95     public void setData(String JavaDoc data) throws DOMException {
96         throw new ROException();
97     }
98
99 }
100
Popular Tags