JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / swingjs / j2s / java / util / Properties.js
1 Clazz.declarePackage ("java.util");\r
2 Clazz.load (["java.util.Hashtable"], "java.util.Properties", ["java.lang.IllegalArgumentException"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.defaults = null;\r
5 if (!Clazz.isClassDefined ("java.util.Properties.LineReader")) {\r
6 java.util.Properties.$Properties$LineReader$ ();\r
7 }\r
8 Clazz.instantialize (this, arguments);\r
9 }, java.util, "Properties", java.util.Hashtable);\r
10 Clazz.makeConstructor (c$, \r
11 function () {\r
12 this.construct (null);\r
13 });\r
14 Clazz.makeConstructor (c$, \r
15 function (defaults) {\r
16 Clazz.superConstructor (this, java.util.Properties, []);\r
17 this.defaults = defaults;\r
18 }, "java.util.Properties");\r
19 Clazz.defineMethod (c$, "setProperty", \r
20 function (key, value) {\r
21 return this.put (key, value);\r
22 }, "~S,~S");\r
23 Clazz.defineMethod (c$, "load", \r
24 function (reader) {\r
25 this.load0 (Clazz.innerTypeInstance (java.util.Properties.LineReader, this, null, reader));\r
26 }, "java.io.Reader");\r
27 Clazz.defineMethod (c$, "load", \r
28 function (inStream) {\r
29 this.load0 (Clazz.innerTypeInstance (java.util.Properties.LineReader, this, null, inStream));\r
30 }, "java.io.InputStream");\r
31 Clazz.defineMethod (c$, "load0", \r
32  function (lr) {\r
33 var convtBuf =  Clazz.newCharArray (1024, '\0');\r
34 var limit;\r
35 var keyLen;\r
36 var valueStart;\r
37 var c;\r
38 var hasSep;\r
39 var precedingBackslash;\r
40 while ((limit = lr.readLine ()) >= 0) {\r
41 c = String.fromCharCode ( 0);\r
42 keyLen = 0;\r
43 valueStart = limit;\r
44 hasSep = false;\r
45 precedingBackslash = false;\r
46 while (keyLen < limit) {\r
47 c = lr.lineBuf[keyLen];\r
48 if ((c == '=' || c == ':') && !precedingBackslash) {\r
49 valueStart = keyLen + 1;\r
50 hasSep = true;\r
51 break;\r
52 } else if ((c == ' ' || c == '\t' || c == '\f') && !precedingBackslash) {\r
53 valueStart = keyLen + 1;\r
54 break;\r
55 }if (c == '\\') {\r
56 precedingBackslash = !precedingBackslash;\r
57 } else {\r
58 precedingBackslash = false;\r
59 }keyLen++;\r
60 }\r
61 while (valueStart < limit) {\r
62 c = lr.lineBuf[valueStart];\r
63 if (c != ' ' && c != '\t' && c != '\f') {\r
64 if (!hasSep && (c == '=' || c == ':')) {\r
65 hasSep = true;\r
66 } else {\r
67 break;\r
68 }}valueStart++;\r
69 }\r
70 var key = this.loadConvert (lr.lineBuf, 0, keyLen, convtBuf);\r
71 var value = this.loadConvert (lr.lineBuf, valueStart, limit - valueStart, convtBuf);\r
72 this.put (key, value);\r
73 }\r
74 }, "java.util.Properties.LineReader");\r
75 Clazz.defineMethod (c$, "loadConvert", \r
76  function ($in, off, len, convtBuf) {\r
77 if (convtBuf.length < len) {\r
78 var newLen = len * 2;\r
79 if (newLen < 0) {\r
80 newLen = 2147483647;\r
81 }convtBuf =  Clazz.newCharArray (newLen, '\0');\r
82 }var aChar;\r
83 var out = convtBuf;\r
84 var outLen = 0;\r
85 var end = off + len;\r
86 while (off < end) {\r
87 aChar = $in[off++];\r
88 if (aChar == '\\') {\r
89 aChar = $in[off++];\r
90 if (aChar == 'u') {\r
91 var value = 0;\r
92 for (var i = 0; i < 4; i++) {\r
93 aChar = $in[off++];\r
94 switch (aChar) {\r
95 case '0':\r
96 case '1':\r
97 case '2':\r
98 case '3':\r
99 case '4':\r
100 case '5':\r
101 case '6':\r
102 case '7':\r
103 case '8':\r
104 case '9':\r
105 value = (value << 4) + aChar.charCodeAt (0) - 48;\r
106 break;\r
107 case 'a':\r
108 case 'b':\r
109 case 'c':\r
110 case 'd':\r
111 case 'e':\r
112 case 'f':\r
113 value = (value << 4) + 10 + aChar.charCodeAt (0) - 97;\r
114 break;\r
115 case 'A':\r
116 case 'B':\r
117 case 'C':\r
118 case 'D':\r
119 case 'E':\r
120 case 'F':\r
121 value = (value << 4) + 10 + aChar.charCodeAt (0) - 65;\r
122 break;\r
123 default:\r
124 throw  new IllegalArgumentException ("Malformed \\uxxxx encoding.");\r
125 }\r
126 }\r
127 out[outLen++] = String.fromCharCode (value);\r
128 } else {\r
129 if (aChar == 't') aChar = '\t';\r
130  else if (aChar == 'r') aChar = '\r';\r
131  else if (aChar == 'n') aChar = '\n';\r
132  else if (aChar == 'f') aChar = '\f';\r
133 out[outLen++] = aChar;\r
134 }} else {\r
135 out[outLen++] = aChar;\r
136 }}\r
137 return  String.instantialize (out, 0, outLen);\r
138 }, "~A,~N,~N,~A");\r
139 Clazz.defineMethod (c$, "getProperty", \r
140 function (key) {\r
141 var oval = Clazz.superCall (this, java.util.Properties, "get", [key]);\r
142 var sval = (Clazz.instanceOf (oval, String)) ? oval : null;\r
143 return ((sval == null) && (this.defaults != null)) ? this.defaults.getProperty (key) : sval;\r
144 }, "~S");\r
145 Clazz.defineMethod (c$, "getProperty", \r
146 function (key, defaultValue) {\r
147 var val = this.getProperty (key);\r
148 return (val == null) ? defaultValue : val;\r
149 }, "~S,~S");\r
150 Clazz.defineMethod (c$, "propertyNames", \r
151 function () {\r
152 var h =  new java.util.Hashtable ();\r
153 this.enumerate (h);\r
154 return h.keys ();\r
155 });\r
156 Clazz.defineMethod (c$, "stringPropertyNames", \r
157 function () {\r
158 var h =  new java.util.Hashtable ();\r
159 this.enumerateStringProperties (h);\r
160 return h.keySet ();\r
161 });\r
162 Clazz.defineMethod (c$, "enumerate", \r
163  function (h) {\r
164 if (this.defaults != null) {\r
165 this.defaults.enumerate (h);\r
166 }for (var e = this.keys (); e.hasMoreElements (); ) {\r
167 var key = e.nextElement ();\r
168 h.put (key, this.get (key));\r
169 }\r
170 }, "java.util.Hashtable");\r
171 Clazz.defineMethod (c$, "enumerateStringProperties", \r
172  function (h) {\r
173 if (this.defaults != null) {\r
174 this.defaults.enumerateStringProperties (h);\r
175 }for (var e = this.keys (); e.hasMoreElements (); ) {\r
176 var k = e.nextElement ();\r
177 var v = this.get (k);\r
178 if (Clazz.instanceOf (k, String) && Clazz.instanceOf (v, String)) {\r
179 h.put (k, v);\r
180 }}\r
181 }, "java.util.Hashtable");\r
182 c$.$Properties$LineReader$ = function () {\r
183 Clazz.pu$h(self.c$);\r
184 c$ = Clazz.decorateAsClass (function () {\r
185 Clazz.prepareCallback (this, arguments);\r
186 this.inByteBuf = null;\r
187 this.inCharBuf = null;\r
188 this.lineBuf = null;\r
189 this.inLimit = 0;\r
190 this.inOff = 0;\r
191 this.inStream = null;\r
192 this.reader = null;\r
193 Clazz.instantialize (this, arguments);\r
194 }, java.util.Properties, "LineReader");\r
195 Clazz.prepareFields (c$, function () {\r
196 this.lineBuf =  Clazz.newCharArray (1024, '\0');\r
197 });\r
198 Clazz.makeConstructor (c$, \r
199 function (a) {\r
200 this.inStream = a;\r
201 this.inByteBuf =  Clazz.newByteArray (8192, 0);\r
202 }, "java.io.InputStream");\r
203 Clazz.makeConstructor (c$, \r
204 function (a) {\r
205 this.reader = a;\r
206 this.inCharBuf =  Clazz.newCharArray (8192, '\0');\r
207 }, "java.io.Reader");\r
208 Clazz.defineMethod (c$, "readLine", \r
209 function () {\r
210 var a = 0;\r
211 var b = String.fromCharCode (0);\r
212 var c = true;\r
213 var d = false;\r
214 var e = true;\r
215 var f = false;\r
216 var g = false;\r
217 var h = false;\r
218 while (true) {\r
219 if (this.inOff >= this.inLimit) {\r
220 this.inLimit = (this.inStream == null) ? this.reader.read (this.inCharBuf) : this.inStream.read (this.inByteBuf);\r
221 this.inOff = 0;\r
222 if (this.inLimit <= 0) {\r
223 if (a == 0 || d) {\r
224 return -1;\r
225 }return a;\r
226 }}if (this.inStream != null) {\r
227 b = String.fromCharCode (0xff & this.inByteBuf[this.inOff++]);\r
228 } else {\r
229 b = this.inCharBuf[this.inOff++];\r
230 }if (h) {\r
231 h = false;\r
232 if (b == '\n') {\r
233 continue;\r
234 }}if (c) {\r
235 if (b == ' ' || b == '\t' || b == '\f') {\r
236 continue;\r
237 }if (!f && (b == '\r' || b == '\n')) {\r
238 continue;\r
239 }c = false;\r
240 f = false;\r
241 }if (e) {\r
242 e = false;\r
243 if (b == '#' || b == '!') {\r
244 d = true;\r
245 continue;\r
246 }}if (b != '\n' && b != '\r') {\r
247 this.lineBuf[a++] = b;\r
248 if (a == this.lineBuf.length) {\r
249 var i = this.lineBuf.length * 2;\r
250 {\r
251 }var j =  Clazz.newCharArray (i, '\0');\r
252 System.arraycopy (this.lineBuf, 0, j, 0, this.lineBuf.length);\r
253 this.lineBuf = j;\r
254 }if (b == '\\') {\r
255 g = !g;\r
256 } else {\r
257 g = false;\r
258 }} else {\r
259 if (d || a == 0) {\r
260 d = false;\r
261 e = true;\r
262 c = true;\r
263 a = 0;\r
264 continue;\r
265 }if (this.inOff >= this.inLimit) {\r
266 this.inLimit = (this.inStream == null) ? this.reader.read (this.inCharBuf) : this.inStream.read (this.inByteBuf);\r
267 this.inOff = 0;\r
268 if (this.inLimit <= 0) {\r
269 return a;\r
270 }}if (g) {\r
271 a -= 1;\r
272 c = true;\r
273 f = true;\r
274 g = false;\r
275 if (b == '\r') {\r
276 h = true;\r
277 }} else {\r
278 return a;\r
279 }}}\r
280 });\r
281 c$ = Clazz.p0p ();\r
282 };\r
283 });\r