XSDJSONVisitor.java
25.7 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.sun.xml.xsom.XSAnnotation
* com.sun.xml.xsom.XSAttGroupDecl
* com.sun.xml.xsom.XSAttributeDecl
* com.sun.xml.xsom.XSAttributeUse
* com.sun.xml.xsom.XSComplexType
* com.sun.xml.xsom.XSContentType
* com.sun.xml.xsom.XSDeclaration
* com.sun.xml.xsom.XSElementDecl
* com.sun.xml.xsom.XSFacet
* com.sun.xml.xsom.XSIdentityConstraint
* com.sun.xml.xsom.XSModelGroup
* com.sun.xml.xsom.XSModelGroupDecl
* com.sun.xml.xsom.XSNotation
* com.sun.xml.xsom.XSParticle
* com.sun.xml.xsom.XSRestrictionSimpleType
* com.sun.xml.xsom.XSSchema
* com.sun.xml.xsom.XSSimpleType
* com.sun.xml.xsom.XSTerm
* com.sun.xml.xsom.XSType
* com.sun.xml.xsom.XSVariety
* com.sun.xml.xsom.XSWildcard
* com.sun.xml.xsom.XSXPath
* com.sun.xml.xsom.XmlString
* com.sun.xml.xsom.impl.ElementDecl
* com.sun.xml.xsom.visitor.XSVisitor
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.xsd;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.xsd.AnnotationProcessor;
import com.sun.xml.xsom.XSAnnotation;
import com.sun.xml.xsom.XSAttGroupDecl;
import com.sun.xml.xsom.XSAttributeDecl;
import com.sun.xml.xsom.XSAttributeUse;
import com.sun.xml.xsom.XSComplexType;
import com.sun.xml.xsom.XSContentType;
import com.sun.xml.xsom.XSDeclaration;
import com.sun.xml.xsom.XSElementDecl;
import com.sun.xml.xsom.XSFacet;
import com.sun.xml.xsom.XSIdentityConstraint;
import com.sun.xml.xsom.XSModelGroup;
import com.sun.xml.xsom.XSModelGroupDecl;
import com.sun.xml.xsom.XSNotation;
import com.sun.xml.xsom.XSParticle;
import com.sun.xml.xsom.XSRestrictionSimpleType;
import com.sun.xml.xsom.XSSchema;
import com.sun.xml.xsom.XSSimpleType;
import com.sun.xml.xsom.XSTerm;
import com.sun.xml.xsom.XSType;
import com.sun.xml.xsom.XSVariety;
import com.sun.xml.xsom.XSWildcard;
import com.sun.xml.xsom.XSXPath;
import com.sun.xml.xsom.XmlString;
import com.sun.xml.xsom.impl.ElementDecl;
import com.sun.xml.xsom.visitor.XSVisitor;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class XSDJSONVisitor
implements XSVisitor {
private Logger logger = LoggerFactory.getLogger(XSDJSONVisitor.class);
private static final Map<String, String> xsdRestrictions = new HashMap<String, String>();
private String currentXPath = "";
private Stack<XSType> xsTypeStack = new Stack();
private List<String> listOfAllXSDPaths = null;
private ResourceResolver resourceResolver = null;
private Boolean getTypeForFragmentCreation = false;
private String calculatedComplexType = "";
private HashMap<String, Integer> nameCountMap;
private JSONObject json;
private JSONObject currentJsonObject;
public XSDJSONVisitor(JSONObject jsonObject, List<String> listOfAllXSDPaths, ResourceResolver resourceResolver) {
this.listOfAllXSDPaths = listOfAllXSDPaths;
this.resourceResolver = resourceResolver;
this.nameCountMap = new HashMap();
this.currentJsonObject = this.json = jsonObject;
}
public XSDJSONVisitor(String currentXPath, Boolean getTypeForFragmentCreation) {
this.getTypeForFragmentCreation = getTypeForFragmentCreation;
this.currentXPath = currentXPath;
this.nameCountMap = new HashMap();
this.currentJsonObject = this.json = null;
}
public void attributeUse(XSAttributeUse use) {
try {
XSAttributeDecl attributeDecl = use.getDecl();
JSONObject attributeJson = new JSONObject();
this.currentJsonObject.put(attributeDecl.getName(), (Object)attributeJson);
JSONObject previousJsonObject = this.currentJsonObject;
this.currentJsonObject = attributeJson;
this.addCommonProperties((XSDeclaration)attributeDecl);
if (use.getDefaultValue() != null) {
String defaultValue = use.getDefaultValue().value;
defaultValue = this.changeDefaultValue(defaultValue, attributeDecl.getType().getName());
this.currentJsonObject.put("_value", (Object)defaultValue);
}
this.currentJsonObject.put("bindRef", (Object)(this.currentXPath + "/@" + attributeDecl.getName()));
if (use.isRequired()) {
this.currentJsonObject.put("mandatory", (Object)"true");
}
XSSimpleType simpleType = attributeDecl.getType();
simpleType.visit((XSVisitor)this);
this.currentJsonObject = previousJsonObject;
}
catch (JSONException e) {
this.logger.error("JSONException while generating JSON for attribute " + use.getDecl().getName() + ", Exception: " + (Object)e);
}
}
public String returnType() {
return this.calculatedComplexType;
}
public void modelGroupDecl(XSModelGroupDecl decl) {
this.modelGroup(decl.getModelGroup());
}
public void modelGroup(XSModelGroup model) {
for (XSParticle particle : model.getChildren()) {
if (!this.calculatedComplexType.equals("")) {
return;
}
particle.visit((XSVisitor)this);
}
}
public void particle(XSParticle particle) {
XSTerm term = particle.getTerm();
if (!this.getTypeForFragmentCreation.booleanValue()) {
if (term.isElementDecl()) {
this.elementDecl(term.asElementDecl(), particle.getMinOccurs() != null ? particle.getMinOccurs().intValue() : 1, particle.getMaxOccurs() != null ? particle.getMaxOccurs().intValue() : 1);
} else {
term.visit((XSVisitor)this);
}
} else if (term.isElementDecl() && this.calculatedComplexType.equals("")) {
if (((ElementDecl)term).getName().equals(this.currentXPath)) {
this.calculatedComplexType = ((ElementDecl)term).getType().toString();
} else if (this.currentXPath.indexOf(47) > 0 && ((ElementDecl)term).getName().equals(StringUtils.substringBefore((String)this.currentXPath, (String)"/"))) {
this.currentXPath = StringUtils.substringAfter((String)this.currentXPath, (String)"/");
XSComplexType type = (XSComplexType)((ElementDecl)term).getType();
if (type.isComplexType()) {
this.complexType(type);
}
}
} else {
term.visit((XSVisitor)this);
}
}
public void complexType(XSComplexType complexType) {
try {
if (!this.getTypeForFragmentCreation.booleanValue()) {
this.addPanelProperties();
this.addPanelAnnotationInfo(complexType);
JSONObject itemsJson = new JSONObject();
this.currentJsonObject.put("items", (Object)itemsJson);
itemsJson.put("jcr:primaryType", (Object)"nt:unstructured");
JSONObject previousJsonObject = this.currentJsonObject;
this.currentJsonObject = itemsJson;
for (XSAttributeUse use : complexType.getAttributeUses()) {
this.attributeUse(use);
}
XSContentType contentType = complexType.getContentType();
if (contentType.asSimpleType() != null) {
JSONObject simpleTypeJson = new JSONObject();
this.currentJsonObject.put("content", (Object)simpleTypeJson);
JSONObject prevJsonObject = this.currentJsonObject;
this.currentJsonObject = simpleTypeJson;
this.addCommonProperties("content", "content");
this.currentJsonObject.put("bindRef", (Object)(this.currentXPath + "/text()"));
contentType.visit((XSVisitor)this);
this.currentJsonObject = prevJsonObject;
} else if (contentType.asParticle() != null) {
contentType.visit((XSVisitor)this);
}
this.currentJsonObject = previousJsonObject;
} else {
if (!"".equals(this.calculatedComplexType)) {
return;
}
XSContentType contentType = complexType.getContentType();
contentType.visit((XSVisitor)this);
}
}
catch (JSONException e) {
this.logger.error("JSONException while generating JSON for complex type " + complexType.getName() + ", Exception: " + (Object)e);
}
}
public void elementDecl(XSElementDecl elementDecl) {
this.elementDecl(elementDecl, 1, 1);
}
public void buildComplexType(XSComplexType xsComplexType) {
XSType type = xsComplexType.getBaseType();
if (this.xsTypeStack.contains((Object)type)) {
return;
}
this.xsTypeStack.push(type);
String originalXpath = this.currentXPath;
this.currentXPath = this.currentXPath + "/" + xsComplexType.getName();
try {
JSONObject elementJson = new JSONObject();
this.currentJsonObject.put(xsComplexType.getName(), (Object)elementJson);
JSONObject previousJsonObject = this.currentJsonObject;
this.currentJsonObject = elementJson;
this.addCommonProperties((XSDeclaration)xsComplexType);
this.currentJsonObject.put("bindRef", (Object)this.currentXPath);
if (type.isComplexType()) {
this.currentJsonObject.put("complexType", (Object)type.getName());
}
xsComplexType.visit((XSVisitor)this);
this.currentJsonObject = previousJsonObject;
}
catch (Exception e) {
throw new GuideException(e);
}
finally {
this.xsTypeStack.pop();
this.currentXPath = originalXpath;
}
}
public void elementDecl(XSElementDecl elementDecl, int minOccur, int maxOccur) {
XSType type = elementDecl.getType();
if (this.xsTypeStack.contains((Object)type)) {
return;
}
this.xsTypeStack.push(type);
String originalXpath = this.currentXPath;
this.currentXPath = this.currentXPath + "/" + elementDecl.getName();
try {
JSONObject elementJson = new JSONObject();
this.currentJsonObject.put(elementDecl.getName(), (Object)elementJson);
JSONObject previousJsonObject = this.currentJsonObject;
this.currentJsonObject = elementJson;
this.addCommonProperties((XSDeclaration)elementDecl);
if (elementDecl.getDefaultValue() != null) {
String defaultValue = elementDecl.getDefaultValue().value;
defaultValue = this.changeDefaultValue(defaultValue, elementDecl.getType().getName());
this.currentJsonObject.put("_value", (Object)defaultValue);
}
this.currentJsonObject.put("bindRef", (Object)this.currentXPath);
if (type.isComplexType()) {
this.currentJsonObject.put("minOccur", minOccur);
this.currentJsonObject.put("maxOccur", maxOccur);
this.currentJsonObject.put("complexType", (Object)type.getName());
this.handleComplexType(type.getName());
}
type.visit((XSVisitor)this);
this.currentJsonObject = previousJsonObject;
}
catch (Exception e) {
throw new GuideException(e);
}
finally {
this.xsTypeStack.pop();
this.currentXPath = originalXpath;
}
}
public void attributeDecl(XSAttributeDecl attrDecl) {
}
public void simpleType(XSSimpleType simpleType) {
if (simpleType.getVariety() == XSVariety.ATOMIC) {
this.addFieldTypeInfo(simpleType);
this.addFieldRestrictions(simpleType);
this.addFieldAnnotationInfo(simpleType);
} else {
this.logger.warn("unsupported simple type, : " + simpleType.getName() + " : " + simpleType.getVariety().toString());
try {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidetextbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideTextBox");
}
catch (JSONException e) {
this.logger.error("Exception while generating JSON for unsupported simple type, : " + simpleType.getName() + " : " + simpleType.getVariety().toString() + ", " + (Object)e);
}
}
}
public void empty(XSContentType empty) {
}
public void facet(XSFacet facet) {
}
public void annotation(XSAnnotation ann) {
}
public void schema(XSSchema schema) {
}
public void notation(XSNotation notation) {
}
public void identityConstraint(XSIdentityConstraint decl) {
}
public void xpath(XSXPath xp) {
}
public void wildcard(XSWildcard wc) {
}
public void attGroupDecl(XSAttGroupDecl decl) {
}
private void addCommonProperties(XSDeclaration xsDeclaration) {
String localName = GuideUtils.getOrGenerateUniqueName(xsDeclaration.getName(), this.nameCountMap);
String decType = xsDeclaration instanceof XSAttributeDecl ? "attribute" : "element";
this.addCommonProperties(localName, decType);
}
private void addCommonProperties(String localName, String elType) {
try {
this.currentJsonObject.put("name", (Object)localName);
this.currentJsonObject.put("jcr:title", (Object)GuideUtils.humanize(localName));
this.currentJsonObject.put("jcr:primaryType", (Object)"nt:unstructured");
this.currentJsonObject.put("guide:xsdtype", (Object)elType);
}
catch (JSONException e) {
this.logger.error("Exception while generating JSON for " + localName + " " + (Object)e);
}
}
private void addPanelProperties() {
try {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/panel");
this.currentJsonObject.put("guideNodeClass", (Object)"guidePanel");
JSONObject layout = new JSONObject();
layout.put("jcr:primaryType", (Object)"nt:unstructured");
layout.put("sling:resourceType", (Object)"fd/af/layouts/gridFluidLayout");
this.currentJsonObject.put("layout", (Object)layout);
}
catch (JSONException e) {
this.logger.error("Exception while generating JSON for panel " + (Object)e);
}
}
private String changeDefaultValue(String defaultValue, String typeOfValue) {
if ("true".equals(defaultValue) && "boolean".equals(typeOfValue)) {
defaultValue = "1";
}
if ("false".equals(defaultValue) && "boolean".equals(typeOfValue)) {
defaultValue = "0";
}
return defaultValue;
}
private void addFieldTypeInfo(XSSimpleType simpleType) {
try {
if (simpleType.getFacet("enumeration") != null) {
JSONArray options = new JSONArray();
List enumFacets = simpleType.getFacets("enumeration");
for (XSFacet enumFacet : enumFacets) {
String enumValue = enumFacet.getValue().value;
options.put((Object)(enumValue + "=" + enumValue));
}
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidedropdownlist");
this.currentJsonObject.put("guideNodeClass", (Object)"guideDropDownList");
this.currentJsonObject.put("options", (Object)options);
return;
}
String simpleTypeName = simpleType.getName();
if ("boolean".equals(simpleTypeName)) {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidecheckbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideCheckBox");
this.currentJsonObject.put("options", (Object)new JSONArray("1=true"));
} else if ("byte".equals(simpleTypeName) || "unsignedByte".equals(simpleTypeName) || "short".equals(simpleTypeName) || "unsignedShort".equals(simpleTypeName) || "int".equals(simpleTypeName) || "unsignedInt".equals(simpleTypeName) || "long".equals(simpleTypeName) || "unsignedLong".equals(simpleTypeName) || "integer".equals(simpleTypeName) || "nonPositiveInteger".equals(simpleTypeName) || "negativeInteger".equals(simpleTypeName) || "nonNegativeInteger".equals(simpleTypeName) || "positiveInteger".equals(simpleTypeName) || this.reachesNearPrimitive(simpleType, "integer")) {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidenumericbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideNumericBox");
this.currentJsonObject.put("dataType", (Object)"integer");
} else if ("decimal".equals(simpleTypeName) || this.reachesNearPrimitive(simpleType, "decimal")) {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidenumericbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideNumericBox");
this.currentJsonObject.put("dataType", (Object)"decimal");
} else if ("double".equals(simpleTypeName) || "float".equals(simpleTypeName) || this.reachesNearPrimitive(simpleType, "float") || this.reachesNearPrimitive(simpleType, "double")) {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidenumericbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideNumericBox");
this.currentJsonObject.put("dataType", (Object)"float");
} else if ("date".equals(simpleTypeName) || this.reachesNearPrimitive(simpleType, "date")) {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidedatepicker");
this.currentJsonObject.put("guideNodeClass", (Object)"guideDatePicker");
} else if ("string".equals(simpleTypeName) || this.reachesNearPrimitive(simpleType, "string")) {
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidetextbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideTextBox");
} else {
this.logger.warn("unrecognized type, treating it as text: " + simpleType.getName() + " : " + simpleType.getPrimitiveType().getName());
this.currentJsonObject.put("sling:resourceType", (Object)"fd/af/components/guidetextbox");
this.currentJsonObject.put("guideNodeClass", (Object)"guideTextBox");
}
}
catch (JSONException e) {
this.logger.error("Exception while generating JSON for field " + simpleType.getName() + " " + (Object)e);
}
}
private boolean reachesNearPrimitive(XSSimpleType simpleType, String dataType) {
if (simpleType.getName() != null && simpleType.getName().equalsIgnoreCase(dataType)) {
return true;
}
if (simpleType.getSimpleBaseType() != null) {
return this.reachesNearPrimitive(simpleType.getSimpleBaseType(), dataType);
}
return false;
}
private void addFieldRestrictions(XSSimpleType simpleType) {
XSRestrictionSimpleType restriction = simpleType.asRestriction();
if (restriction == null || restriction.getFacet("enumeration") != null) {
return;
}
StringBuffer restrictRegexBuffer = new StringBuffer("");
for (String facetType : xsdRestrictions.keySet()) {
if (restriction.getFacet(facetType) == null) continue;
restrictRegexBuffer.append("(" + restriction.getFacet((String)facetType).getValue().value + ") && ");
}
String restrictRegex = restrictRegexBuffer.toString();
if (restrictRegex.endsWith(" && ")) {
restrictRegex = restrictRegex.substring(0, restrictRegex.length() - 4);
}
}
private void addFieldAnnotationInfo(XSSimpleType simpleType) {
try {
this.applyAnnotationInfo((XSType)simpleType);
}
catch (JSONException e) {
this.logger.error("Exception while generating annotation JSON for field " + simpleType.getName() + " " + (Object)e);
}
}
private void addPanelAnnotationInfo(XSComplexType complexType) {
try {
this.applyAnnotationInfo((XSType)complexType);
}
catch (JSONException e) {
this.logger.error("Exception while generating annotation JSON for panel " + complexType.getName() + " " + (Object)e);
}
}
private void applyAnnotationInfo(XSType type) throws JSONException {
XSAnnotation ann = type.getAnnotation();
if (ann == null) {
return;
}
AnnotationProcessor annotationProcessor = AnnotationProcessor.getInstance();
Element element = (Element)ann.getAnnotation();
List<Node> appinfoNodes = annotationProcessor.getValidAppInfoNodes(element);
Hashtable<String, String> propertiesTable = new Hashtable<String, String>();
for (Node appinfo : appinfoNodes) {
propertiesTable.putAll(annotationProcessor.getProperties(appinfo));
}
Set set = propertiesTable.entrySet();
for (Map.Entry property : set) {
this.applyNestedJson(this.currentJsonObject, (String)property.getKey(), property.getValue());
}
}
private void applyNestedJson(JSONObject jsonObject, String key, Object value) throws JSONException {
if (key.charAt(0) == '/') {
throw new JSONException("/ at the beginning of key is not allowed");
}
if (key.contains("/")) {
int prevIndex = -1;
int currIndex = key.indexOf(47, prevIndex + 1);
String levelKey = null;
JSONObject currJsonObject = jsonObject;
JSONObject levelJsonObject = null;
while (currIndex != -1) {
levelKey = key.substring(prevIndex + 1, currIndex);
levelJsonObject = currJsonObject.optJSONObject(levelKey);
if (levelJsonObject == null) {
levelJsonObject = new JSONObject();
currJsonObject.put(levelKey, (Object)levelJsonObject);
}
currJsonObject = levelJsonObject;
prevIndex = currIndex;
currIndex = key.indexOf(47, prevIndex + 1);
}
levelKey = key.substring(prevIndex + 1);
currJsonObject.put(levelKey, value);
} else {
jsonObject.put(key, value);
}
}
private void handleComplexType(String complexTypeName) {
try {
String query;
Iterator fragmentNodes;
if (this.resourceResolver != null && (fragmentNodes = this.resourceResolver.findResources(query = "/jcr:root/content/dam/formsanddocuments//element(*, dam:Asset) \n[\njcr:content/metadata/@fragmentModelRoot ='/" + complexTypeName + "'\n]", "xpath")).hasNext()) {
Resource resource = (Resource)fragmentNodes.next();
String fragRef = resource.getPath();
ValueMap valueMap = (ValueMap)resource.getChild("jcr:content").getChild("metadata").adaptTo(ValueMap.class);
String xsdRef = (String)valueMap.get((Object)"xsdRef");
this.listOfAllXSDPaths = this.getListWithContentBeforeJCRContent(this.listOfAllXSDPaths);
if (this.listOfAllXSDPaths.contains(xsdRef)) {
this.currentJsonObject.put("fragRef", (Object)fragRef);
}
}
}
catch (Exception e) {
this.logger.error("Error in setting fragRef for ComplexType" + complexTypeName, (Throwable)e);
}
}
private List<String> getListWithContentBeforeJCRContent(List<String> listOfAllXSDPaths) {
boolean index = false;
ArrayList<String> sanitizedList = new ArrayList<String>();
ListIterator<String> iterator = listOfAllXSDPaths.listIterator();
while (iterator.hasNext()) {
String listEntry = iterator.next();
sanitizedList.add(StringUtils.substringBefore((String)listEntry, (String)"/jcr:content"));
}
return sanitizedList;
}
static {
xsdRestrictions.put("fractionDigits", "*");
xsdRestrictions.put("totalDigits", "*");
xsdRestrictions.put("minLength", "*");
xsdRestrictions.put("maxLength", "*");
xsdRestrictions.put("length", "*");
xsdRestrictions.put("maxExclusive", "*");
xsdRestrictions.put("maxInclusive", "*");
xsdRestrictions.put("minExclusive", "*");
xsdRestrictions.put("minInclusive", "*");
xsdRestrictions.put("pattern", "*");
}
}