URLHandler.java
8.03 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.ICUDebug;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public abstract class URLHandler {
private static final Map handlers;
private static final boolean DEBUG;
public static URLHandler get(URL url) {
block9 : {
Method m;
if (url == null) {
return null;
}
String protocol = url.getProtocol();
if (handlers != null && (m = (Method)handlers.get(protocol)) != null) {
try {
URLHandler handler = (URLHandler)m.invoke(null, url);
if (handler != null) {
return handler;
}
}
catch (IllegalAccessException e) {
if (DEBUG) {
System.err.println(e);
}
}
catch (IllegalArgumentException e) {
if (DEBUG) {
System.err.println(e);
}
}
catch (InvocationTargetException e) {
if (!DEBUG) break block9;
System.err.println(e);
}
}
}
return URLHandler.getDefault(url);
}
protected static URLHandler getDefault(URL url) {
String protocol = url.getProtocol();
if (protocol.equals("file")) {
return new FileURLHandler(url);
}
if (protocol.equals("jar")) {
return new JarURLHandler(url);
}
return null;
}
public void guide(URLVisitor visitor, boolean recurse) {
this.guide(visitor, recurse, true);
}
public abstract void guide(URLVisitor var1, boolean var2, boolean var3);
static {
HashMap<String, Method> h;
block14 : {
DEBUG = ICUDebug.enabled("URLHandler");
h = null;
try {
Class class_ = URLHandler.class;
InputStream is = class_.getResourceAsStream("urlhandler.props");
if (is == null) {
is = ClassLoader.getSystemClassLoader().getResourceAsStream("urlhandler.props");
}
if (is == null) break block14;
Class[] arrclass = new Class[1];
Class class_2 = URL.class;
arrclass[0] = class_2;
Class[] params = arrclass;
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
while (line != null) {
block15 : {
if ((line = line.trim()).length() != 0 && line.charAt(0) != '#') {
int ix = line.indexOf(61);
if (ix == -1) {
if (DEBUG) {
System.err.println("bad urlhandler line: '" + line + "'");
}
break;
}
String key = line.substring(0, ix).trim();
String value = line.substring(ix + 1).trim();
try {
Class<?> cl = Class.forName(value);
Method m = cl.getDeclaredMethod("get", params);
if (h == null) {
h = new HashMap<String, Method>();
}
h.put(key, m);
}
catch (ClassNotFoundException e) {
if (DEBUG) {
System.err.println(e);
}
}
catch (NoSuchMethodException e) {
if (DEBUG) {
System.err.println(e);
}
}
catch (SecurityException e) {
if (!DEBUG) break block15;
System.err.println(e);
}
}
}
line = br.readLine();
}
}
catch (Throwable t) {
if (!DEBUG) break block14;
System.err.println(t);
}
}
handlers = h;
}
public static interface URLVisitor {
public void visit(String var1);
}
private static class JarURLHandler
extends URLHandler {
JarFile jarFile;
String prefix;
JarURLHandler(URL url) {
try {
this.prefix = url.getPath();
int ix = this.prefix.indexOf("!/");
if (ix >= 0) {
this.prefix = this.prefix.substring(ix + 2);
}
JarURLConnection conn = (JarURLConnection)url.openConnection();
this.jarFile = conn.getJarFile();
}
catch (Exception e) {
if (DEBUG) {
System.err.println("icurb jar error: " + e);
}
throw new IllegalArgumentException("jar error: " + e.getMessage());
}
}
public void guide(URLVisitor v, boolean recurse, boolean strip) {
block5 : {
try {
Enumeration<JarEntry> entries = this.jarFile.entries();
while (entries.hasMoreElements()) {
String name;
JarEntry entry = entries.nextElement();
if (entry.isDirectory() || !(name = entry.getName()).startsWith(this.prefix)) continue;
int ix = (name = name.substring(this.prefix.length())).lastIndexOf(47);
if (ix != -1) {
if (!recurse) continue;
if (strip) {
name = name.substring(ix + 1);
}
}
v.visit(name);
}
}
catch (Exception e) {
if (!DEBUG) break block5;
System.err.println("icurb jar error: " + e);
}
}
}
}
private static class FileURLHandler
extends URLHandler {
File file;
String root;
FileURLHandler(URL url) {
this.root = url.getPath();
this.file = new File(this.root);
if (!this.file.exists()) {
if (DEBUG) {
System.err.println("file does not exist");
}
throw new IllegalArgumentException();
}
}
public void guide(URLVisitor v, boolean recurse, boolean strip) {
if (this.file.isDirectory()) {
this.process(v, recurse, strip, "/", this.file.listFiles());
} else {
v.visit(this.file.getName());
}
}
private void process(URLVisitor v, boolean recurse, boolean strip, String path, File[] files) {
for (int i = 0; i < files.length; ++i) {
File f = files[i];
if (f.isDirectory()) {
if (!recurse) continue;
this.process(v, recurse, strip, path + f.getName() + '/', f.listFiles());
continue;
}
v.visit(strip ? f.getName() : path + f.getName());
}
}
}
}