annotate NGSrich_0.5.5/src/org/jdom/Text.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 /*--
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 $Id: Text.java,v 1.25 2007/11/10 05:28:59 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 All rights reserved.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 modification, are permitted provided that the following conditions
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 are met:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 1. Redistributions of source code must retain the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 notice, this list of conditions, and the following disclaimer.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 2. Redistributions in binary form must reproduce the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 notice, this list of conditions, and the disclaimer that follows
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 these conditions in the documentation and/or other materials
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 provided with the distribution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 3. The name "JDOM" must not be used to endorse or promote products
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 derived from this software without prior written permission. For
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 written permission, please contact <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 4. Products derived from this software may not be called "JDOM", nor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 may "JDOM" appear in their name, without prior written permission
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 from the JDOM Project Management <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 In addition, we request (but do not require) that you include in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 end-user documentation provided with the redistribution and/or in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 software itself an acknowledgement equivalent to the following:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 "This product includes software developed by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 JDOM Project (http://www.jdom.org/)."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 Alternatively, the acknowledgment may be graphical using the logos
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 available at http://www.jdom.org/images/logos.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 SUCH DAMAGE.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 This software consists of voluntary contributions made by many
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 individuals on behalf of the JDOM Project and was originally
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 on the JDOM Project, please see <http://www.jdom.org/>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 package org.jdom;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 * Character-based XML content. Provides a modular, parentable method of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 * representing text. Text makes no guarantees about the underlying textual
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 * representation of character data, but does expose that data as a Java String.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 * @version $Revision: 1.25 $, $Date: 2007/11/10 05:28:59 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 * @author Bradley S. Huffman
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 public class Text extends Content {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 "@(#) $RCSfile: Text.java,v $ $Revision: 1.25 $ $Date: 2007/11/10 05:28:59 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 static final String EMPTY_STRING = "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 /** The actual character content */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 // XXX See http://www.servlets.com/archive/servlet/ReadMsg?msgId=8612
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 // from elharo for a description of why Java characters may not suffice
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 // long term
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 protected String value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 * This is the protected, no-args constructor standard in all JDOM
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 * classes. It allows subclassers to get a raw instance with no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 * initialization.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 protected Text() { }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 * This constructor creates a new <code>Text</code> node, with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 * supplied string value as it's character content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 * @param str the node's character content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 * @throws IllegalDataException if <code>str</code> contains an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 * illegal character such as a vertical tab (as determined
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 * by {@link org.jdom.Verifier#checkCharacterData})
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 public Text(String str) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 setText(str);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 * This returns the value of this <code>Text</code> node as a Java
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 * <code>String</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 * @return <code>String</code> - character content of this node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 public String getText() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 return value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 * This returns the textual content with all surrounding whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 * removed. If only whitespace exists, the empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 * @return trimmed text content or empty string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 public String getTextTrim() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 return getText().trim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 * This returns the textual content with all surrounding whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 * removed and internal whitespace normalized to a single space. If
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 * only whitespace exists, the empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 * @return normalized text content or empty string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 public String getTextNormalize() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 return normalizeString(getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 * This returns a new string with all surrounding whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 * removed and internal whitespace normalized to a single space. If
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 * only whitespace exists, the empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 * Per XML 1.0 Production 3 whitespace includes: #x20, #x9, #xD, #xA
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 * @param str string to be normalized.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 * @return normalized string or empty string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 public static String normalizeString(String str) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 if (str == null)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 return EMPTY_STRING;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 char[] c = str.toCharArray();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 char[] n = new char[c.length];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 boolean white = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 int pos = 0;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 for (int i = 0; i < c.length; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 if (" \t\n\r".indexOf(c[i]) != -1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 if (!white) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 n[pos++] = ' ';
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 white = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 n[pos++] = c[i];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 white = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 if (white && pos > 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 pos--;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 return new String(n, 0, pos);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 * This will set the value of this <code>Text</code> node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 * @param str value for node's content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 * @return the object on which the method was invoked
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 * @throws IllegalDataException if <code>str</code> contains an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 * illegal character such as a vertical tab (as determined
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 * by {@link org.jdom.Verifier#checkCharacterData})
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 public Text setText(String str) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 String reason;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 if (str == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 value = EMPTY_STRING;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 if ((reason = Verifier.checkCharacterData(str)) != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 throw new IllegalDataException(str, "character content", reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 value = str;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 * This will append character content to whatever content already
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 * exists within this <code>Text</code> node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 * @param str character content to append.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 * @throws IllegalDataException if <code>str</code> contains an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 * illegal character such as a vertical tab (as determined
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 * by {@link org.jdom.Verifier#checkCharacterData})
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 public void append(String str) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 String reason;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 if (str == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 if ((reason = Verifier.checkCharacterData(str)) != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 throw new IllegalDataException(str, "character content", reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 if (str == EMPTY_STRING)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 value = str;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 else value += str;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 * This will append the content of another <code>Text</code> node
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 * to this node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 * @param text Text node to append.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 public void append(Text text) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 if (text == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 value += text.getText();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 * Returns the XPath 1.0 string value of this element, which is the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 * text itself.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 * @return the text
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 public String getValue() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 return value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 * This returns a <code>String</code> representation of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 * <code>Text</code> node, suitable for debugging. If the XML
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 * representation of the <code>Text</code> node is desired,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 * either <code>{@link #getText}</code> or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 * {@link org.jdom.output.XMLOutputter#outputString(Text)}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 * should be used.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 * @return <code>String</code> - information about this node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 public String toString() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 return new StringBuffer(64)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 .append("[Text: ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 .append(getText())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 .append("]")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 .toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 * This will return a clone of this <code>Text</code> node, with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 * same character content, but no parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 * @return <code>Text</code> - cloned node.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265 public Object clone() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 Text text = (Text)super.clone();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 text.value = value;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 return text;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 }