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