KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.netbeans.modules.xml.text.syntax.*;
24 import org.netbeans.modules.xml.spi.dom.*;
25 import org.netbeans.editor.*;
26
27 /**
28  * DOM Text implementation. Note that it is automatically
29  * coalesced with <code>Text</code> siblings.
30  * <p>
31  * The implementation handles differently content and attribute
32  * text nodes because there is no syntax element for attribute.
33  *
34  * @author Petr Kuzel
35  */

36 public class TextImpl extends SyntaxNode implements Text {
37
38     // if attribute text node then parent otherwise null
39
private AttrImpl parent;
40     
41     /**
42      * Create content text node.
43      */

44     public TextImpl(XMLSyntaxSupport support, TokenItem from, int to) {
45         super( support, from, to );
46     }
47     
48     /**
49      * Create attribute text node.
50      */

51     TextImpl(XMLSyntaxSupport syntax, TokenItem from, AttrImpl parent) {
52         super( syntax, from, 0);
53         if (parent == null) throw new IllegalArgumentException JavaDoc();
54         this.parent = parent;
55     }
56     
57     /**
58      * Get parent node. For content text nodes may be <code>null</code>
59      */

60     public Node getParentNode() {
61         if (parent != null) {
62             return parent;
63         } else {
64             return super.getParentNode();
65         }
66     }
67
68     public Node getPreviousSibling() {
69         if (parent == null) return super.getPreviousSibling();
70         return parent.getPreviousSibling(this);
71     }
72     
73     public Node getNextSibling() {
74         if (parent == null) return super.getNextSibling();
75         return parent.getNextSibling(this);
76     }
77     
78     public short getNodeType() {
79         return Node.TEXT_NODE;
80     }
81     
82     public String JavaDoc getNodeValue() {
83         return getData();
84     }
85         
86     public Text splitText(int offset) {
87         throw new ROException();
88     }
89  
90     public String JavaDoc getData() {
91         return first.getImage();
92     }
93
94     public void setData(String JavaDoc data) {
95         throw new ROException();
96     }
97     
98     public int getLength() {
99         return getData().length();
100     }
101     
102     public String JavaDoc substringData(int offset, int count) {
103         return getData().substring(offset, offset + count + 1);
104     }
105
106     public void appendData(String JavaDoc arg) {
107         throw new ROException();
108     }
109     
110     public void insertData(int offset, String JavaDoc arg) {
111         throw new ROException();
112     }
113
114
115     public void deleteData(int offset, int count) {
116         throw new ROException();
117     }
118
119     public void replaceData(int offset, int count, String JavaDoc arg) {
120         throw new ROException();
121     }
122
123
124     /**
125      * Dump content of the nod efor debug purposes.
126      */

127     public String JavaDoc toString() {
128         return "Text" + super.toString() + " value: '" + getNodeValue() + "'";
129     }
130
131     
132 }
133
134
Popular Tags