Resolver.java
4.92 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.ut;
import com.adobe.xfa.protocol.Protocol;
import com.adobe.xfa.protocol.ProtocolUtils;
import com.adobe.xfa.ut.StringHolder;
import java.util.HashMap;
import java.util.Map;
public class Resolver {
private static final ThreadLocal<Map<String, Protocol>> moProtocolRegistry = new ThreadLocal<Map<String, Protocol>>(){
@Override
protected synchronized Map<String, Protocol> initialValue() {
return new HashMap<String, Protocol>();
}
};
public static final String gsServerIndicator = "://";
private Resolver() {
}
public static void setProtocol(Protocol oProtocol) {
if (oProtocol != null) {
String sScheme = oProtocol.scheme();
moProtocolRegistry.get().put(sScheme, oProtocol);
}
}
public static void resetProtocols() {
moProtocolRegistry.get().clear();
}
public static Protocol getProtocol(String sScheme) {
Protocol protocol;
if (sScheme.endsWith(":")) {
sScheme = sScheme.substring(0, sScheme.length() - 1);
}
if ((protocol = moProtocolRegistry.get().get(sScheme)) == null) {
protocol = moProtocolRegistry.get().get("");
}
return protocol;
}
public static void crackUrl(String sUrl, StringHolder sScheme, StringHolder sUser, StringHolder sPwd, StringHolder sHost, StringHolder sPort, StringHolder sPath) {
String sTmp = sUrl;
int nFoundAt = 0;
String sHostValue = null;
nFoundAt = sTmp.indexOf("://");
if (nFoundAt != -1) {
if (sScheme != null) {
sScheme.value = sTmp.substring(0, nFoundAt);
}
sHostValue = sTmp.substring(nFoundAt + 3);
if (sPath != null && (nFoundAt = sHostValue.indexOf(47)) != -1) {
sPath.value = sHostValue.substring(nFoundAt + 1);
sHostValue = sHostValue.substring(0, nFoundAt);
}
} else {
nFoundAt = sTmp.indexOf(58);
if (nFoundAt != -1) {
if (sScheme != null) {
sScheme.value = sTmp.substring(0, nFoundAt);
}
sHostValue = sTmp.substring(nFoundAt + 1);
}
}
if (sHostValue != null) {
nFoundAt = sHostValue.indexOf(64);
if (sUser != null && nFoundAt != -1) {
sUser.value = sHostValue.substring(0, nFoundAt);
sHostValue = sHostValue.substring(nFoundAt + 1);
if (sPwd != null && (nFoundAt = sUser.value.indexOf(58)) != -1) {
sPwd.value = sUser.value.substring(nFoundAt + 1);
sUser.value = sUser.value.substring(0, nFoundAt);
}
}
if (sPort != null) {
int nOffset = sHostValue.indexOf(93);
if (nOffset == -1) {
nOffset = 0;
}
if ((nFoundAt = sHostValue.indexOf(58, nOffset)) != -1) {
sPort.value = sHostValue.substring(nFoundAt + 1);
sHost.value = sHostValue.substring(0, nFoundAt);
}
}
}
if (sHost != null) {
sHost.value = sHostValue;
}
}
public static String canonUrl(String sScheme, String sHost, String sPort, String sPath) {
StringBuilder sUrl = new StringBuilder(sScheme);
if (sScheme.equals("file") || sScheme.equals("ftp") || sScheme.equals("ftps") || sScheme.equals("gopher") || sScheme.equals("http") || sScheme.equals("https") || sScheme.equals("ldap") || sScheme.equals("nntp") || sScheme.equals("telnet")) {
sUrl.append("://");
} else {
sUrl.append(':');
}
if (sHost != null) {
sUrl.append(sHost);
}
if (sPort != null && sPort.length() > 0) {
sUrl.append(':');
sUrl.append(sPort);
}
if (sPath != null && sPath.length() > 0) {
sUrl.append('/');
sUrl.append(sPath);
}
return sUrl.toString();
}
public static String urlEncode(String sUrl) {
String sEncodedPath;
StringHolder sScheme = new StringHolder();
StringHolder sUser = new StringHolder();
StringHolder sPwd = new StringHolder();
StringHolder sHost = new StringHolder();
StringHolder sPort = new StringHolder();
StringHolder sPath = new StringHolder();
Resolver.crackUrl(sUrl, sScheme, sUser, sPwd, sHost, sPort, sPath);
if (!ProtocolUtils.isUrlEncoded(sUrl) && sPath.value != null && !(sEncodedPath = ProtocolUtils.urlEncode(sPath.value)).equals(sPath.value)) {
return Resolver.canonUrl(sScheme.value, sHost.value, sPort.value, sEncodedPath);
}
return sUrl;
}
public static String urlDecode(String sUrl) {
return ProtocolUtils.urlDecode(sUrl);
}
}