Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / net / URLStreamHandler.js
1 Clazz.declarePackage ("java.net");
2 Clazz.load (null, "java.net.URLStreamHandler", ["java.lang.IllegalArgumentException", "$.SecurityException", "$.UnsupportedOperationException"], function () {
3 c$ = Clazz.declareType (java.net, "URLStreamHandler");
4 Clazz.defineMethod (c$, "openConnectionProxy", 
5 function (u, p) {
6 throw  new UnsupportedOperationException ("Method not implemented.");
7 }, "java.net.URL,java.net.Proxy");
8 Clazz.defineMethod (c$, "parseURL", 
9 function (u, spec, start, limit) {
10 var protocol = u.getProtocol ();
11 var authority = u.getAuthority ();
12 var userInfo = u.getUserInfo ();
13 var host = u.getHost ();
14 var port = u.getPort ();
15 var path = u.getPath ();
16 var query = u.getQuery ();
17 var ref = u.getRef ();
18 var isRelPath = false;
19 var queryOnly = false;
20 if (start < limit) {
21 var queryStart = spec.indexOf ('?');
22 queryOnly = queryStart == start;
23 if ((queryStart != -1) && (queryStart < limit)) {
24 query = spec.substring (queryStart + 1, limit);
25 if (limit > queryStart) limit = queryStart;
26 spec = spec.substring (0, queryStart);
27 }}var i = 0;
28 var isUNCName = (start <= limit - 4) && (spec.charAt (start) == '/') && (spec.charAt (start + 1) == '/') && (spec.charAt (start + 2) == '/') && (spec.charAt (start + 3) == '/');
29 if (!isUNCName && (start <= limit - 2) && (spec.charAt (start) == '/') && (spec.charAt (start + 1) == '/')) {
30 start += 2;
31 i = spec.indexOf ('/', start);
32 if (i < 0) {
33 i = spec.indexOf ('?', start);
34 if (i < 0) i = limit;
35 }host = authority = spec.substring (start, i);
36 var ind = authority.indexOf ('@');
37 if (ind != -1) {
38 userInfo = authority.substring (0, ind);
39 host = authority.substring (ind + 1);
40 } else {
41 userInfo = null;
42 }if (host != null) {
43 if (host.length > 0 && (host.charAt (0) == '[')) {
44 throw  new IllegalArgumentException ("Invalid host: " + host);
45 }ind = host.indexOf (':');
46 port = -1;
47 if (ind >= 0) {
48 if (host.length > (ind + 1)) {
49 port = Integer.parseInt (host.substring (ind + 1));
50 }host = host.substring (0, ind);
51 }} else {
52 host = "";
53 }if (port < -1) throw  new IllegalArgumentException ("Invalid port number :" + port);
54 start = i;
55 if (authority.length > 0) path = "";
56 }if (host == null) {
57 host = "";
58 }if (start < limit) {
59 if (spec.charAt (start) == '/') {
60 path = spec.substring (start, limit);
61 } else if (path != null && path.length > 0) {
62 isRelPath = true;
63 var ind = path.lastIndexOf ('/');
64 var seperator = "";
65 if (ind == -1 && authority != null) seperator = "/";
66 path = path.substring (0, ind + 1) + seperator + spec.substring (start, limit);
67 } else {
68 var seperator = (authority != null) ? "/" : "";
69 path = seperator + spec.substring (start, limit);
70 }} else if (queryOnly && path != null) {
71 var ind = path.lastIndexOf ('/');
72 if (ind < 0) ind = 0;
73 path = path.substring (0, ind) + "/";
74 }if (path == null) path = "";
75 if (isRelPath) {
76 while ((i = path.indexOf ("/./")) >= 0) {
77 path = path.substring (0, i) + path.substring (i + 2);
78 }
79 i = 0;
80 while ((i = path.indexOf ("/../", i)) >= 0) {
81 if (i > 0 && (limit = path.lastIndexOf ('/', i - 1)) >= 0 && (path.indexOf ("/../", limit) != 0)) {
82 path = path.substring (0, limit) + path.substring (i + 3);
83 i = 0;
84 } else {
85 i = i + 3;
86 }}
87 while (path.endsWith ("/..")) {
88 i = path.indexOf ("/..");
89 if ((limit = path.lastIndexOf ('/', i - 1)) >= 0) {
90 path = path.substring (0, limit + 1);
91 } else {
92 break;
93 }}
94 if (path.startsWith ("./") && path.length > 2) path = path.substring (2);
95 if (path.endsWith ("/.")) path = path.substring (0, path.length - 1);
96 }this.setURL (u, protocol, host, port, authority, userInfo, path, query, ref);
97 }, "java.net.URL,~S,~N,~N");
98 Clazz.defineMethod (c$, "getDefaultPort", 
99 function () {
100 return -1;
101 });
102 Clazz.defineMethod (c$, "equals2", 
103 function (u1, u2) {
104 var ref1 = u1.getRef ();
105 var ref2 = u2.getRef ();
106 return (ref1 === ref2 || (ref1 != null && ref1.equals (ref2))) && this.sameFile (u1, u2);
107 }, "java.net.URL,java.net.URL");
108 Clazz.defineMethod (c$, "hashCode", 
109 function (u) {
110 var h = 0;
111 var protocol = u.getProtocol ();
112 if (protocol != null) h += protocol.hashCode ();
113 h += u.toString ().hashCode ();
114 var file = u.getFile ();
115 if (file != null) h += file.hashCode ();
116 if (u.getPort () == -1) h += this.getDefaultPort ();
117  else h += u.getPort ();
118 var ref = u.getRef ();
119 if (ref != null) h += ref.hashCode ();
120 return h;
121 }, "java.net.URL");
122 Clazz.defineMethod (c$, "sameFile", 
123 function (u1, u2) {
124 if (!((u1.getProtocol () === u2.getProtocol ()) || (u1.getProtocol () != null && u1.getProtocol ().equalsIgnoreCase (u2.getProtocol ())))) return false;
125 if (!(u1.getFile () === u2.getFile () || (u1.getFile () != null && u1.getFile ().equals (u2.getFile ())))) return false;
126 var port1;
127 var port2;
128 port1 = (u1.getPort () != -1) ? u1.getPort () : u1.handler.getDefaultPort ();
129 port2 = (u2.getPort () != -1) ? u2.getPort () : u2.handler.getDefaultPort ();
130 if (port1 != port2) return false;
131 if (!this.hostsEqual (u1, u2)) return false;
132 return true;
133 }, "java.net.URL,java.net.URL");
134 Clazz.defineMethod (c$, "hostsEqual", 
135 function (u1, u2) {
136 if (u1.getHost () != null && u2.getHost () != null) return u1.getHost ().equalsIgnoreCase (u2.getHost ());
137 return u1.getHost () == null && u2.getHost () == null;
138 }, "java.net.URL,java.net.URL");
139 Clazz.defineMethod (c$, "toExternalForm", 
140 function (u) {
141 return "";
142 }, "java.net.URL");
143 Clazz.defineMethod (c$, "setURL", 
144 function (u, protocol, host, port, authority, userInfo, path, query, ref) {
145 if (this !== u.handler) {
146 throw  new SecurityException ("handler for url different from this handler");
147 }u.set (u.getProtocol (), host, port, authority, userInfo, path, query, ref);
148 }, "java.net.URL,~S,~S,~N,~S,~S,~S,~S,~S");
149 Clazz.defineMethod (c$, "setURLDeprecated", 
150 function (u, protocol, host, port, file, ref) {
151 var authority = null;
152 var userInfo = null;
153 if (host != null && host.length != 0) {
154 authority = (port == -1) ? host : host + ":" + port;
155 var at = host.lastIndexOf ('@');
156 if (at != -1) {
157 userInfo = host.substring (0, at);
158 host = host.substring (at + 1);
159 }}var path = null;
160 var query = null;
161 if (file != null) {
162 var q = file.lastIndexOf ('?');
163 if (q != -1) {
164 query = file.substring (q + 1);
165 path = file.substring (0, q);
166 } else path = file;
167 }this.setURL (u, protocol, host, port, authority, userInfo, path, query, ref);
168 }, "java.net.URL,~S,~S,~N,~S,~S");
169 });