1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.metricshub.wbem.sblim.cimclient.internal.uri;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 import java.util.regex.Pattern;
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 public class Authority {
81 private static final String PCTENCODED = "%[0-9A-Fa-f]{2}";
82
83 private static final String UNRESERVED = "A-Za-z0-9\\-\\._~";
84
85 private static final String SUBDELIMS = "!\\$&'\\(\\)\\*\\+,;=";
86
87 private static final String REGNAMEREG = "([" + UNRESERVED + SUBDELIMS + "]|" + PCTENCODED + ")+";
88
89 private static final String ZONEINDEX = "(%[" + UNRESERVED + "]+)?";
90
91 private static final String IPV4 = "([0-9]{1,3}\\.){3}[0-9]{1,3}";
92
93 private static final String H16 = "[0-9A-Fa-f]{1,4}";
94
95 private static final String LS32 = "((" + H16 + ":" + H16 + ")" + "|(" + IPV4 + "))";
96
97 private static final String IPV6 =
98
99 "(((" +
100 H16 +
101 ":){6}" +
102 LS32 +
103 ")|" +
104
105 "(::(" +
106 H16 +
107 ":){5}" +
108 LS32 +
109 ")|" +
110
111 "((" +
112 H16 +
113 ")?::" +
114 "(" +
115 H16 +
116 ":){4}" +
117 LS32 +
118 ")|" +
119
120 "(((" +
121 H16 +
122 ":){0,1}" +
123 H16 +
124 ")?::(" +
125 H16 +
126 ":){3}" +
127 LS32 +
128 ")|" +
129
130 "(((" +
131 H16 +
132 ":){0,2}" +
133 H16 +
134 ")?::(" +
135 H16 +
136 ":){2}" +
137 LS32 +
138 ")|" +
139
140 "(((" +
141 H16 +
142 ":){0,3}" +
143 H16 +
144 ")?::" +
145 H16 +
146 ":" +
147 LS32 +
148 ")|" +
149
150 "(((" +
151 H16 +
152 ":){0,4}" +
153 H16 +
154 ")?::" +
155 LS32 +
156 ")|" +
157
158 "(((" +
159 H16 +
160 ":){0,5}" +
161 H16 +
162 ")?::" +
163 H16 +
164 ")|" +
165
166 "(((" +
167 H16 +
168 ":){0,6}" +
169 H16 +
170 ")?::))" +
171 ZONEINDEX;
172
173
174 private static final String IPVFUTURE = "v[0-9A-Fa-f]+\\.([" + UNRESERVED + SUBDELIMS + "]|:)+";
175
176 private static final String IPLITERAL = "\\[(" + IPV6 + "|" + IPVFUTURE + ")\\]";
177
178 private static Pattern USERINFOPAT = Pattern.compile(
179 "^((([" + UNRESERVED + SUBDELIMS + ":]|(" + PCTENCODED + "))*)@).*"
180 );
181
182 private static Pattern HOSTPAT = Pattern.compile("^((" + IPV4 + ")|(" + REGNAMEREG + ")|(" + IPLITERAL + ")).*");
183
184 private static Pattern PORTPAT = Pattern.compile("^([0-9]+).*");
185
186
187
188
189
190
191
192 public static Authority parse(URIString pUriStr) {
193
194 URIString uriStr = pUriStr.deepCopy();
195 String userInfo;
196 if (uriStr.matchAndCut(USERINFOPAT, 1)) {
197 userInfo = uriStr.group(2);
198 } else {
199 userInfo = null;
200 }
201 if (!uriStr.matchAndCut(HOSTPAT, 1)) {
202 return null;
203 }
204 String host = uriStr.group(1);
205 String port = null;
206 if (uriStr.cutStarting(':')) {
207 if (!uriStr.matchAndCut(PORTPAT, 1)) {
208
209
210 return null;
211 }
212 port = uriStr.group(1);
213 }
214 pUriStr.set(uriStr);
215 return new Authority(userInfo, host, port);
216 }
217
218 private String iUserInfo;
219
220 private String iHost;
221
222 private String iPort;
223
224 private Authority(String pUserInfo, String pHost, String pPort) {
225 this.iUserInfo = pUserInfo;
226 this.iHost = pHost;
227 this.iPort = pPort;
228 }
229
230
231
232
233
234
235 @Override
236 public String toString() {
237 return (
238 (this.iUserInfo == null ? "" : this.iUserInfo + "@") + this.iHost + (this.iPort == null ? "" : ":" + this.iPort)
239 );
240 }
241
242
243
244
245
246
247 public String getUserInfo() {
248 return this.iUserInfo;
249 }
250
251
252
253
254
255
256 public String getHost() {
257 return this.iHost;
258 }
259
260
261
262
263
264
265 public String getPort() {
266 return this.iPort;
267 }
268 }