home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
-
- public abstract class URLStreamHandler {
- protected abstract URLConnection openConnection(URL var1) throws IOException;
-
- protected void parseURL(URL u, String spec, int start, int limit) {
- String protocol = u.getProtocol();
- String host = u.getHost();
- int port = u.getPort();
- String file = u.getFile();
- String ref = u.getRef();
- if (start <= limit - 2 && spec.charAt(start) == '/' && spec.charAt(start + 1) == '/') {
- start += 2;
- int i = spec.indexOf(47, start);
- if (i < 0) {
- i = limit;
- }
-
- int prn = spec.indexOf(58, start);
- port = -1;
- if (prn < i && prn >= 0) {
- try {
- port = Integer.parseInt(spec.substring(prn + 1, i));
- } catch (Exception var12) {
- }
-
- if (prn > start) {
- host = spec.substring(start, prn);
- }
- } else {
- host = spec.substring(start, i);
- }
-
- start = i;
- file = null;
- } else if (host == null) {
- host = "";
- }
-
- if (start < limit) {
- if (spec.charAt(start) == '/') {
- file = spec.substring(start, limit);
- } else {
- file = (file != null ? file.substring(0, file.lastIndexOf(47)) : "") + "/" + spec.substring(start, limit);
- }
- }
-
- if (file == null || file.length() == 0) {
- file = "/";
- }
-
- int i;
- while((i = file.indexOf("/./")) >= 0) {
- file = file.substring(0, i) + file.substring(i + 2);
- }
-
- while((i = file.indexOf("/../")) >= 0) {
- if ((limit = file.lastIndexOf(47, i - 1)) >= 0) {
- file = file.substring(0, limit) + file.substring(i + 3);
- } else {
- file = file.substring(i + 3);
- }
- }
-
- if (file.endsWith("/.")) {
- file = file.substring(0, file.length() - 1);
- }
-
- if (file.endsWith("/..")) {
- if ((limit = file.lastIndexOf(47, file.length() - 4)) > 0) {
- file = file.substring(0, limit + 1);
- } else {
- file = "/";
- }
- }
-
- u.set(protocol, host, port, file, ref);
- }
-
- protected String toExternalForm(URL u) {
- String result = u.getProtocol() + ":";
- if (u.getHost() != null && u.getHost().length() > 0) {
- result = result + "//" + u.getHost();
- if (u.getPort() != -1) {
- result = result + ":" + u.getPort();
- }
- }
-
- result = result + u.getFile();
- if (u.getRef() != null) {
- result = result + "#" + u.getRef();
- }
-
- return result;
- }
-
- protected void setURL(URL u, String protocol, String host, int port, String file, String ref) {
- u.set(protocol, host, port, file, ref);
- }
- }
-