URLExpander.java
2.94 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.text.GlobPattern
* com.day.text.Text
*/
package com.day.util;
import com.day.text.GlobPattern;
import com.day.text.Text;
import com.day.util.HandleExpander;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
public class URLExpander
implements HandleExpander {
public String[] expand(String pattern) {
try {
URI uri = new URI(pattern);
if (uri.getScheme() == null || uri.getScheme().equals("file")) {
ArrayList list = new ArrayList();
String path = uri.getPath();
this.traverse_directory(list, new StringBuffer(path.length()), path.toCharArray(), 0);
return list.toArray(new String[list.size()]);
}
URL url = uri.toURL();
throw new UnsupportedOperationException("hmpf. still have to do this");
}
catch (URISyntaxException e) {
}
catch (IOException e) {
// empty catch block
}
return new String[0];
}
private void traverse_directory(ArrayList list, StringBuffer dir, char[] ptr, int p) {
int lastslash = p;
int first = p;
while (p < ptr.length && ptr[p] != '*' && ptr[p] != '?' && ptr[p] != '[' && ptr[p] != ']') {
if (ptr[p] == '/') {
lastslash = p;
}
++p;
}
if (p == ptr.length) {
dir.append('/');
dir.append(ptr, first, p - first);
String path = dir.toString();
if (new File(path).isFile()) {
list.add(path);
}
} else {
if (lastslash > first) {
dir.append('/');
dir.append(ptr, first, lastslash - first);
++lastslash;
}
while (p < ptr.length && ptr[p] != '/') {
++p;
}
GlobPattern glob = new GlobPattern(new String(ptr, lastslash, p - lastslash));
File directory = new File(dir.toString());
File[] files = directory.listFiles();
if (files == null) {
return;
}
for (int i = 0; i < files.length; ++i) {
String name = files[i].getName();
if (!glob.matches(name)) continue;
int len = dir.length();
dir.append('/');
dir.append(name);
if (files[i].isDirectory() && p < ptr.length) {
this.traverse_directory(list, dir, ptr, p + 1);
} else if (files[i].isFile() && p == ptr.length) {
String filename = dir.toString();
list.add(Text.fullPath((String)filename, (String)""));
}
dir.setLength(len);
}
}
}
}