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