1 Clazz.declarePackage ("java.net");
2 Clazz.load (["java.util.Hashtable"], "java.net.URL", ["java.io.IOException", "java.lang.Character", "$.Error", "java.net.MalformedURLException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
15 Clazz.instantialize (this, arguments);
16 }, java.net, "URL", null, java.io.Serializable);
17 Clazz.makeConstructor (c$,
18 function (context, spec, handler) {
20 switch (arguments.length) {
22 spec = context;context = handler = null;
28 if (context == null || Clazz.instanceOf(context, java.net.URL))
31 alert("java.net.URL constructor format not supported");
34 context && context.valueOf && context.valueOf() == null && (context = null);
40 var newProtocol = null;
42 var isRelative = false;
45 while ((limit > 0) && (spec.charAt (limit - 1) <= ' ')) {
48 while ((start < limit) && (spec.charAt (start) <= ' ')) {
51 if (spec.regionMatches (true, start, "url:", 0, 4)) {
53 }if (start < spec.length && spec.charAt (start) == '#') {
55 }for (i = start; !aRef && (i < limit) && ((c = spec.charCodeAt (i)) != 47); i++) {
57 var s = spec.substring (start, i).toLowerCase ();
58 if (this.isValidProtocol (s)) {
63 this.protocol = newProtocol;
64 if ((context != null) && ((newProtocol == null) || newProtocol.equalsIgnoreCase (context.protocol))) {
65 if (handler == null) {
66 handler = context.handler;
67 }if (context.path != null && context.path.startsWith ("/")) newProtocol = null;
68 if (newProtocol == null) {
69 this.protocol = context.protocol;
70 this.authority = context.authority;
71 this.userInfo = context.userInfo;
72 this.host = context.host;
73 this.port = context.port;
74 this.file = context.file;
75 this.path = context.path;
77 }}if (this.protocol == null) {
78 throw new java.net.MalformedURLException ("no protocol: " + original);
79 }if (handler == null && (handler = java.net.URL.getURLStreamHandler (this.protocol)) == null) {
80 throw new java.net.MalformedURLException ("unknown protocol: " + this.protocol);
81 }this.handler = handler;
82 i = spec.indexOf ('#', start);
84 this.ref = spec.substring (i + 1, limit);
86 }if (isRelative && start == limit) {
87 this.query = context.query;
88 if (this.ref == null) {
89 this.ref = context.ref;
90 }}handler.parseURL (this, spec, start, limit);
92 if (Clazz.exceptionOf (e$$, java.net.MalformedURLException)) {
97 } else if (Clazz.exceptionOf (e$$, Exception)) {
100 var exception = new java.net.MalformedURLException (e.getMessage ());
101 exception.initCause (e);
108 }, "java.net.URL,~S,java.net.URLStreamHandler");
109 Clazz.defineMethod (c$, "isValidProtocol",
110 function (protocol) {
111 var len = protocol.length;
112 if (len < 1) return false;
113 var c = protocol.charAt (0);
114 if (!Character.isLetter (c)) return false;
115 for (var i = 1; i < len; i++) {
116 c = protocol.charAt (i);
117 if (!Character.isLetterOrDigit (c) && c != '.' && c != '+' && c != '-') {
122 Clazz.defineMethod (c$, "set5",
123 function (protocol, host, port, file, ref) {
125 this.protocol = protocol;
127 this.authority = port == -1 ? host : host + ":" + port;
132 var q = file.lastIndexOf ('?');
134 this.query = file.substring (q + 1);
135 this.path = file.substring (0, q);
136 } else this.path = file;
137 }}, "~S,~S,~N,~S,~S");
138 Clazz.defineMethod (c$, "set",
139 function (protocol, host, port, authority, userInfo, path, query, ref) {
141 this.protocol = protocol;
144 this.file = query == null ? path : path + "?" + query;
145 this.userInfo = userInfo;
150 this.authority = authority;
151 }}, "~S,~S,~N,~S,~S,~S,~S,~S");
152 Clazz.defineMethod (c$, "getQuery",
156 Clazz.defineMethod (c$, "getPath",
160 Clazz.defineMethod (c$, "getUserInfo",
162 return this.userInfo;
164 Clazz.defineMethod (c$, "getAuthority",
166 return this.authority;
168 Clazz.defineMethod (c$, "getPort",
172 Clazz.defineMethod (c$, "getDefaultPort",
174 return this.handler.getDefaultPort ();
176 Clazz.defineMethod (c$, "getProtocol",
178 return this.protocol;
180 Clazz.defineMethod (c$, "getHost",
184 Clazz.defineMethod (c$, "getFile",
188 Clazz.defineMethod (c$, "getRef",
192 Clazz.overrideMethod (c$, "equals",
194 if (!(Clazz.instanceOf (obj, java.net.URL))) return false;
196 return this.handler.equals2 (this, u2);
198 Clazz.overrideMethod (c$, "hashCode",
200 if (this.$hashCode != -1) return this.$hashCode;
201 this.$hashCode = this.handler.hashCode (this);
202 return this.$hashCode;
204 Clazz.defineMethod (c$, "sameFile",
206 return this.handler.sameFile (this, other);
208 Clazz.overrideMethod (c$, "toString",
210 return this.toExternalForm ();
212 Clazz.defineMethod (c$, "toExternalForm",
214 return this.handler.toExternalForm (this);
216 Clazz.defineMethod (c$, "openConnection",
218 return this.handler.openConnection (this);
220 Clazz.defineMethod (c$, "openStream",
222 return this.openConnection ().getInputStream ();
224 Clazz.defineMethod (c$, "getContent",
226 return this.openConnection ().getInputStream ();
228 c$.setURLStreamHandlerFactory = Clazz.defineMethod (c$, "setURLStreamHandlerFactory",
231 if (java.net.URL.factory != null) {
232 throw new Error ("factory already defined");
233 }var security = System.getSecurityManager ();
234 if (security != null) {
235 security.checkSetFactory ();
236 }java.net.URL.handlers.clear ();
237 java.net.URL.factory = fac;
238 }}, "java.net.URLStreamHandlerFactory");
239 c$.getURLStreamHandler = Clazz.defineMethod (c$, "getURLStreamHandler",
240 function (protocol) {
241 var handler = java.net.URL.handlers.get (protocol);
242 if (handler == null) {
243 if (java.net.URL.factory != null) {
244 handler = java.net.URL.factory.createURLStreamHandler (protocol);
247 Clazz.defineStatics (c$,
249 c$.handlers = c$.prototype.handlers = new java.util.Hashtable ();
250 c$.streamHandlerLock = c$.prototype.streamHandlerLock = new Clazz._O ();