URIUtils.java
10.3 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.codec.net.URLCodec
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.forms.common.utils;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.BitSet;
import org.apache.commons.codec.net.URLCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class URIUtils {
private static final Logger logger;
private static final String DEFAULT_PROTOCOL_CHARSET = "UTF-8";
protected static final BitSet percent;
protected static final BitSet digit;
protected static final BitSet alpha;
protected static final BitSet alphanum;
protected static final BitSet hex;
protected static final BitSet escaped;
protected static final BitSet mark;
protected static final BitSet unreserved;
protected static final BitSet reserved;
protected static final BitSet uric;
protected static final BitSet fragment;
protected static final BitSet query;
protected static final BitSet pchar;
protected static final BitSet param;
protected static final BitSet segment;
protected static final BitSet path_segments;
protected static final BitSet abs_path;
protected static final BitSet uric_no_slash;
protected static final BitSet opaque_part;
protected static final BitSet path;
protected static final BitSet port;
protected static final BitSet IPv4address;
protected static final BitSet IPv6address;
protected static final BitSet IPv6reference;
protected static final BitSet toplabel;
protected static final BitSet domainlabel;
protected static final BitSet hostname;
protected static final BitSet host;
protected static final BitSet hostport;
protected static final BitSet userinfo;
private static final BitSet within_userinfo;
protected static final BitSet server;
protected static final BitSet reg_name;
protected static final BitSet authority;
protected static final BitSet scheme;
protected static final BitSet rel_segment;
protected static final BitSet rel_path;
protected static final BitSet net_path;
protected static final BitSet hier_part;
protected static final BitSet relativeURI;
protected static final BitSet absoluteURI;
protected static final BitSet URI_reference;
public static URI getUri(String path, boolean escaped) throws URISyntaxException {
if (escaped) {
return new URI(path);
}
return new URI(URIUtils.escapeURI(path));
}
private static String escapeURI(String path) throws URISyntaxException {
try {
BitSet bitSetallowed = URI_reference;
String charset = "";
return URIUtils.encode(path, bitSetallowed, "UTF-8");
}
catch (Exception e) {
logger.error("Unable to encode uri path:" + path, (Throwable)e);
throw new URISyntaxException(path, e.getMessage());
}
}
private static String encode(String unescaped, BitSet allowed, String charset) throws URISyntaxException {
byte[] rawdata = URLCodec.encodeUrl((BitSet)allowed, (byte[])URIUtils.getBytes(unescaped, charset));
return URIUtils.getAsciiString(rawdata);
}
public static String getAsciiString(byte[] data) {
return URIUtils.getAsciiString(data, 0, data.length);
}
private static byte[] getBytes(String data, String charset) {
if (data == null) {
throw new IllegalArgumentException("data may not be null");
}
if (charset == null || charset.length() == 0) {
throw new IllegalArgumentException("charset may not be null or empty");
}
try {
return data.getBytes(charset);
}
catch (UnsupportedEncodingException e) {
logger.warn("Unable to get ASCII string based on charset :" + charset, (Throwable)e);
return data.getBytes();
}
}
private static String getAsciiString(byte[] data, int offset, int length) {
if (data == null) {
throw new IllegalArgumentException("Parameter may not be null");
}
try {
return new String(data, offset, length, "US-ASCII");
}
catch (UnsupportedEncodingException e) {
logger.error("Unable to convert the byte array of ASCII characters to a string", (Throwable)e);
return null;
}
}
static {
int i;
logger = LoggerFactory.getLogger(URIUtils.class);
percent = new BitSet(256);
percent.set(37);
digit = new BitSet(256);
for (i = 48; i <= 57; ++i) {
digit.set(i);
}
alpha = new BitSet(256);
for (i = 97; i <= 122; ++i) {
alpha.set(i);
}
for (i = 65; i <= 90; ++i) {
alpha.set(i);
}
alphanum = new BitSet(256);
alphanum.or(alpha);
alphanum.or(digit);
hex = new BitSet(256);
hex.or(digit);
for (i = 97; i <= 102; ++i) {
hex.set(i);
}
for (i = 65; i <= 70; ++i) {
hex.set(i);
}
escaped = new BitSet(256);
escaped.or(percent);
escaped.or(hex);
mark = new BitSet(256);
mark.set(45);
mark.set(95);
mark.set(46);
mark.set(33);
mark.set(126);
mark.set(42);
mark.set(39);
mark.set(40);
mark.set(41);
unreserved = new BitSet(256);
unreserved.or(alphanum);
unreserved.or(mark);
reserved = new BitSet(256);
reserved.set(59);
reserved.set(47);
reserved.set(63);
reserved.set(58);
reserved.set(64);
reserved.set(38);
reserved.set(61);
reserved.set(43);
reserved.set(36);
reserved.set(44);
uric = new BitSet(256);
uric.or(reserved);
uric.or(unreserved);
uric.or(escaped);
fragment = uric;
query = uric;
pchar = new BitSet(256);
pchar.or(unreserved);
pchar.or(escaped);
pchar.set(58);
pchar.set(64);
pchar.set(38);
pchar.set(61);
pchar.set(43);
pchar.set(36);
pchar.set(44);
param = pchar;
segment = new BitSet(256);
segment.or(pchar);
segment.set(59);
segment.or(param);
path_segments = new BitSet(256);
path_segments.set(47);
path_segments.or(segment);
abs_path = new BitSet(256);
abs_path.set(47);
abs_path.or(path_segments);
uric_no_slash = new BitSet(256);
uric_no_slash.or(unreserved);
uric_no_slash.or(escaped);
uric_no_slash.set(59);
uric_no_slash.set(63);
uric_no_slash.set(59);
uric_no_slash.set(64);
uric_no_slash.set(38);
uric_no_slash.set(61);
uric_no_slash.set(43);
uric_no_slash.set(36);
uric_no_slash.set(44);
opaque_part = new BitSet(256);
opaque_part.or(uric_no_slash);
opaque_part.or(uric);
path = new BitSet(256);
path.or(abs_path);
path.or(opaque_part);
port = digit;
IPv4address = new BitSet(256);
IPv4address.or(digit);
IPv4address.set(46);
IPv6address = new BitSet(256);
IPv6address.or(hex);
IPv6address.set(58);
IPv6address.or(IPv4address);
IPv6reference = new BitSet(256);
IPv6reference.set(91);
IPv6reference.or(IPv6address);
IPv6reference.set(93);
toplabel = new BitSet(256);
toplabel.or(alphanum);
toplabel.set(45);
domainlabel = toplabel;
hostname = new BitSet(256);
hostname.or(toplabel);
hostname.set(46);
host = new BitSet(256);
host.or(hostname);
host.or(IPv6reference);
hostport = new BitSet(256);
hostport.or(host);
hostport.set(58);
hostport.or(port);
userinfo = new BitSet(256);
userinfo.or(unreserved);
userinfo.or(escaped);
userinfo.set(59);
userinfo.set(58);
userinfo.set(38);
userinfo.set(61);
userinfo.set(43);
userinfo.set(36);
userinfo.set(44);
within_userinfo = new BitSet(256);
within_userinfo.or(userinfo);
within_userinfo.clear(59);
within_userinfo.clear(58);
within_userinfo.clear(64);
within_userinfo.clear(63);
within_userinfo.clear(47);
server = new BitSet(256);
server.or(userinfo);
server.set(64);
server.or(hostport);
reg_name = new BitSet(256);
reg_name.or(unreserved);
reg_name.or(escaped);
reg_name.set(36);
reg_name.set(44);
reg_name.set(59);
reg_name.set(58);
reg_name.set(64);
reg_name.set(38);
reg_name.set(61);
reg_name.set(43);
authority = new BitSet(256);
authority.or(server);
authority.or(reg_name);
scheme = new BitSet(256);
scheme.or(alpha);
scheme.or(digit);
scheme.set(43);
scheme.set(45);
scheme.set(46);
rel_segment = new BitSet(256);
rel_segment.or(unreserved);
rel_segment.or(escaped);
rel_segment.set(59);
rel_segment.set(64);
rel_segment.set(38);
rel_segment.set(61);
rel_segment.set(43);
rel_segment.set(36);
rel_segment.set(44);
rel_path = new BitSet(256);
rel_path.or(rel_segment);
rel_path.or(abs_path);
net_path = new BitSet(256);
net_path.set(47);
net_path.or(authority);
net_path.or(abs_path);
hier_part = new BitSet(256);
hier_part.or(net_path);
hier_part.or(abs_path);
hier_part.or(query);
relativeURI = new BitSet(256);
relativeURI.or(net_path);
relativeURI.or(abs_path);
relativeURI.or(rel_path);
relativeURI.or(query);
absoluteURI = new BitSet(256);
absoluteURI.or(scheme);
absoluteURI.set(58);
absoluteURI.or(hier_part);
absoluteURI.or(opaque_part);
URI_reference = new BitSet(256);
URI_reference.or(absoluteURI);
URI_reference.or(relativeURI);
URI_reference.set(35);
URI_reference.or(fragment);
}
}