FontPath.java
2.72 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
*/
package com.day.image.internal;
import com.day.image.internal.GlobPattern;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class FontPath {
private final GlobPattern[] patterns;
private final ResourceResolver resolver;
private String[] currentPath;
public FontPath(ResourceResolver resolver, String[] patternStrings) {
this.resolver = resolver;
this.patterns = new GlobPattern[patternStrings.length];
for (int i = 0; i < patternStrings.length; ++i) {
this.patterns[i] = new GlobPattern(patternStrings[i], true);
}
this.currentPath = null;
}
public String[] getCurrentPath() {
if (this.currentPath == null) {
this.currentPath = this.scanPath();
}
return this.currentPath;
}
public boolean matches(String path) {
for (GlobPattern pattern : this.patterns) {
if (!pattern.matches(path)) continue;
return true;
}
return false;
}
private String[] scanPath() {
ArrayList<String> list = new ArrayList<String>();
for (GlobPattern pattern : this.patterns) {
Resource start = this.getStartResource(pattern);
if (start == null) continue;
this.recurse(list, pattern, start);
}
return list.toArray(new String[list.size()]);
}
private void recurse(List<String> list, GlobPattern pattern, Resource start) {
if (pattern.matches(start.getPath())) {
list.add(start.getPath());
} else {
Iterator children = ResourceUtil.listChildren((Resource)start);
while (children.hasNext()) {
this.recurse(list, pattern, (Resource)children.next());
}
}
}
private Resource getStartResource(GlobPattern pattern) {
String wcp = "*?[]";
String ps = pattern.toString();
int slash = -1;
for (int i = 0; i < ps.length(); ++i) {
char c = ps.charAt(i);
if (c == '/') {
slash = i;
continue;
}
if (wcp.indexOf(c) >= 0) break;
}
ps = slash >= 0 ? ps.substring(0, slash) : "/";
return this.resolver.getResource(ps);
}
}