forked from collectionspace/application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spec.java
649 lines (583 loc) · 23 KB
/
Spec.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/* Copyright 2010 University of Cambridge
* Licensed under the Educational Community License (ECL), Version 2.0. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the ECL 2.0 License at https://source.collectionspace.org/collection-space/LICENSE.txt
*/
package org.collectionspace.chain.csp.schema;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.collectionspace.chain.csp.config.Configurable;
import org.collectionspace.chain.csp.config.ReadOnlySection;
import org.collectionspace.chain.csp.config.Rules;
import org.collectionspace.chain.csp.config.Target;
import org.collectionspace.chain.csp.inner.CoreConfig;
import org.collectionspace.csp.api.core.CSP;
import org.collectionspace.csp.api.core.CSPContext;
import org.collectionspace.csp.api.core.CSPDependencyException;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author caret
* Handles the rules for parsing the default.xml / cspace-config.xml file
*
*
*/
public class Spec implements CSP, Configurable {
private static final Logger log=LoggerFactory.getLogger(Spec.class);
public static String SECTIONED="org.collectionspace.app.config.spec";
public static String SECTION_PREFIX="org.collectionspace.app.config.spec.";
public static String SPEC_ROOT=SECTION_PREFIX+"spec";
private static final String required_version="11";
private Map<String,Record> records=new HashMap<String,Record>();
private Map<String,Relationship> relationships=new HashMap<String,Relationship>();
private Map<String,Relationship> relationshipsPredicate=new HashMap<String,Relationship>();
private Map<String,String> inverserelationships = new HashMap<String,String>();
private Map<String,Schemas> schemas=new HashMap<String,Schemas>();
private Map<String,Record> records_by_web_url=new HashMap<String,Record>();
private Map<String,Record> records_by_services_url=new HashMap<String,Record>();
private Map<String,Record> records_by_services_docType=new HashMap<String,Record>();
private Map<String,Instance> instances=new LinkedHashMap<String,Instance>();
private Map<String, Set<Field>> termlist = new HashMap<String, Set<Field>>();
private Map<String, Structure> structure=new HashMap<String,Structure>();
private String version;
private String tenantid;
private EmailData ed;
private AdminData adminData;
@Override
public String getName() { return "schema"; }
public String getVersion() {
return version;
}
public String getTenantID() {
return tenantid;
}
@Override
public void go(CSPContext ctx) throws CSPDependencyException {
ctx.addConfigRules(this);
}
@Override
public void configure(Rules rules) {
/* MAIN/tenantid -> string */
rules.addRule(SECTIONED,new String[]{"tenantid"},SECTION_PREFIX+"tenantid",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
tenantid=(String)section.getValue("");
return this;
}
});
/* MAIN/version -> string */
rules.addRule(SECTIONED,new String[]{"version"},SECTION_PREFIX+"version",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
version=(String)section.getValue("");
return this;
}
});
/* MAIN/email -> EmailData */
rules.addRule(SECTIONED,new String[]{"email"},SECTION_PREFIX+"email",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
ed = new EmailData(Spec.this,section);
return this;
}
});
/* MAIN/admin -> AdminData */
rules.addRule(SECTIONED,new String[]{"admin"},SECTION_PREFIX+"admin",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
adminData = new AdminData(Spec.this,section);
return this;
}
});
/* MAIN/spec -> SPEC */
rules.addRule(SECTIONED,new String[]{"spec"},SECTION_PREFIX+"spec",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
((CoreConfig)parent).setRoot(SPEC_ROOT,Spec.this);
return Spec.this;
}
});
/* SPEC/schemas -> SCHEMAS */
rules.addRule(SECTION_PREFIX+"spec",new String[]{"schemas"},SECTION_PREFIX+"schemas",null,null);
/* RELATIONSHIPS/relation -> RELATION(@id) */
rules.addRule(SECTION_PREFIX+"schemas",new String[]{"schema"},SECTION_PREFIX+"schema",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Schemas s=new Schemas(Spec.this,section);
schemas.put(s.getID(),s);
return s;
}
});
/* SPEC/relationships -> RELATIONSHIPS */
rules.addRule(SECTION_PREFIX+"spec",new String[]{"relationships"},SECTION_PREFIX+"relationships",null,null);
/* RELATIONSHIPS/relation -> RELATION(@id) */
rules.addRule(SECTION_PREFIX+"relationships",new String[]{"relation"},SECTION_PREFIX+"relation",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Relationship r=new Relationship(Spec.this,section);
relationships.put(r.getID(),r);
relationshipsPredicate.put(r.getPredicate(),r);
if(r.hasInverse()){
inverserelationships.put(r.getInverse(), r.getID());
}
return r;
}
});
/* SPEC/records -> RECORDS */
rules.addRule(SECTION_PREFIX+"spec",new String[]{"records"},SECTION_PREFIX+"records",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Map<String,String> recordsdata=new HashMap<String,String>();
String blanks = "";
blanks=(String)section.getValue("/enum-blank");
if(blanks == null){
blanks = "Default String";
}
recordsdata.put("blank", blanks);
return recordsdata;
}
});
/* RECORDS/record -> RECORD(@id) */
rules.addRule(SECTION_PREFIX+"records",new String[]{"record"},SECTION_PREFIX+"record",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Map<String,String>data = (Map<String,String>)parent;
Record r=new Record(Spec.this,section,data);
records.put(r.getID(),r);
records_by_web_url.put(r.getWebURL(),r);
records_by_services_url.put(r.getServicesURL(),r);
records_by_services_docType.put(r.getServicesTenantSg(),r);
return r;
}
});
/* SPEC/section -> Sections */
rules.addRule(SECTION_PREFIX+"record",new String[]{"section"},SECTION_PREFIX+"uisection",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
String id=(String)section.getValue("/@id");
Record r=(Record)parent;
r.addUISection("base",id);
return r;
}
});
/* Section/section -> Sections */
rules.addRule(SECTION_PREFIX+"uisection",new String[]{"section"},SECTION_PREFIX+"uisection",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
String id=(String)section.getValue("/@id");
Record r=(Record)parent;
r.addUISection("base",id);
return r;
}
});
/* RECORD/services-instances-path -> RECORDPATH */
rules.addRule(SECTION_PREFIX+"record",new String[]{"services-single-instance-path"},SECTION_PREFIX+"instance-path",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Record r=(Record)parent;
String id=(String)section.getValue("/@id");
if(id==null)
id="common";
r.setServicesInstancePath(id,(String)section.getValue(""));
return r;
}
});
/* RECORD/services-record-path -> RECORDPATH */
rules.addRule(SECTION_PREFIX+"record",new String[]{"services-record-path"},SECTION_PREFIX+"record-path",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Record r=(Record)parent;
String id=(String)section.getValue("/@id");
if(id==null)
id="common";
r.setServicesRecordPath(id,(String)section.getValue(""));
return r;
}
});
/* RECORD/instances/instance -> INSTANCE */
rules.addRule(SECTION_PREFIX+"record",new String[]{"instances","instance"},SECTION_PREFIX+"instance",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Instance n=new Instance((Record)parent,section);
((Record)parent).addInstance(n);
return n;
}
});
/* FIELD/options/option -> OPTION */
rules.addRule(SECTION_PREFIX+"instance",new String[]{"options","option"},SECTION_PREFIX+"option",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Instance n=(Instance)parent;
boolean dfault=false;
String value=(String)section.getValue("/@default");
dfault=(value!=null && ("yes".equals(value.toLowerCase()) || "1".equals(value.toLowerCase())));
n.addOption((String)section.getValue("/@id"),(String)section.getValue(""),(String)section.getValue("/@sample"),dfault,(String)section.getValue("/@desc"));
return n;
}
});
/* RECORD/field -> FIELD */
rules.addRule(SECTION_PREFIX+"uisection",new String[]{"field"},SECTION_PREFIX+"field",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Field f=new Field((Record)parent,section);
((Record)parent).addField(f);
String is_chooser=(String)section.getValue("/@chooser");
if(is_chooser!=null && ("1".equals(is_chooser) || "yes".equals(is_chooser.toLowerCase())))
f.setType("chooser");
return f;
}
});
/* RECORD/structures/structure -> STRUCTURE */
rules.addRule(SECTION_PREFIX+"record",new String[]{"structures","structure"},SECTION_PREFIX+"structure",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Structure s=new Structure((Record)parent,section);
((Record)parent).addStructure(s);
return s;
}
});
/* STRUCTURE/repeat -> REPEAT */
rules.addRule(SECTION_PREFIX+"structure",new String[]{"view","sidebar","repeat"},SECTION_PREFIX+"repeat",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Repeat r=new Repeat((Structure)parent,section);
((Structure)parent).addSideBar(r);
return r;
}
});
//
/* FIELD/options/option -> OPTION */
rules.addRule(SECTION_PREFIX+"structure",new String[]{"view","hierarchy-section", "options", "option"},SECTION_PREFIX+"option",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Structure n=(Structure)parent;
boolean dfault=false;
String value=(String)section.getValue("/@default");
dfault=(value!=null && ("yes".equals(value.toLowerCase()) || "1".equals(value.toLowerCase())));
n.addOption((String)section.getValue("/@id"),(String)section.getValue(""),(String)section.getValue("/@sample"),dfault);
return n;
}
});
/* STRUCTURE/repeat -> REPEAT */
rules.addRule(SECTION_PREFIX+"structure",new String[]{"repeat"},SECTION_PREFIX+"repeat",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Repeat r=new Repeat((Structure)parent,section);
((Structure)parent).addField(r);
((Structure)parent).addAllField(r);
return r;
}
});
/* RECORD/repeat -> REPEAT */
rules.addRule(SECTION_PREFIX+"uisection",new String[]{"repeat"},SECTION_PREFIX+"repeat",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Repeat r=new Repeat((Record)parent,section);
((Record)parent).addField(r);
return r;
}
});
/* REPEAT/field -> FIELD */
rules.addRule(SECTION_PREFIX+"repeat",new String[]{"field"},SECTION_PREFIX+"field",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Field f=new Field((Repeat)parent,section);
f.getRecord().addField(f);
((Repeat)parent).addChild(f);
return f;
}
});
/* RECORD/group -> GROUP */
rules.addRule(SECTION_PREFIX+"uisection",new String[]{"group"},SECTION_PREFIX+"group",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Group r=new Group((Record)parent,section);
((Record)parent).addField(r);
return r;
}
});
/* GROUP/field -> FIELD */
rules.addRule(SECTION_PREFIX+"group",new String[]{"field"},SECTION_PREFIX+"field",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Field f=new Field((Group)parent,section);
f.getRecord().addField(f);
((Group)parent).addChild(f);
return f;
}
});
/* GROUP/group -> GROUP */
rules.addRule(SECTION_PREFIX+"group",new String[]{"group"},SECTION_PREFIX+"group",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Group r=new Group((Group)parent,section);
((Group)parent).addChild(r);
r.getRecord().addField(r);
return r;
}
});
/* REPEAT/group -> GROUP */
rules.addRule(SECTION_PREFIX+"repeat",new String[]{"group"},SECTION_PREFIX+"group",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Group r=new Group((Repeat)parent,section);
((Repeat)parent).addChild(r);
r.getRecord().addField(r);
return r;
}
});
/* GROUP/repeat -> REPEAT */
rules.addRule(SECTION_PREFIX+"group",new String[]{"repeat"},SECTION_PREFIX+"repeat",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Repeat r=new Repeat((Repeat)parent,section);
((Group)parent).addChild(r);
r.getRecord().addField(r);
return r;
}
});
/* REPEAT/repeat -> REPEAT */
rules.addRule(SECTION_PREFIX+"repeat",new String[]{"repeat"},SECTION_PREFIX+"repeat",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Repeat r=new Repeat((Repeat)parent,section);
((Repeat)parent).addChild(r);
r.getRecord().addField(r);
return r;
}
});
/* FIELD/options/option -> OPTION */
rules.addRule(SECTION_PREFIX+"field",new String[]{"options","option"},SECTION_PREFIX+"option",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Field f=(Field)parent;
boolean dfault=false;
String value=(String)section.getValue("/@default");
dfault=(value!=null && ("yes".equals(value.toLowerCase()) || "1".equals(value.toLowerCase())));
f.addOption((String)section.getValue("/@id"),(String)section.getValue(""),(String)section.getValue("/@sample"),dfault);
return f;
}
});
/* FIELD/merges/merge -> OPTION */
rules.addRule(SECTION_PREFIX+"field",new String[]{"merges","merge"},SECTION_PREFIX+"merge",null,new Target(){
@Override
public Object populate(Object parent, ReadOnlySection section) {
Field f=(Field)parent;
f.addMerge((String)section.getValue("/@id"), (String)section.getValue("/@rank"));
/*
boolean dfault=false;
String value=(String)section.getValue("/@default");
dfault=(value!=null && ("yes".equals(value.toLowerCase()) || "1".equals(value.toLowerCase())));
f.addOption((String)section.getValue("/@id"),(String)section.getValue(""),(String)section.getValue("/@sample"),dfault);
*/
return f;
}
});
}
public EmailData getEmailData() { return ed.getEmailData(); }
public AdminData getAdminData() { return adminData.getAdminData(); }
public Boolean hasRelationship(String id){ if(relationships.containsKey(id)){return true;} else return false;}
public Boolean hasRelationshipByPredicate(String id){ if(relationshipsPredicate.containsKey(id)){return true;} else return false;}
public Relationship getRelation(String id) { return relationships.get(id); }
public Relationship getRelationshipByPredicate(String id){ return relationshipsPredicate.get(id); }
public Relationship[] getAllRelations(){ return relationships.values().toArray(new Relationship[0]); }
public Relationship getInverseRelationship(String id) { if(inverserelationships.containsKey(id)){ return relationships.get(inverserelationships.get(id)); } else return null; }
public Boolean hasRelationshipInverse(String id){ if(inverserelationships.containsKey(id) && relationships.containsKey(inverserelationships.get(id))){return true;} else return false;}
public Boolean hasSchema(String id){ if(schemas.containsKey(id)){return true;} else return false;}
public Schemas getSchema(String id) { return schemas.get(id); }
public Schemas[] getAllSchemas(){ return schemas.values().toArray(new Schemas[0]); }
public Boolean hasRecord(String id){ if(records.containsKey(id)){return true;} else return false;}
public Boolean hasRecordByServicesUrl(String url) { return records_by_services_url.containsKey(url); }
public Boolean hasRecordByServicesDocType(String docType) { return records_by_services_docType.containsKey(docType); }
public Boolean hasRecordByWebUrl(String url){ return records_by_web_url.containsKey(url);}
public Record getRecord(String id) { return records.get(id); }
public Record getRecordByWebUrl(String url) { return records_by_web_url.get(url); }
public Record getRecordByServicesUrl(String url) { return records_by_services_url.get(url); }
public Record getRecordByServicesDocType(String docType) { return records_by_services_docType.get(docType); }
public Record[] getAllRecords() { return records.values().toArray(new Record[0]); }
public String[] getAllRecordsOrdered() {
List<String> precrds = new ArrayList<String>();
List<String> arecrds = new ArrayList<String>();
List<String> vrecrds = new ArrayList<String>();
List<String> adrecrds = new ArrayList<String>();
List<String> crecrds = new ArrayList<String>();
for (Record rc : this.getAllRecords()) {
if (rc.isInRecordList()) {
if (rc.isShowType("procedure")) {
precrds.add(rc.getWebURL());
} else if (rc.isShowType("authority")) {
vrecrds.add(rc.getWebURL());
for(Instance ins : rc.getAllInstances()){
arecrds.add(ins.getWebURL());
}
} else if (rc.isShowType("record")) {
crecrds.add(rc.getWebURL());
} else if(rc.isShowType("authorizationdata") || rc.isShowType("userdata")){
adrecrds.add(rc.getWebURL());
}
}
}
//order:
/*
* Cataloging
* Procedures in alpha order
* Vocabularies in alpha order
* Admin in alpha order
*/
Collections.sort(crecrds);
Collections.sort(precrds);
Collections.sort(vrecrds);
Collections.sort(arecrds);
Collections.sort(adrecrds);
crecrds.addAll(precrds);
crecrds.addAll(vrecrds);
crecrds.addAll(adrecrds);
crecrds.addAll(arecrds);
return crecrds.toArray(new String[0]);
}
public void addTermlist(String instanceid, Field fs){
if(termlist.containsKey(instanceid)){
Set<Field> temp = termlist.get(instanceid);
temp.add(fs);
termlist.put(instanceid,temp);
}
else{
termlist.put(instanceid,new HashSet<Field>(Arrays.asList(fs)));
}
}
public void addInstance(Instance n) {
instances.put(n.getID(),n);
}
public void addStructure(Structure s) {
structure.put(s.getID(),s);
}
public Boolean hasTermlist(String id){ if(termlist.containsKey(id)){return true;} else return false;}
public Field[] getTermlist(String id) { return termlist.get(id).toArray(new Field[0]);}
public Instance getInstance(String id) { return instances.get(id); }
public Structure getStructure(String id) { return structure.get(id); }
@Override
public void config_finish() throws CSPDependencyException {
if(!required_version.equals(version))
throw new CSPDependencyException("Config is out of date: require="+required_version+" got="+version);
for(Record r : records.values()) {
r.config_finish(this);
}
}
@Override
public void complete_init() throws CSPDependencyException {}
public Map<String,String> ui_url_to_id(){
Map<String,String> url_to_type=new HashMap<String,String>();
for(Record r : getAllRecords()) {
url_to_type.put(r.getWebURL(),r.getID());
}
return url_to_type;
}
public String dump() {
StringBuffer out=new StringBuffer();
String[] allStrings = null;
String[] allBooleans = null;
String[] allSets = null;
Map <String, StringBuffer> rout = new HashMap<String, StringBuffer>();
for(Record r : records.values()){
if(allStrings == null){
allStrings = r.utils.getAllString();
allBooleans = r.utils.getAllBoolean();
allSets = r.utils.getAllSets();
for(String s: allStrings){
rout.put("String:"+s, new StringBuffer());
rout.get("String:"+s).append(r.utils.getDefaultString(s) + ",");
}
for(String s: allBooleans){
rout.put("Boolean:"+s, new StringBuffer());
rout.get("Boolean:"+s).append(r.utils.getDefaultBoolean(s) + ",");
}
for(String s:allSets){
rout.put("Set:"+s, new StringBuffer());
rout.get("Set:"+s).append("\"" + r.utils.allDefaultSets.get(s) + "\"" + ",");
}
out.append("Field Name,Default Value,");
}
for(String s: allStrings){
rout.get("String:"+s).append(r.utils.getString(s) + ",");
}
for(String s: allBooleans){
rout.get("Boolean:"+s).append(r.utils.getBoolean(s) + ",");
}
for(String s:allSets){
rout.get("Set:"+s).append("\""+ r.utils.allSets.get(s) + "\"" + ",");
}
//might want to pivot the view to have records down and fields across to make it wasier to see patterns
out.append(r.getID() + ",");
}
for (Map.Entry<String, StringBuffer> entry : rout.entrySet()) {
String key = entry.getKey();
StringBuffer value = entry.getValue();
out.append("\n");
out.append(key+",");
out.append(value);
// ...
}
return out.toString();
}
public JSONObject dumpJson() throws JSONException {
JSONObject out=new JSONObject();
ed.dumpJson(out);
adminData.dumpJson(out);
String[] allStrings = null;
String[] allBooleans = null;
String[] allSets = null;
JSONObject RecordTable=new JSONObject();
for(Record r : records.values()){
if(allStrings == null){
allStrings = r.utils.getAllString();
allBooleans = r.utils.getAllBoolean();
allSets = r.utils.getAllSets();
for(String s: allStrings){
JSONObject data = new JSONObject();
data.put("default", r.utils.getDefaultString(s));
RecordTable.put("String:"+s, data);
}
for(String s: allBooleans){
JSONObject data = new JSONObject();
data.put("default", r.utils.getDefaultBoolean(s));
RecordTable.put("Boolean:"+s,data);
}
for(String s:allSets){
JSONObject data = new JSONObject();
data.put("default", r.utils.getDefaultSet(s));
RecordTable.put("Set:"+s,data);
}
}
else{
for(String s: allStrings){
JSONObject data = RecordTable.getJSONObject("String:"+s);
data.put(r.getID(), r.utils.getString(s));
RecordTable.put("String:"+s, data);
}
for(String s: allBooleans){
JSONObject data = RecordTable.getJSONObject("Boolean:"+s);
data.put(r.getID(), r.utils.getBoolean(s));
RecordTable.put("Boolean:"+s,data);
}
for(String s:allSets){
JSONObject data = RecordTable.getJSONObject("Set:"+s);
data.put(r.getID(), r.utils.getSet(s));
RecordTable.put("Set:"+s,data);
}
}
}
out.put("allrecords", RecordTable);
// r.dumpJson(out);
return out;
}
}