KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > publishing > markups > TKMarkupFloatParamClass


1 package com.teamkonzept.publishing.markups;
2
3 /**
4  * @author $Author: mischa $
5  * @version $Revision: 1.6 $
6  */

7 public class TKMarkupFloatParamClass extends TKMarkupParamClass {
8
9     /**
10      * checks if raw is a string representation of a float
11      * @return the trimmed string (if it is a float) or null
12      */

13     public String JavaDoc checkValue (String JavaDoc raw) {
14         if (raw == null){
15             return raw;
16         }
17             
18         String JavaDoc value = raw.trim();
19         int pos = 0;
20         // is true as long as there is no '.'
21
boolean isInt = true;
22
23         while (pos < value.length()) {
24             char chr = value.charAt (pos++);
25                     
26             if (chr == '.'){
27                 if (!isInt){
28                     return null;
29                 }
30                 else {
31                     isInt = false;
32                 }
33             }
34             else if (digitCodes.indexOf(chr) == -1){
35                 return null;
36             }
37         }
38         return value;
39     }
40
41     public int parseUnquotedValue (String JavaDoc text, int pos, StringBuffer JavaDoc value)
42         throws TKMarkupParserException {
43     
44         if (value != null) value.setLength (0);
45
46         boolean isInt = true;
47         boolean isFloat = true;
48
49         while (pos < text.length()) {
50         
51             char chr = text.charAt (pos);
52
53             if (chr == '.'){
54                 if (!isInt){
55                     isFloat = false;
56                 }
57                 else{
58                     isInt = false;
59                 }
60             }
61             else if (digitCodes.indexOf(chr) == -1){
62                 isInt = false;
63                 isFloat = false;
64             }
65             if (!isInt && !isFloat) break;
66             if (value != null) value.append (chr);
67
68             pos++;
69         }
70         return pos;
71     }
72
73     public String JavaDoc wrapValue (String JavaDoc value) {
74
75         return value;
76     }
77 }
78
79
Popular Tags