QueryTokenizer.java
2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.error.Scaffold
* com.scene7.is.util.text.ParameterException
* com.scene7.is.util.text.ParsingException
*/
package com.scene7.is.ps.provider.parsers;
import com.scene7.is.util.error.Scaffold;
import com.scene7.is.util.text.ParameterException;
import com.scene7.is.util.text.ParsingException;
import java.io.IOException;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.StringReader;
public class QueryTokenizer {
private StreamTokenizer tokenizer;
private String paramName;
private String paramValue;
public QueryTokenizer(String query) {
this.tokenizer = new StreamTokenizer(new StringReader(query));
this.tokenizer.resetSyntax();
this.tokenizer.resetSyntax();
this.tokenizer.wordChars(97, 122);
this.tokenizer.wordChars(65, 90);
this.tokenizer.wordChars(48, 57);
this.tokenizer.wordChars(37, 37);
this.tokenizer.wordChars(36, 36);
this.tokenizer.wordChars(45, 45);
this.tokenizer.wordChars(95, 95);
this.tokenizer.wordChars(46, 46);
this.tokenizer.wordChars(44, 44);
this.tokenizer.wordChars(47, 47);
this.nextToken();
if (this.tokenizer.ttype == 63) {
this.nextToken();
}
while (this.tokenizer.ttype == 38) {
this.nextToken();
}
}
public boolean hasMoreTokens() {
return this.tokenizer.ttype != -1;
}
public boolean nextTokenPair() throws ParsingException, ParameterException {
this.validateToken(-3);
this.paramName = this.tokenizer.sval;
this.nextToken();
this.validateToken(61);
this.nextToken();
this.validateToken(-3);
this.paramValue = this.tokenizer.sval;
while (this.nextToken() == 38) {
}
return this.hasMoreTokens();
}
public String getName() {
return this.paramName;
}
public String getValue() {
return this.paramValue;
}
private int nextToken() {
try {
return this.tokenizer.nextToken();
}
catch (IOException e) {
throw Scaffold.error((Throwable)e);
}
}
private void validateToken(int expected) throws ParsingException {
if (this.tokenizer.ttype != expected) {
if (this.tokenizer.ttype >= 32) {
throw new ParsingException(0, "'" + (char)this.tokenizer.ttype + "'", null);
}
throw new ParsingException(0, "0x" + Integer.toHexString(this.tokenizer.ttype), null);
}
}
}