Method which does all of the work of parsing the string. @param url the URL string to parse
(String url)
| 230 | * @param url the URL string to parse |
| 231 | */ |
| 232 | protected void parseString(String url) { |
| 233 | // initialize everything in case called from subclass |
| 234 | // (URLName really should be a final class) |
| 235 | protocol = file = ref = host = username = password = null; |
| 236 | port = -1; |
| 237 | |
| 238 | int len = url.length(); |
| 239 | |
| 240 | // find the protocol |
| 241 | // XXX - should check for only legal characters before the colon |
| 242 | // (legal: a-z, A-Z, 0-9, "+", ".", "-") |
| 243 | int protocolEnd = url.indexOf(':'); |
| 244 | if (protocolEnd != -1) |
| 245 | protocol = url.substring(0, protocolEnd); |
| 246 | |
| 247 | // is this an Internet standard URL that contains a host name? |
| 248 | if (url.regionMatches(protocolEnd + 1, "//", 0, 2)) { |
| 249 | // find where the file starts |
| 250 | String fullhost = null; |
| 251 | int fileStart = url.indexOf('/', protocolEnd + 3); |
| 252 | if (fileStart != -1) { |
| 253 | fullhost = url.substring(protocolEnd + 3, fileStart); |
| 254 | if (fileStart + 1 < len) |
| 255 | file = url.substring(fileStart + 1); |
| 256 | else |
| 257 | file = ""; |
| 258 | } else |
| 259 | fullhost = url.substring(protocolEnd + 3); |
| 260 | |
| 261 | // examine the fullhost, for username password etc. |
| 262 | int i = fullhost.indexOf('@'); |
| 263 | if (i != -1) { |
| 264 | String fulluserpass = fullhost.substring(0, i); |
| 265 | fullhost = fullhost.substring(i + 1); |
| 266 | |
| 267 | // get user and password |
| 268 | int passindex = fulluserpass.indexOf(':'); |
| 269 | if (passindex != -1) { |
| 270 | username = fulluserpass.substring(0, passindex); |
| 271 | password = fulluserpass.substring(passindex + 1); |
| 272 | } else { |
| 273 | username = fulluserpass; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | // get the port (if there) |
| 278 | int portindex; |
| 279 | if (fullhost.length() > 0 && fullhost.charAt(0) == '[') { |
| 280 | // an IPv6 address? |
| 281 | portindex = fullhost.indexOf(':', fullhost.indexOf(']')); |
| 282 | } else { |
| 283 | portindex = fullhost.indexOf(':'); |
| 284 | } |
| 285 | if (portindex != -1) { |
| 286 | String portstring = fullhost.substring(portindex + 1); |
| 287 | if (portstring.length() > 0) { |
| 288 | try { |
| 289 | port = Integer.parseInt(portstring); |