KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > jdbc > EscapeParser


1 package in.co.daffodil.db.jdbc;
2
3 public class EscapeParser {
4
5    static final char SPACE = (char) 32;
6
7    public static String JavaDoc parse(String JavaDoc str) {
8       String JavaDoc toRetutn = "";
9       int length = str.length();
10       int count = 0;
11       boolean ignore = false;
12       try {
13          for (int i = 0; i < length; i++) {
14             char ch = str.charAt(i);
15             if (ch == '{' && !ignore) {
16                count++;
17                String JavaDoc toSubstitute = "";
18                while (str.charAt(++i) == SPACE)
19                   ;
20                ch = str.charAt(i);
21                while (ch != SPACE && ch != '{' && ch != '}') {
22                   toSubstitute += ch;
23                   ch = str.charAt(++i);
24                }
25                toRetutn += getSubstitute(toSubstitute);
26                i--;
27             } else if (ch == '}' && !ignore) {
28                count--;
29             } else if (ch == '\'') {
30                ignore = !ignore;
31                toRetutn += ch;
32             } else
33                toRetutn += ch;
34          }
35       } catch (StringIndexOutOfBoundsException JavaDoc e) {}
36       finally {
37          if (count != 0){
38          ;//// Removed By Program ** System.out.println("P R O B L E M W I T H B R A C E S");
39
}
40       }
41       return toRetutn;
42    }
43
44    static String JavaDoc result = "";
45
46    static String JavaDoc parse1(String JavaDoc toParse) {
47       int openingBracePosition = toParse.indexOf("{");
48       int closingBracePosition = toParse.indexOf("}");
49
50       if (openingBracePosition == -1 && closingBracePosition == -1)
51          return result;
52
53       String JavaDoc toAdd = "";
54       int pointer = closingBracePosition;
55       int nextPointer = pointer + 1;
56       if (openingBracePosition != -1 && openingBracePosition < closingBracePosition) {
57          pointer = openingBracePosition;
58
59          while (toParse.charAt(++openingBracePosition) == ' ')
60             ;
61
62          nextPointer = toParse.indexOf(" ", openingBracePosition);
63
64          String JavaDoc toRemove = toParse.substring(openingBracePosition, nextPointer);
65          toAdd = getSubstitute(toRemove);
66       }
67
68       result += (toParse.substring(0, pointer) + toAdd);
69       return parse1(toParse.substring(nextPointer));
70    }
71
72    static String JavaDoc getSubstitute(String JavaDoc str) {
73       String JavaDoc toReturn = "";
74       if (str.equalsIgnoreCase("t"))
75          return "TIME";
76       if (str.equalsIgnoreCase("ts"))
77          return "TIMESTAMP";
78       if (str.equalsIgnoreCase("d"))
79          return "DATE";
80       if (str.equalsIgnoreCase("fn") || str.equalsIgnoreCase("oj"))
81          return "";
82       return str;
83    }
84    /* public EscapeParser(String toParse) {
85      parse(toParse);
86        }
87     static String result = "";
88     public static String parse(String toParse){
89      int openingBracePosition = toParse.indexOf("{");
90      int closingBracePosition = toParse.indexOf("}");
91      if(openingBracePosition == -1 && closingBracePosition == -1)
92       return result;
93      String toAdd = "";
94      int pointer = closingBracePosition;
95      int nextPointer = pointer + 1;
96      if(openingBracePosition != -1 && openingBracePosition < closingBracePosition){
97       pointer = openingBracePosition;
98       while(toParse.charAt(++openingBracePosition) == ' ');
99       nextPointer = toParse.indexOf(" ", openingBracePosition);
100       String toRemove = toParse.substring(openingBracePosition, nextPointer);
101       toAdd = getSubstitute(toRemove);
102      }
103      result += (toParse.substring(0, pointer) + toAdd);
104      return parse(toParse.substring(nextPointer));
105     }
106     private static String getSubstitute(String str){
107      String toReturn = "";
108      if(str.equals("t"))
109       return "time";
110      if(str.equals("d"))
111       return "date";
112      if(str.equals("ts"))
113       return "timestamp";
114      if(str.equals("fn"))
115       return "";
116      return str;
117     }*/

118
119 }
120
Popular Tags