KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > utils > XMLStringDefault


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: XMLStringDefault.java,v 1.3 2004/02/17 04:21:14 minchau Exp $
18  */

19 package org.apache.xml.utils;
20
21 import java.util.Locale JavaDoc;
22
23 /**
24  * The default implementation of the XMLString interface,
25  * which is just a simple wrapper of a String object.
26  */

27 public class XMLStringDefault implements XMLString
28 {
29
30   private String JavaDoc m_str;
31   
32   /**
33    * Create a XMLStringDefault object from a String
34    */

35   public XMLStringDefault(String JavaDoc str)
36   {
37     m_str = str;
38   }
39   
40   /**
41    * Directly call the
42    * characters method on the passed ContentHandler for the
43    * string-value. Multiple calls to the
44    * ContentHandler's characters methods may well occur for a single call to
45    * this method.
46    *
47    * @param ch A non-null reference to a ContentHandler.
48    *
49    * @throws org.xml.sax.SAXException
50    */

51   public void dispatchCharactersEvents(org.xml.sax.ContentHandler JavaDoc ch)
52     throws org.xml.sax.SAXException JavaDoc
53   {
54   }
55
56   /**
57    * Directly call the
58    * comment method on the passed LexicalHandler for the
59    * string-value.
60    *
61    * @param lh A non-null reference to a LexicalHandler.
62    *
63    * @throws org.xml.sax.SAXException
64    */

65   public void dispatchAsComment(org.xml.sax.ext.LexicalHandler JavaDoc lh)
66     throws org.xml.sax.SAXException JavaDoc
67   {
68   }
69     
70   /**
71    * Conditionally trim all leading and trailing whitespace in the specified String.
72    * All strings of white space are
73    * replaced by a single space character (#x20), except spaces after punctuation which
74    * receive double spaces if doublePunctuationSpaces is true.
75    * This function may be useful to a formatter, but to get first class
76    * results, the formatter should probably do it's own white space handling
77    * based on the semantics of the formatting object.
78    *
79    * @param trimHead Trim leading whitespace?
80    * @param trimTail Trim trailing whitespace?
81    * @param doublePunctuationSpaces Use double spaces for punctuation?
82    * @return The trimmed string.
83    */

84   public XMLString fixWhiteSpace(boolean trimHead,
85                                  boolean trimTail,
86                                  boolean doublePunctuationSpaces)
87   {
88     return new XMLStringDefault(m_str.trim());
89   }
90
91   /**
92    * Returns the length of this string.
93    *
94    * @return the length of the sequence of characters represented by this
95    * object.
96    */

97   public int length()
98   {
99     return m_str.length();
100   }
101
102   /**
103    * Returns the character at the specified index. An index ranges
104    * from <code>0</code> to <code>length() - 1</code>. The first character
105    * of the sequence is at index <code>0</code>, the next at index
106    * <code>1</code>, and so on, as for array indexing.
107    *
108    * @param index the index of the character.
109    * @return the character at the specified index of this string.
110    * The first character is at index <code>0</code>.
111    * @exception IndexOutOfBoundsException if the <code>index</code>
112    * argument is negative or not less than the length of this
113    * string.
114    */

115   public char charAt(int index)
116   {
117     return m_str.charAt(index);
118   }
119
120   /**
121    * Copies characters from this string into the destination character
122    * array.
123    *
124    * @param srcBegin index of the first character in the string
125    * to copy.
126    * @param srcEnd index after the last character in the string
127    * to copy.
128    * @param dst the destination array.
129    * @param dstBegin the start offset in the destination array.
130    * @exception IndexOutOfBoundsException If any of the following
131    * is true:
132    * <ul><li><code>srcBegin</code> is negative.
133    * <li><code>srcBegin</code> is greater than <code>srcEnd</code>
134    * <li><code>srcEnd</code> is greater than the length of this
135    * string
136    * <li><code>dstBegin</code> is negative
137    * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
138    * <code>dst.length</code></ul>
139    * @exception NullPointerException if <code>dst</code> is <code>null</code>
140    */

141   public void getChars(int srcBegin, int srcEnd, char dst[],
142                                 int dstBegin)
143   {
144     int destIndex = dstBegin;
145     for (int i = srcBegin; i < srcEnd; i++)
146     {
147       dst[destIndex++] = m_str.charAt(i);
148     }
149   }
150                                 
151   /**
152    * Compares this string to the specified object.
153    * The result is <code>true</code> if and only if the argument is not
154    * <code>null</code> and is a <code>String</code> object that represents
155    * the same sequence of characters as this object.
156    *
157    * @param anObject the object to compare this <code>String</code>
158    * against.
159    * @return <code>true</code> if the <code>String </code>are equal;
160    * <code>false</code> otherwise.
161    * @see java.lang.String#compareTo(java.lang.String)
162    * @see java.lang.String#equalsIgnoreCase(java.lang.String)
163    */

164   public boolean equals(XMLString anObject)
165   {
166     return m_str.equals(anObject.toString());
167   }
168
169
170   /**
171    * Compares this string to the specified object.
172    * The result is <code>true</code> if and only if the argument is not
173    * <code>null</code> and is a <code>String</code> object that represents
174    * the same sequence of characters as this object.
175    *
176    * @param anObject the object to compare this <code>String</code>
177    * against.
178    * @return <code>true</code> if the <code>String </code>are equal;
179    * <code>false</code> otherwise.
180    * @see java.lang.String#compareTo(java.lang.String)
181    * @see java.lang.String#equalsIgnoreCase(java.lang.String)
182    */

183   public boolean equals(Object JavaDoc anObject)
184   {
185     return m_str.equals(anObject);
186   }
187
188   /**
189    * Compares this <code>String</code> to another <code>String</code>,
190    * ignoring case considerations. Two strings are considered equal
191    * ignoring case if they are of the same length, and corresponding
192    * characters in the two strings are equal ignoring case.
193    *
194    * @param anotherString the <code>String</code> to compare this
195    * <code>String</code> against.
196    * @return <code>true</code> if the argument is not <code>null</code>
197    * and the <code>String</code>s are equal,
198    * ignoring case; <code>false</code> otherwise.
199    * @see #equals(Object)
200    * @see java.lang.Character#toLowerCase(char)
201    * @see java.lang.Character#toUpperCase(char)
202    */

203   public boolean equalsIgnoreCase(String JavaDoc anotherString)
204   {
205     return m_str.equalsIgnoreCase(anotherString);
206   }
207
208   /**
209    * Compares two strings lexicographically.
210    *
211    * @param anotherString the <code>String</code> to be compared.
212    * @return the value <code>0</code> if the argument string is equal to
213    * this string; a value less than <code>0</code> if this string
214    * is lexicographically less than the string argument; and a
215    * value greater than <code>0</code> if this string is
216    * lexicographically greater than the string argument.
217    * @exception java.lang.NullPointerException if <code>anotherString</code>
218    * is <code>null</code>.
219    */

220   public int compareTo(XMLString anotherString)
221   {
222     return m_str.compareTo(anotherString.toString());
223   }
224
225   /**
226    * Compares two strings lexicographically, ignoring case considerations.
227    * This method returns an integer whose sign is that of
228    * <code>this.toUpperCase().toLowerCase().compareTo(
229    * str.toUpperCase().toLowerCase())</code>.
230    * <p>
231    * Note that this method does <em>not</em> take locale into account,
232    * and will result in an unsatisfactory ordering for certain locales.
233    * The java.text package provides <em>collators</em> to allow
234    * locale-sensitive ordering.
235    *
236    * @param str the <code>String</code> to be compared.
237    * @return a negative integer, zero, or a positive integer as the
238    * the specified String is greater than, equal to, or less
239    * than this String, ignoring case considerations.
240    * @see java.text.Collator#compare(String, String)
241    * @since 1.2
242    */

243   public int compareToIgnoreCase(XMLString str)
244   {
245     return m_str.compareToIgnoreCase(str.toString());
246   }
247
248   /**
249    * Tests if this string starts with the specified prefix beginning
250    * a specified index.
251    *
252    * @param prefix the prefix.
253    * @param toffset where to begin looking in the string.
254    * @return <code>true</code> if the character sequence represented by the
255    * argument is a prefix of the substring of this object starting
256    * at index <code>toffset</code>; <code>false</code> otherwise.
257    * The result is <code>false</code> if <code>toffset</code> is
258    * negative or greater than the length of this
259    * <code>String</code> object; otherwise the result is the same
260    * as the result of the expression
261    * <pre>
262    * this.subString(toffset).startsWith(prefix)
263    * </pre>
264    * @exception java.lang.NullPointerException if <code>prefix</code> is
265    * <code>null</code>.
266    */

267   public boolean startsWith(String JavaDoc prefix, int toffset)
268   {
269     return m_str.startsWith(prefix, toffset);
270   }
271
272   /**
273    * Tests if this string starts with the specified prefix beginning
274    * a specified index.
275    *
276    * @param prefix the prefix.
277    * @param toffset where to begin looking in the string.
278    * @return <code>true</code> if the character sequence represented by the
279    * argument is a prefix of the substring of this object starting
280    * at index <code>toffset</code>; <code>false</code> otherwise.
281    * The result is <code>false</code> if <code>toffset</code> is
282    * negative or greater than the length of this
283    * <code>String</code> object; otherwise the result is the same
284    * as the result of the expression
285    * <pre>
286    * this.subString(toffset).startsWith(prefix)
287    * </pre>
288    * @exception java.lang.NullPointerException if <code>prefix</code> is
289    * <code>null</code>.
290    */

291   public boolean startsWith(XMLString prefix, int toffset)
292   {
293     return m_str.startsWith(prefix.toString(), toffset);
294   }
295
296   /**
297    * Tests if this string starts with the specified prefix.
298    *
299    * @param prefix the prefix.
300    * @return <code>true</code> if the character sequence represented by the
301    * argument is a prefix of the character sequence represented by
302    * this string; <code>false</code> otherwise.
303    * Note also that <code>true</code> will be returned if the
304    * argument is an empty string or is equal to this
305    * <code>String</code> object as determined by the
306    * {@link #equals(Object)} method.
307    * @exception java.lang.NullPointerException if <code>prefix</code> is
308    * <code>null</code>.
309    * @since JDK1. 0
310    */

311   public boolean startsWith(String JavaDoc prefix)
312   {
313     return m_str.startsWith(prefix);
314   }
315
316   /**
317    * Tests if this string starts with the specified prefix.
318    *
319    * @param prefix the prefix.
320    * @return <code>true</code> if the character sequence represented by the
321    * argument is a prefix of the character sequence represented by
322    * this string; <code>false</code> otherwise.
323    * Note also that <code>true</code> will be returned if the
324    * argument is an empty string or is equal to this
325    * <code>String</code> object as determined by the
326    * {@link #equals(Object)} method.
327    * @exception java.lang.NullPointerException if <code>prefix</code> is
328    * <code>null</code>.
329    * @since JDK1. 0
330    */

331   public boolean startsWith(XMLString prefix)
332   {
333     return m_str.startsWith(prefix.toString());
334   }
335
336   /**
337    * Tests if this string ends with the specified suffix.
338    *
339    * @param suffix the suffix.
340    * @return <code>true</code> if the character sequence represented by the
341    * argument is a suffix of the character sequence represented by
342    * this object; <code>false</code> otherwise. Note that the
343    * result will be <code>true</code> if the argument is the
344    * empty string or is equal to this <code>String</code> object
345    * as determined by the {@link #equals(Object)} method.
346    * @exception java.lang.NullPointerException if <code>suffix</code> is
347    * <code>null</code>.
348    */

349   public boolean endsWith(String JavaDoc suffix)
350   {
351     return m_str.endsWith(suffix);
352   }
353
354   /**
355    * Returns a hashcode for this string. The hashcode for a
356    * <code>String</code> object is computed as
357    * <blockquote><pre>
358    * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
359    * </pre></blockquote>
360    * using <code>int</code> arithmetic, where <code>s[i]</code> is the
361    * <i>i</i>th character of the string, <code>n</code> is the length of
362    * the string, and <code>^</code> indicates exponentiation.
363    * (The hash value of the empty string is zero.)
364    *
365    * @return a hash code value for this object.
366    */

367   public int hashCode()
368   {
369     return m_str.hashCode();
370   }
371
372   /**
373    * Returns the index within this string of the first occurrence of the
374    * specified character. If a character with value <code>ch</code> occurs
375    * in the character sequence represented by this <code>String</code>
376    * object, then the index of the first such occurrence is returned --
377    * that is, the smallest value <i>k</i> such that:
378    * <blockquote><pre>
379    * this.charAt(<i>k</i>) == ch
380    * </pre></blockquote>
381    * is <code>true</code>. If no such character occurs in this string,
382    * then <code>-1</code> is returned.
383    *
384    * @param ch a character.
385    * @return the index of the first occurrence of the character in the
386    * character sequence represented by this object, or
387    * <code>-1</code> if the character does not occur.
388    */

389   public int indexOf(int ch)
390   {
391     return m_str.indexOf(ch);
392   }
393
394   /**
395    * Returns the index within this string of the first occurrence of the
396    * specified character, starting the search at the specified index.
397    * <p>
398    * If a character with value <code>ch</code> occurs in the character
399    * sequence represented by this <code>String</code> object at an index
400    * no smaller than <code>fromIndex</code>, then the index of the first
401    * such occurrence is returned--that is, the smallest value <i>k</i>
402    * such that:
403    * <blockquote><pre>
404    * (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
405    * </pre></blockquote>
406    * is true. If no such character occurs in this string at or after
407    * position <code>fromIndex</code>, then <code>-1</code> is returned.
408    * <p>
409    * There is no restriction on the value of <code>fromIndex</code>. If it
410    * is negative, it has the same effect as if it were zero: this entire
411    * string may be searched. If it is greater than the length of this
412    * string, it has the same effect as if it were equal to the length of
413    * this string: <code>-1</code> is returned.
414    *
415    * @param ch a character.
416    * @param fromIndex the index to start the search from.
417    * @return the index of the first occurrence of the character in the
418    * character sequence represented by this object that is greater
419    * than or equal to <code>fromIndex</code>, or <code>-1</code>
420    * if the character does not occur.
421    */

422   public int indexOf(int ch, int fromIndex)
423   {
424     return m_str.indexOf(ch, fromIndex);
425   }
426
427   /**
428    * Returns the index within this string of the last occurrence of the
429    * specified character. That is, the index returned is the largest
430    * value <i>k</i> such that:
431    * <blockquote><pre>
432    * this.charAt(<i>k</i>) == ch
433    * </pre></blockquote>
434    * is true.
435    * The String is searched backwards starting at the last character.
436    *
437    * @param ch a character.
438    * @return the index of the last occurrence of the character in the
439    * character sequence represented by this object, or
440    * <code>-1</code> if the character does not occur.
441    */

442   public int lastIndexOf(int ch)
443   {
444     return m_str.lastIndexOf(ch);
445   }
446
447   /**
448    * Returns the index within this string of the last occurrence of the
449    * specified character, searching backward starting at the specified
450    * index. That is, the index returned is the largest value <i>k</i>
451    * such that:
452    * <blockquote><pre>
453    * this.charAt(k) == ch) && (k <= fromIndex)
454    * </pre></blockquote>
455    * is true.
456    *
457    * @param ch a character.
458    * @param fromIndex the index to start the search from. There is no
459    * restriction on the value of <code>fromIndex</code>. If it is
460    * greater than or equal to the length of this string, it has
461    * the same effect as if it were equal to one less than the
462    * length of this string: this entire string may be searched.
463    * If it is negative, it has the same effect as if it were -1:
464    * -1 is returned.
465    * @return the index of the last occurrence of the character in the
466    * character sequence represented by this object that is less
467    * than or equal to <code>fromIndex</code>, or <code>-1</code>
468    * if the character does not occur before that point.
469    */

470   public int lastIndexOf(int ch, int fromIndex)
471   {
472     return m_str.lastIndexOf(ch, fromIndex);
473   }
474
475   /**
476    * Returns the index within this string of the first occurrence of the
477    * specified substring. The integer returned is the smallest value
478    * <i>k</i> such that:
479    * <blockquote><pre>
480    * this.startsWith(str, <i>k</i>)
481    * </pre></blockquote>
482    * is <code>true</code>.
483    *
484    * @param str any string.
485    * @return if the string argument occurs as a substring within this
486    * object, then the index of the first character of the first
487    * such substring is returned; if it does not occur as a
488    * substring, <code>-1</code> is returned.
489    * @exception java.lang.NullPointerException if <code>str</code> is
490    * <code>null</code>.
491    */

492   public int indexOf(String JavaDoc str)
493   {
494     return m_str.indexOf(str);
495   }
496
497   /**
498    * Returns the index within this string of the first occurrence of the
499    * specified substring. The integer returned is the smallest value
500    * <i>k</i> such that:
501    * <blockquote><pre>
502    * this.startsWith(str, <i>k</i>)
503    * </pre></blockquote>
504    * is <code>true</code>.
505    *
506    * @param str any string.
507    * @return if the string argument occurs as a substring within this
508    * object, then the index of the first character of the first
509    * such substring is returned; if it does not occur as a
510    * substring, <code>-1</code> is returned.
511    * @exception java.lang.NullPointerException if <code>str</code> is
512    * <code>null</code>.
513    */

514   public int indexOf(XMLString str)
515   {
516     return m_str.indexOf(str.toString());
517   }
518
519   /**
520    * Returns the index within this string of the first occurrence of the
521    * specified substring, starting at the specified index. The integer
522    * returned is the smallest value <i>k</i> such that:
523    * <blockquote><pre>
524    * this.startsWith(str, <i>k</i>) && (<i>k</i> >= fromIndex)
525    * </pre></blockquote>
526    * is <code>true</code>.
527    * <p>
528    * There is no restriction on the value of <code>fromIndex</code>. If
529    * it is negative, it has the same effect as if it were zero: this entire
530    * string may be searched. If it is greater than the length of this
531    * string, it has the same effect as if it were equal to the length of
532    * this string: <code>-1</code> is returned.
533    *
534    * @param str the substring to search for.
535    * @param fromIndex the index to start the search from.
536    * @return If the string argument occurs as a substring within this
537    * object at a starting index no smaller than
538    * <code>fromIndex</code>, then the index of the first character
539    * of the first such substring is returned. If it does not occur
540    * as a substring starting at <code>fromIndex</code> or beyond,
541    * <code>-1</code> is returned.
542    * @exception java.lang.NullPointerException if <code>str</code> is
543    * <code>null</code>
544    */

545   public int indexOf(String JavaDoc str, int fromIndex)
546   {
547     return m_str.indexOf(str, fromIndex);
548   }
549
550   /**
551    * Returns the index within this string of the rightmost occurrence
552    * of the specified substring. The rightmost empty string "" is
553    * considered to occur at the index value <code>this.length()</code>.
554    * The returned index is the largest value <i>k</i> such that
555    * <blockquote><pre>
556    * this.startsWith(str, k)
557    * </pre></blockquote>
558    * is true.
559    *
560    * @param str the substring to search for.
561    * @return if the string argument occurs one or more times as a substring
562    * within this object, then the index of the first character of
563    * the last such substring is returned. If it does not occur as
564    * a substring, <code>-1</code> is returned.
565    * @exception java.lang.NullPointerException if <code>str</code> is
566    * <code>null</code>.
567    */

568   public int lastIndexOf(String JavaDoc str)
569   {
570     return m_str.lastIndexOf(str);
571   }
572
573   /**
574    * Returns the index within this string of the last occurrence of
575    * the specified substring.
576    *
577    * @param str the substring to search for.
578    * @param fromIndex the index to start the search from. There is no
579    * restriction on the value of fromIndex. If it is greater than
580    * the length of this string, it has the same effect as if it
581    * were equal to the length of this string: this entire string
582    * may be searched. If it is negative, it has the same effect
583    * as if it were -1: -1 is returned.
584    * @return If the string argument occurs one or more times as a substring
585    * within this object at a starting index no greater than
586    * <code>fromIndex</code>, then the index of the first character of
587    * the last such substring is returned. If it does not occur as a
588    * substring starting at <code>fromIndex</code> or earlier,
589    * <code>-1</code> is returned.
590    * @exception java.lang.NullPointerException if <code>str</code> is
591    * <code>null</code>.
592    */

593   public int lastIndexOf(String JavaDoc str, int fromIndex)
594   {
595     return m_str.lastIndexOf(str, fromIndex);
596   }
597
598   /**
599    * Returns a new string that is a substring of this string. The
600    * substring begins with the character at the specified index and
601    * extends to the end of this string. <p>
602    * Examples:
603    * <blockquote><pre>
604    * "unhappy".substring(2) returns "happy"
605    * "Harbison".substring(3) returns "bison"
606    * "emptiness".substring(9) returns "" (an empty string)
607    * </pre></blockquote>
608    *
609    * @param beginIndex the beginning index, inclusive.
610    * @return the specified substring.
611    * @exception IndexOutOfBoundsException if
612    * <code>beginIndex</code> is negative or larger than the
613    * length of this <code>String</code> object.
614    */

615   public XMLString substring(int beginIndex)
616   {
617     return new XMLStringDefault(m_str.substring(beginIndex));
618   }
619
620   /**
621    * Returns a new string that is a substring of this string. The
622    * substring begins at the specified <code>beginIndex</code> and
623    * extends to the character at index <code>endIndex - 1</code>.
624    * Thus the length of the substring is <code>endIndex-beginIndex</code>.
625    *
626    * @param beginIndex the beginning index, inclusive.
627    * @param endIndex the ending index, exclusive.
628    * @return the specified substring.
629    * @exception IndexOutOfBoundsException if the
630    * <code>beginIndex</code> is negative, or
631    * <code>endIndex</code> is larger than the length of
632    * this <code>String</code> object, or
633    * <code>beginIndex</code> is larger than
634    * <code>endIndex</code>.
635    */

636   public XMLString substring(int beginIndex, int endIndex)
637   {
638     return new XMLStringDefault(m_str.substring(beginIndex, endIndex));
639   }
640
641   /**
642    * Concatenates the specified string to the end of this string.
643    *
644    * @param str the <code>String</code> that is concatenated to the end
645    * of this <code>String</code>.
646    * @return a string that represents the concatenation of this object's
647    * characters followed by the string argument's characters.
648    * @exception java.lang.NullPointerException if <code>str</code> is
649    * <code>null</code>.
650    */

651   public XMLString concat(String JavaDoc str)
652   {
653     return new XMLStringDefault(m_str.concat(str));
654   }
655
656   /**
657    * Converts all of the characters in this <code>String</code> to lower
658    * case using the rules of the given <code>Locale</code>.
659    *
660    * @param locale use the case transformation rules for this locale
661    * @return the String, converted to lowercase.
662    * @see java.lang.Character#toLowerCase(char)
663    * @see java.lang.String#toUpperCase(Locale)
664    */

665   public XMLString toLowerCase(Locale JavaDoc locale)
666   {
667     return new XMLStringDefault(m_str.toLowerCase(locale));
668   }
669
670   /**
671    * Converts all of the characters in this <code>String</code> to lower
672    * case using the rules of the default locale, which is returned
673    * by <code>Locale.getDefault</code>.
674    * <p>
675    *
676    * @return the string, converted to lowercase.
677    * @see java.lang.Character#toLowerCase(char)
678    * @see java.lang.String#toLowerCase(Locale)
679    */

680   public XMLString toLowerCase()
681   {
682     return new XMLStringDefault(m_str.toLowerCase());
683   }
684
685   /**
686    * Converts all of the characters in this <code>String</code> to upper
687    * case using the rules of the given locale.
688    * @param locale use the case transformation rules for this locale
689    * @return the String, converted to uppercase.
690    * @see java.lang.Character#toUpperCase(char)
691    * @see java.lang.String#toLowerCase(Locale)
692    */

693   public XMLString toUpperCase(Locale JavaDoc locale)
694   {
695     return new XMLStringDefault(m_str.toUpperCase(locale));
696   }
697
698   /**
699    * Converts all of the characters in this <code>String</code> to upper
700    * case using the rules of the default locale, which is returned
701    * by <code>Locale.getDefault</code>.
702    *
703    * <p>
704    * If no character in this string has a different uppercase version,
705    * based on calling the <code>toUpperCase</code> method defined by
706    * <code>Character</code>, then the original string is returned.
707    * <p>
708    * Otherwise, this method creates a new <code>String</code> object
709    * representing a character sequence identical in length to the
710    * character sequence represented by this <code>String</code> object and
711    * with every character equal to the result of applying the method
712    * <code>Character.toUpperCase</code> to the corresponding character of
713    * this <code>String</code> object. <p>
714    * Examples:
715    * <blockquote><pre>
716    * "Fahrvergnügen".toUpperCase() returns "FAHRVERGNÜGEN"
717    * "Visit Ljubinje!".toUpperCase() returns "VISIT LJUBINJE!"
718    * </pre></blockquote>
719    *
720    * @return the string, converted to uppercase.
721    * @see java.lang.Character#toUpperCase(char)
722    * @see java.lang.String#toUpperCase(Locale)
723    */

724   public XMLString toUpperCase()
725   {
726     return new XMLStringDefault(m_str.toUpperCase());
727   }
728
729   /**
730    * Removes white space from both ends of this string.
731    * <p>
732    * If this <code>String</code> object represents an empty character
733    * sequence, or the first and last characters of character sequence
734    * represented by this <code>String</code> object both have codes
735    * greater than <code>'&#92;u0020'</code> (the space character), then a
736    * reference to this <code>String</code> object is returned.
737    * <p>
738    * Otherwise, if there is no character with a code greater than
739    * <code>'&#92;u0020'</code> in the string, then a new
740    * <code>String</code> object representing an empty string is created
741    * and returned.
742    * <p>
743    * Otherwise, let <i>k</i> be the index of the first character in the
744    * string whose code is greater than <code>'&#92;u0020'</code>, and let
745    * <i>m</i> be the index of the last character in the string whose code
746    * is greater than <code>'&#92;u0020'</code>. A new <code>String</code>
747    * object is created, representing the substring of this string that
748    * begins with the character at index <i>k</i> and ends with the
749    * character at index <i>m</i>-that is, the result of
750    * <code>this.substring(<i>k</i>,&nbsp;<i>m</i>+1)</code>.
751    * <p>
752    * This method may be used to trim
753    * {@link Character#isSpace(char) whitespace} from the beginning and end
754    * of a string; in fact, it trims all ASCII control characters as well.
755    *
756    * @return this string, with white space removed from the front and end.
757    */

758   public XMLString trim()
759   {
760     return new XMLStringDefault(m_str.trim());
761   }
762
763   /**
764    * This object (which is already a string!) is itself returned.
765    *
766    * @return the string itself.
767    */

768   public String JavaDoc toString()
769   {
770     return m_str;
771   }
772   
773   /**
774    * Tell if this object contains a java String object.
775    *
776    * @return true if this XMLString can return a string without creating one.
777    */

778   public boolean hasString()
779   {
780     return true;
781   }
782   
783   /**
784    * Convert a string to a double -- Allowed input is in fixed
785    * notation ddd.fff.
786    *
787    * @return A double value representation of the string, or return Double.NaN
788    * if the string can not be converted.
789    */

790   public double toDouble()
791   {
792     try {
793       return Double.valueOf(m_str).doubleValue();
794     }
795     catch (NumberFormatException JavaDoc nfe)
796     {
797       return Double.NaN;
798     }
799   }
800 }
801
Popular Tags