1 Clazz.declarePackage ("javajs.util");
2 Clazz.load (["javajs.api.GenericCifDataParser", "java.util.Hashtable", "javajs.util.SB"], "javajs.util.CifDataParser", ["javajs.util.Lst", "$.PT"], function () {
3 c$ = Clazz.decorateAsClass (function () {
10 this.wasUnQuoted = false;
11 this.strPeeked = null;
15 this.fileHeader = null;
17 this.nullString = "\0";
19 Clazz.instantialize (this, arguments);
20 }, javajs.util, "CifDataParser", null, javajs.api.GenericCifDataParser);
21 Clazz.prepareFields (c$, function () {
22 this.fileHeader = new javajs.util.SB ();
24 Clazz.defineMethod (c$, "setNullValue",
25 function (nullString) {
26 this.nullString = nullString;
28 Clazz.makeConstructor (c$,
31 Clazz.overrideMethod (c$, "getLoopData",
33 return this.loopData[i];
35 Clazz.overrideMethod (c$, "getFieldCount",
37 return this.fieldCount;
39 Clazz.overrideMethod (c$, "getField",
41 return this.fields[i];
43 Clazz.overrideMethod (c$, "set",
44 function (reader, br) {
48 }, "javajs.api.GenericLineReader,java.io.BufferedReader");
49 Clazz.overrideMethod (c$, "getFileHeader",
51 return this.fileHeader.toString ();
53 Clazz.overrideMethod (c$, "getAllCifData",
58 var allData = new java.util.Hashtable ();
59 var models = new javajs.util.Lst ();
60 allData.put ("models", models);
62 while ((key = this.getNextToken ()) != null) {
63 if (key.startsWith ("global_") || key.startsWith ("data_")) {
64 models.addLast (data = new java.util.Hashtable ());
65 data.put ("name", key);
67 }if (key.startsWith ("loop_")) {
68 this.getAllCifLoopData (data);
70 }if (key.charAt (0) != '_') {
71 System.out.println ("CIF ERROR ? should be an underscore: " + key);
73 var value = this.getNextToken ();
75 System.out.println ("CIF ERROR ? end of file; data missing: " + key);
77 data.put (this.fixKey (key), value);
80 if (Clazz.exceptionOf (e, Exception)) {
86 if (this.br != null) this.br.close ();
88 if (Clazz.exceptionOf (e, Exception)) {
95 Clazz.defineMethod (c$, "getAllCifLoopData",
96 ($fz = function (data) {
98 var keyWords = new javajs.util.Lst ();
99 while ((key = this.peekToken ()) != null && key.charAt (0) == '_') {
100 key = this.fixKey (this.getTokenPeeked ());
101 keyWords.addLast (key);
102 data.put (key, new javajs.util.Lst ());
104 this.fieldCount = keyWords.size ();
105 if (this.fieldCount == 0) return;
106 this.loopData = new Array (this.fieldCount);
107 while (this.getData ()) for (var i = 0; i < this.fieldCount; i++) (data.get (keyWords.get (i))).addLast (this.loopData[i]);
110 }, $fz.isPrivate = true, $fz), "java.util.Map");
111 Clazz.overrideMethod (c$, "readLine",
114 this.line = (this.reader == null ? this.br.readLine () : this.reader.readNextLine ());
115 if (this.line == null) return null;
117 if (this.line.startsWith ("#")) this.fileHeader.append (this.line).appendC ('\n');
118 else this.isHeader = false;
121 if (Clazz.exceptionOf (e, Exception)) {
128 Clazz.overrideMethod (c$, "getData",
130 for (var i = 0; i < this.fieldCount; ++i) if ((this.loopData[i] = this.getNextDataToken ()) == null) return false;
132 return (this.fieldCount > 0);
134 Clazz.overrideMethod (c$, "skipLoop",
135 function (doReport) {
137 var ret = (doReport ? new javajs.util.SB () : null);
139 while ((str = this.peekToken ()) != null && str.charAt (0) == '_') {
140 if (ret != null) ret.append (str).append ("\n");
141 this.getTokenPeeked ();
145 while ((str = this.getNextDataToken ()) != null) {
146 if (ret == null) continue;
147 ret.append (str).append (" ");
148 if ((++m % n) == 0) ret.append ("\n");
150 return (ret == null ? null : ret.toString ());
152 Clazz.overrideMethod (c$, "getNextToken",
154 while (!this.strHasMoreTokens ()) if (this.setStringNextLine () == null) return null;
156 return this.nextStrToken ();
158 Clazz.overrideMethod (c$, "getNextDataToken",
160 var str = this.peekToken ();
161 if (str == null) return null;
162 if (this.wasUnQuoted) if (str.charAt (0) == '_' || str.startsWith ("loop_") || str.startsWith ("data_") || str.startsWith ("stop_") || str.startsWith ("global_")) return null;
163 return this.getTokenPeeked ();
165 Clazz.overrideMethod (c$, "peekToken",
167 while (!this.strHasMoreTokens ()) if (this.setStringNextLine () == null) return null;
170 this.strPeeked = this.nextStrToken ();
171 this.ichPeeked = this.ich;
173 return this.strPeeked;
175 Clazz.overrideMethod (c$, "getTokenPeeked",
177 this.ich = this.ichPeeked;
178 return this.strPeeked;
180 Clazz.overrideMethod (c$, "fullTrim",
183 var pt1 = str.length;
184 while (++pt0 < pt1 && javajs.util.PT.isWhitespace (str.charAt (pt0))) {
186 while (--pt1 > pt0 && javajs.util.PT.isWhitespace (str.charAt (pt1))) {
188 return str.substring (pt0, pt1 + 1);
190 Clazz.overrideMethod (c$, "toUnicode",
194 while ((pt = data.indexOf ('\\')) >= 0) {
195 var c = data.charCodeAt (pt + 1);
196 var ch = (c >= 65 && c <= 90 ? "ABX\u0394E\u03a6\u0393HI_K\u039bMNO\u03a0\u0398P\u03a3TY_\u03a9\u039e\u03a5Z".substring (c - 65, c - 64) : c >= 97 && c <= 122 ? "\u03b1\u03b2\u03c7\u03a4\u03a5\u03c6\u03b3\u03b7\u03b9_\u03ba\u03bb\u03bc\u03bd\u03bf\u03c0\u03b8\u03c1\u03c3\u03c4\u03c5_\u03c9\u03be\u03c5\u03b6".substring (c - 97, c - 96) : "_");
197 data = data.substring (0, pt) + ch + data.substring (pt + 2);
200 if (Clazz.exceptionOf (e, Exception)) {
207 Clazz.overrideMethod (c$, "parseLoopParameters",
208 function (fields, fieldOf, propertyOf) {
209 var propertyCount = 0;
210 if (fields == null) {
211 this.fields = new Array (100);
213 if (!javajs.util.CifDataParser.htFields.containsKey (fields[0])) for (var i = fields.length; --i >= 0; ) javajs.util.CifDataParser.htFields.put (fields[i], Integer.$valueOf (i));
215 for (var i = fields.length; --i >= 0; ) fieldOf[i] = -1;
217 propertyCount = fields.length;
218 }this.fieldCount = 0;
220 var str = this.peekToken ();
224 }if (str.charAt (0) != '_') break;
225 var pt = this.fieldCount++;
226 str = this.fixKey (this.getTokenPeeked ());
227 if (fields == null) {
228 this.fields[propertyOf[pt] = fieldOf[pt] = pt] = str;
230 }var iField = javajs.util.CifDataParser.htFields.get (str);
231 var i = (iField == null ? -1 : iField.intValue ());
232 if ((propertyOf[pt] = i) != -1) fieldOf[i] = pt;
234 if (this.fieldCount > 0) this.loopData = new Array (this.fieldCount);
235 return propertyCount;
237 Clazz.overrideMethod (c$, "fixKey",
239 return (javajs.util.PT.rep (key.startsWith ("_magnetic") ? key.substring (9) : key.startsWith ("_jana") ? key.substring (5) : key, ".", "_").toLowerCase ());
241 Clazz.defineMethod (c$, "setString",
242 ($fz = function (str) {
243 this.str = this.line = str;
244 this.cch = (str == null ? 0 : str.length);
246 }, $fz.isPrivate = true, $fz), "~S");
247 Clazz.defineMethod (c$, "setStringNextLine",
249 this.setString (this.readLine ());
250 if (this.line == null || this.line.length == 0) return this.line;
251 if (this.line.charAt (0) != ';') {
252 if (this.str.startsWith ("###non-st#")) this.ich = 10;
255 var str = '\1' + this.line.substring (1) + '\n';
256 while (this.readLine () != null) {
257 if (this.line.startsWith (";")) {
258 str = str.substring (0, str.length - 1) + '\1' + this.line.substring (1);
260 }str += this.line + '\n';
262 this.setString (str);
264 }, $fz.isPrivate = true, $fz));
265 Clazz.defineMethod (c$, "strHasMoreTokens",
267 if (this.str == null) return false;
269 while (this.ich < this.cch && ((ch = this.str.charAt (this.ich)) == ' ' || ch == '\t')) ++this.ich;
271 return (this.ich < this.cch && ch != '#');
272 }, $fz.isPrivate = true, $fz));
273 Clazz.defineMethod (c$, "nextStrToken",
275 if (this.ich == this.cch) return null;
276 var ichStart = this.ich;
277 var ch = this.str.charAt (ichStart);
278 if (ch != '\'' && ch != '"' && ch != '\1') {
279 this.wasUnQuoted = true;
280 while (this.ich < this.cch && (ch = this.str.charAt (this.ich)) != ' ' && ch != '\t') ++this.ich;
282 if (this.ich == ichStart + 1) if (this.nullString != null && (this.str.charAt (ichStart) == '.' || this.str.charAt (ichStart) == '?')) return this.nullString;
283 var s = this.str.substring (ichStart, this.ich);
285 }this.wasUnQuoted = false;
286 var chOpeningQuote = ch;
287 var previousCharacterWasQuote = false;
288 while (++this.ich < this.cch) {
289 ch = this.str.charAt (this.ich);
290 if (previousCharacterWasQuote && (ch == ' ' || ch == '\t')) break;
291 previousCharacterWasQuote = (ch == chOpeningQuote);
293 if (this.ich == this.cch) {
294 if (previousCharacterWasQuote) return this.str.substring (ichStart + 1, this.ich - 1);
295 return this.str.substring (ichStart, this.ich);
297 return this.str.substring (ichStart + 1, this.ich - 2);
298 }, $fz.isPrivate = true, $fz));
299 c$.htFields = c$.prototype.htFields = new java.util.Hashtable ();
300 Clazz.defineStatics (c$,
301 "grABC", "ABX\u0394E\u03a6\u0393HI_K\u039bMNO\u03a0\u0398P\u03a3TY_\u03a9\u039e\u03a5Z",
302 "grabc", "\u03b1\u03b2\u03c7\u03a4\u03a5\u03c6\u03b3\u03b7\u03b9_\u03ba\u03bb\u03bc\u03bd\u03bf\u03c0\u03b8\u03c1\u03c3\u03c4\u03c5_\u03c9\u03be\u03c5\u03b6");