URLQueryParser.java
4.48 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.error.Scaffold
* com.scene7.is.util.text.Parser
* com.scene7.is.util.text.ParsingException
* com.scene7.is.util.text.Scanner
*/
package com.scene7.is.ps.provider.parsers;
import com.scene7.is.util.error.Scaffold;
import com.scene7.is.util.text.Parser;
import com.scene7.is.util.text.ParsingException;
import com.scene7.is.util.text.Scanner;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class URLQueryParser
implements Parser {
private final boolean[] nameChars;
private final boolean[] valueChars;
private static final String SAFE = "$-_.+";
private static final String EXTRA = "!*'(),";
private static final boolean[] PEDANTIC_NAME_CHARS = new boolean[256];
private static final boolean[] PEDANTIC_VALUE_CHARS = new boolean[256];
private static final boolean[] TOLERANT_NAME_CHARS = new boolean[256];
private static final boolean[] TOLERANT_VALUE_CHARS = new boolean[256];
private final boolean pedantic;
public static final Logger LOGGER = Logger.getLogger(URLQueryParser.class.getName());
public URLQueryParser(boolean pedantic) {
this.pedantic = pedantic;
if (pedantic) {
this.nameChars = PEDANTIC_NAME_CHARS;
this.valueChars = PEDANTIC_VALUE_CHARS;
} else {
this.nameChars = TOLERANT_NAME_CHARS;
this.valueChars = TOLERANT_VALUE_CHARS;
}
}
public Object parse(String query) throws ParsingException {
StringReader reader = new StringReader(query);
ValueHolder valueHolder = this.createResponseHolder();
Object error = null;
StringBuilder name = new StringBuilder(10);
StringBuilder value = new StringBuilder(100);
try {
while (Scanner.skipWhile((Reader)reader, (char)'&') != -1) {
name.setLength(0);
Scanner.collectWhile((Reader)reader, (StringBuilder)name, (boolean[])this.nameChars, (boolean)true);
Scanner.skipOne((Reader)reader, (char)'=');
value.setLength(0);
Scanner.collectWhile((Reader)reader, (StringBuilder)value, (boolean[])this.valueChars, (boolean)true);
try {
valueHolder.updateValue(name.toString(), value.toString());
}
catch (ParsingException e) {
if (this.pedantic) {
throw e;
}
LOGGER.warning("Invalid modifier: " + name);
LOGGER.log(Level.FINER, "Reason: ", (Throwable)e);
}
}
}
catch (ParsingException e) {
throw new ParsingException(4, query, (Throwable)e);
}
catch (IOException e) {
throw Scaffold.error((Throwable)e);
}
if (error == null) {
return valueHolder.getValue();
}
error.setResult(valueHolder.getValue());
throw error;
}
protected abstract ValueHolder createResponseHolder();
static {
Scanner.setChars((boolean[])PEDANTIC_NAME_CHARS, (char)'a', (char)'z', (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_NAME_CHARS, (char)'A', (char)'Z', (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_NAME_CHARS, (char)'0', (char)'9', (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_NAME_CHARS, (String)"_.$", (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_VALUE_CHARS, (char)'a', (char)'z', (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_VALUE_CHARS, (char)'A', (char)'Z', (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_VALUE_CHARS, (char)'0', (char)'9', (boolean)true);
Scanner.setChars((boolean[])PEDANTIC_VALUE_CHARS, (String)"$-_.+!*'(),%;:@=", (boolean)true);
Scanner.setChars((boolean[])TOLERANT_NAME_CHARS, (char)'\u0000', (char)'\u00ff', (boolean)true);
Scanner.setChars((boolean[])TOLERANT_NAME_CHARS, (String)"=&", (boolean)false);
Scanner.setChars((boolean[])TOLERANT_VALUE_CHARS, (char)'\u0000', (char)'%', (boolean)true);
Scanner.setChars((boolean[])TOLERANT_VALUE_CHARS, (char)'\'', (char)'\u00ff', (boolean)true);
}
protected static interface ValueHolder {
public void updateValue(String var1, String var2) throws ParsingException;
public Object getValue();
}
}