JsonObjectCreatorImpl.java
31.4 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
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.i18n.I18n
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* 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.apache.sling.i18n.ResourceBundleProvider
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.service.impl;
import com.adobe.aemds.guide.common.ResourcePropertyTransformer;
import com.adobe.aemds.guide.service.AdaptiveFormConfigurationService;
import com.adobe.aemds.guide.service.GuideModelImporter;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.service.GuideModuleImporter;
import com.adobe.aemds.guide.service.JsonObjectCreator;
import com.adobe.aemds.guide.service.XFAModelTransformer;
import com.adobe.aemds.guide.service.impl.GuideModelImporterImpl;
import com.adobe.aemds.guide.taglibs.GuideELUtils;
import com.adobe.aemds.guide.utils.GuideContainerThreadLocal;
import com.adobe.aemds.guide.utils.GuideFragmentHolder;
import com.adobe.aemds.guide.utils.GuideSchema;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.JSONCreationOptions;
import com.adobe.aemds.guide.utils.NodeStructureUtils;
import com.adobe.aemds.guide.utils.XMLUtils;
import com.adobe.aemds.guide.utils.guideJson.AbsoluteBindrefResolver;
import com.adobe.aemds.guide.utils.guideJson.AssetRefCollector;
import com.adobe.aemds.guide.utils.guideJson.CrossFragFieldsCollector;
import com.adobe.aemds.guide.utils.guideJson.DuplicateBindrefsCollector;
import com.adobe.aemds.guide.utils.guideJson.EmbeddedFormsXsdRootFixer;
import com.adobe.aemds.guide.utils.guideJson.GuideJsonItemsTraverser;
import com.adobe.aemds.guide.utils.guideJson.GuideJsonVisitor;
import com.adobe.aemds.guide.utils.guideJson.LazyPanelsCollector;
import com.day.cq.i18n.I18n;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
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.apache.sling.i18n.ResourceBundleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, metatype=0, label="Adaptive Form Json Object creator", description="Adaptive Form Json Object creator Service")
@Service(value={JsonObjectCreator.class})
public class JsonObjectCreatorImpl
implements JsonObjectCreator {
private static Logger log = LoggerFactory.getLogger(JsonObjectCreatorImpl.class);
@Reference(target="(component.name=org.apache.sling.i18n.impl.JcrResourceBundleProvider)")
private ResourceBundleProvider resourceBundleProvider;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private GuideModuleImporter guideModuleImporter;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private XFAModelTransformer xfaModelTransformerService;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private GuideModelImporter guideModelImporterService;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private GuideModelTransformer guideModelTransformer;
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private AdaptiveFormConfigurationService adaptiveFormConfigurationService;
private static Set<String> blackListProp = new HashSet<String>(Arrays.asList("expJson", "cssStyle", "styleProperties", "cq:cssClass", "jcr:lastModified", "jcr:lastModifiedBy", "jcr:primaryType"));
private static final String ECMA_DATE_FORMAT = "EEE MMM dd yyyy HH:mm:ss 'GMT'Z";
private static final Locale DATE_FORMAT_LOCALE = Locale.US;
private static final DateFormat CALENDAR_FORMAT = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z", DATE_FORMAT_LOCALE);
public JSONObject create(Resource resource, int maxRecursionLevels, JSONCreationOptions jsonCreationOptions) throws JSONException {
JSONObject jsonObject = this.create(resource, 0, maxRecursionLevels, jsonCreationOptions, "");
return jsonObject;
}
public JSONObject createWithContext(Resource resource, int maxRecursionLevels, JSONCreationOptions jsonCreationOptions) {
JSONObject guideJson = null;
try {
guideJson = this.create(resource, maxRecursionLevels, jsonCreationOptions);
this.refineGuideJsonPostCreation(guideJson, resource);
}
catch (Exception e) {
log.error("Could not emit JSON with context", (Throwable)e);
}
return guideJson;
}
private void refineGuideJsonPostCreation(JSONObject guideJson, Resource resource) {
String xsdRootEl;
ArrayList<GuideJsonVisitor> visitors = new ArrayList<GuideJsonVisitor>();
JSONObject guideContainer = GuideUtils.getGuideContainer(guideJson);
if (guideContainer.has("xsdRef") && XMLUtils.isValidXsdRoot(xsdRootEl = this.fixXsdRootElementProperty(guideContainer, resource))) {
visitors.add(new AbsoluteBindrefResolver(xsdRootEl));
}
DuplicateBindrefsCollector duplicateBindrefsCollector = new DuplicateBindrefsCollector();
if (!this.adaptiveFormConfigurationService.getPreventLiveLinkingFields().booleanValue()) {
visitors.add(duplicateBindrefsCollector);
}
CrossFragFieldsCollector crossFragFieldsCollector = new CrossFragFieldsCollector();
visitors.add(crossFragFieldsCollector);
LazyPanelsCollector lazyPanelsCollector = new LazyPanelsCollector();
visitors.add(lazyPanelsCollector);
AssetRefCollector assetRefCollector = new AssetRefCollector();
visitors.add(assetRefCollector);
EmbeddedFormsXsdRootFixer embeddedFormsXsdRootFixer = new EmbeddedFormsXsdRootFixer(resource, this.guideModelTransformer);
visitors.add(embeddedFormsXsdRootFixer);
GuideJsonItemsTraverser guideJsonItemsTraverser = new GuideJsonItemsTraverser(guideContainer, visitors);
guideJsonItemsTraverser.traverse();
try {
guideContainer.put("repeatBindRef", duplicateBindrefsCollector.getDuplicatedBindRefs());
guideContainer.put("guideGlobalLazyField", (Object)crossFragFieldsCollector.getGlobals());
guideContainer.put("allLazyChildren", lazyPanelsCollector.getLazyTemplateIds());
guideContainer.put("assetRefs", assetRefCollector.getAssetRefs());
if (embeddedFormsXsdRootFixer.isHasEmbeddedForms()) {
guideContainer.put("hasEmbeddedForms", true);
if (embeddedFormsXsdRootFixer.isHasEmbeddedXsdForm()) {
guideContainer.put("isHasEmbeddedXsdForm", true);
}
}
}
catch (JSONException e) {
log.error("Failed to write properties in guideJson", (Throwable)e);
}
}
private String fixXsdRootElementProperty(JSONObject guideJson, Resource resource) {
String xsdRootEl = XMLUtils.extractXsdRootElement(guideJson);
if (!XMLUtils.isValidXsdRoot(xsdRootEl)) {
log.debug("Failed read XSD root element name property from node for XSD based form");
xsdRootEl = ((GuideModelImporterImpl)this.guideModelImporterService).getFirstXSDRootElementName(resource);
if (!XMLUtils.isValidXsdRoot(xsdRootEl)) {
log.debug("Failed to fetch XSD root element by parsing XSD schema");
xsdRootEl = "?";
}
try {
guideJson.put("xsdRootElement", (Object)xsdRootEl);
}
catch (JSONException e) {
log.error("Failed to add xsdRootElement property in Guide Json", (Throwable)e);
}
}
return XMLUtils.extractXsdRootElement(guideJson);
}
private JSONObject create(Resource resource, int currentRecursionLevel, int maxRecursionLevels, JSONCreationOptions jsonCreationOptions, String parentSOM) throws JSONException {
if (jsonCreationOptions == null) {
jsonCreationOptions = new JSONCreationOptions();
}
I18n i18n = jsonCreationOptions.getI18n();
ValueMap valueMap = (ValueMap)resource.adaptTo(ValueMap.class);
ValueMap propertyMap = valueMap != null ? valueMap : (Map)resource.adaptTo(Map.class);
JSONObject obj = new JSONObject();
String templateId = null;
if (propertyMap == null) {
String value = (String)resource.adaptTo(String.class);
if (value != null) {
obj.put(ResourceUtil.getName((Resource)resource), (Object)value);
} else {
String[] values = (String[])resource.adaptTo(String[].class);
if (values != null) {
obj.put(ResourceUtil.getName((Resource)resource), (Object)new JSONArray(Arrays.asList(values)));
}
}
} else if (jsonCreationOptions.getTransformer() != null) {
JSONObject tmpObj = jsonCreationOptions.getTransformer().transform(resource, parentSOM);
if (tmpObj == null) {
return null;
}
Iterator keys = tmpObj.keys();
while (keys.hasNext()) {
String key = (String)keys.next();
obj.put(key, tmpObj.get(key));
}
} else {
Iterator props = propertyMap.entrySet().iterator();
String resourceType = (String)propertyMap.get("sling:resourceType");
if (resource.getPath() != null && !"items".equals(resource.getName())) {
templateId = NodeStructureUtils.getGuideNodeHtmlId(resource);
if (templateId != null && templateId.length() > 0) {
obj.put("templateId", (Object)templateId);
obj.put("id", (Object)"");
}
if (jsonCreationOptions.isIncludeJcrPath()) {
obj.put("jcr:path", (Object)resource.getPath());
}
}
if (!"items".equals(resource.getName())) {
String effectiveBindRef;
String compName = null;
if (propertyMap.containsKey("guideNodeClass") && "guideSeparator".equals(compName = (String)propertyMap.get("guideNodeClass"))) {
return null;
}
while (props.hasNext()) {
Map.Entry prop = props.next();
String propName = prop.getKey().toString();
Object propValue = prop.getValue();
if (propValue instanceof String && compName != null && i18n != null && GuideSchema.isLocalizableProperty(compName, propName)) {
String translatedString = GuideUtils.translateOrReturnOriginal((String)propValue, i18n);
propValue = translatedString;
}
if (blackListProp.contains(propName)) continue;
JsonObjectCreatorImpl.createProperty(obj, valueMap, propName, propValue, i18n, resource);
}
String bindRef = JsonObjectCreatorImpl.handleMinMaxOccursAndBindRefForFragments((Map)propertyMap, obj);
String name = (String)propertyMap.get("name");
String string = effectiveBindRef = bindRef != null ? bindRef : name;
if (!StringUtils.isEmpty((CharSequence)compName) && propertyMap.containsKey("jcr:title")) {
String nonLocalizedTitle = (String)propertyMap.get("jcr:title");
JsonObjectCreatorImpl.createProperty(obj, valueMap, "nonLocalizedTitle", nonLocalizedTitle, null, resource);
}
String slingResourceType = jsonCreationOptions.getFormResourceProperty("sling:resourceType");
if (this.guideModuleImporter != null && !"fd/adaddon/components/guideDocumentContainer".equals(slingResourceType)) {
String resolvedHtml;
if (propertyMap.containsKey("assetRef")) {
resolvedHtml = "";
String assetRef = (String)propertyMap.get("assetRef");
if (!StringUtils.isEmpty((CharSequence)assetRef) && !StringUtils.isEmpty((CharSequence)compName)) {
if ("guideAdModule".equals(compName)) {
resolvedHtml = this.guideModuleImporter.getModuleResolution(assetRef, null);
} else if ("guideAdModuleGroup".equals(compName)) {
HashMap<String, Object> moduleParameter = new HashMap<String, Object>();
moduleParameter.put("letterRef", jsonCreationOptions.getFormResourceProperty("letterRef"));
resolvedHtml = this.guideModuleImporter.getModuleGroupResolution(assetRef, moduleParameter);
}
}
obj.put("_value", (Object)resolvedHtml);
} else if ("guideAdModuleGroup".equals(compName)) {
resolvedHtml = "";
Resource itemsResource = resource.getChild("items");
if (itemsResource != null) {
ArrayList<String> moduleAssetRefs = new ArrayList<String>();
for (Resource itemResource : itemsResource.getChildren()) {
ValueMap itemValueMap = ResourceUtil.getValueMap((Resource)itemResource);
String itemAssetRef = (String)itemValueMap.get("assetRef", (Object)"");
if (StringUtils.isEmpty((CharSequence)itemAssetRef)) continue;
moduleAssetRefs.add(itemAssetRef);
}
HashMap<String, Object> moduleParameter = new HashMap<String, Object>();
moduleParameter.put("moduleList", moduleAssetRefs);
resolvedHtml = this.guideModuleImporter.getModuleGroupResolution(null, moduleParameter);
}
obj.put("_value", (Object)resolvedHtml);
}
}
}
}
if (JsonObjectCreatorImpl.recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
Iterator children = ResourceUtil.listChildren((Resource)resource);
while (children.hasNext()) {
Resource n = (Resource)children.next();
if (obj.has("SOM")) {
parentSOM = obj.getString("SOM");
}
this.createSingleResource(n, obj, currentRecursionLevel, maxRecursionLevels, jsonCreationOptions, parentSOM);
}
}
return obj;
}
private static synchronized String format(Calendar date) {
return CALENDAR_FORMAT.format(date.getTime());
}
private static Object getValue(Object value) {
if (value instanceof InputStream) {
return 0;
}
if (value instanceof Calendar) {
return JsonObjectCreatorImpl.format((Calendar)value);
}
if (value instanceof Boolean) {
return value;
}
if (value instanceof Long) {
return value;
}
if (value instanceof Integer) {
return value;
}
if (value instanceof Double) {
return value;
}
return value.toString();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled force condition propagation
* Lifted jumps to return sites
*/
private void createSingleResource(Resource n, JSONObject parent, int currentRecursionLevel, int maxRecursionLevels, JSONCreationOptions jsonCreationOptions, String parentSOM) throws JSONException {
if (!JsonObjectCreatorImpl.recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) return;
JSONObject obj = null;
Map propertyMap = (Map)n.adaptTo(ValueMap.class);
String fragRef = (String)propertyMap.get("fragRef");
if (fragRef != null && fragRef.length() > 0) {
String fragRefContainerPath = GuideUtils.convertFMAssetPathToContainerPath(fragRef);
Resource fragRefContainerResource = n.getResourceResolver().getResource(fragRefContainerPath);
Resource fragRootPanel = null;
if (fragRefContainerResource != null) {
fragRootPanel = GuideUtils.getRootPanel(fragRefContainerResource);
} else {
log.warn("The fragment at specified path " + fragRef + " is not available.");
}
String previousPrefixId = null;
String fragmentModelRootPrevious = null;
String bindPrefixForFragment = null;
String bindPrefixForFragmentPrevious = null;
String prevGuideContainerPath = null;
I18n i18nPrevious = null;
try {
String fragmentModelRoot;
GuideFragmentHolder guideFragmentHolderPrev = GuideContainerThreadLocal.getGuideFragmentHolder();
prevGuideContainerPath = GuideContainerThreadLocal.getGuideContainerPath();
if (guideFragmentHolderPrev != null) {
previousPrefixId = guideFragmentHolderPrev.getFragPrefixID();
bindPrefixForFragmentPrevious = guideFragmentHolderPrev.getBindRefPrefixForFragment();
fragmentModelRootPrevious = guideFragmentHolderPrev.getFragmentModelRoot();
i18nPrevious = guideFragmentHolderPrev.getI18n();
}
String currentPrefixId = NodeStructureUtils.getFragPrefixString(n, previousPrefixId);
obj = this.create(n, currentRecursionLevel + 1, maxRecursionLevels, jsonCreationOptions, parentSOM);
parent.put(ResourceUtil.getName((Resource)n), (Object)obj);
if (fragRefContainerResource == null) return;
ValueMap containerValueMap = ResourceUtil.getValueMap((Resource)fragRefContainerResource);
if (obj != null && obj.has("bindRef")) {
bindPrefixForFragment = (String)obj.get("bindRef");
}
if (StringUtils.isBlank((CharSequence)(fragmentModelRoot = (String)containerValueMap.get("xsdRootElement", containerValueMap.get("fragmentModelRoot", (Object)""))))) {
Map<String, String> mapOfNameAndFragmentModelRoot;
if (containerValueMap.containsKey((Object)"xdpRef") && (mapOfNameAndFragmentModelRoot = this.xfaModelTransformerService.getXDPFramgmentRootSubform((String)containerValueMap.get((Object)"xdpRef"))) != null) {
fragmentModelRoot = mapOfNameAndFragmentModelRoot.get("fragmentModelRoot");
}
} else if (!StringUtils.startsWith((CharSequence)fragmentModelRoot, (CharSequence)"/") && !StringUtils.startsWith((CharSequence)fragmentModelRoot, (CharSequence)"xfa[0].form[0]")) {
fragmentModelRoot = "/" + fragmentModelRoot;
}
I18n i18nForFragment = GuideELUtils.getI18n(this.resourceBundleProvider, fragRefContainerResource, jsonCreationOptions.getLocale());
GuideContainerThreadLocal.setGuideFragmentHolder(currentPrefixId, bindPrefixForFragment, fragmentModelRoot, i18nForFragment);
GuideContainerThreadLocal.setGuideContainerPath(fragRefContainerResource.getPath());
boolean includeFragmentJson = false;
if (jsonCreationOptions != null) {
includeFragmentJson = jsonCreationOptions.isIncludeFragmentJson();
}
if (!includeFragmentJson) return;
JSONCreationOptions jsonCreationOptionsWithFragmentI18n = new JSONCreationOptions(i18nForFragment, jsonCreationOptions.isIncludeJcrPath(), jsonCreationOptions.isIncludeFragmentJson(), jsonCreationOptions.getLocale(), jsonCreationOptions.getFormResource());
jsonCreationOptionsWithFragmentI18n.setTransformer(jsonCreationOptions.getTransformer());
JSONObject itemsNode = new JSONObject();
obj.put("items", (Object)itemsNode);
String currentParentSOM = parentSOM;
if (obj.has("SOM")) {
currentParentSOM = obj.getString("SOM");
}
for (Resource childOfRoot : fragRootPanel.getChild("items").getChildren()) {
if (((ValueMap)childOfRoot.adaptTo(ValueMap.class)).get((Object)"fragRef") != null) {
this.createSingleResource(childOfRoot, itemsNode, currentRecursionLevel, maxRecursionLevels, jsonCreationOptionsWithFragmentI18n, currentParentSOM);
continue;
}
itemsNode.put(childOfRoot.getName(), (Object)this.create(childOfRoot, currentRecursionLevel + 1, maxRecursionLevels, jsonCreationOptionsWithFragmentI18n, currentParentSOM));
}
return;
}
catch (Exception e) {
log.error("Error while clearing thread local in JsonObjectCreator", (Throwable)e);
}
finally {
GuideContainerThreadLocal.setGuideContainerPath(prevGuideContainerPath);
GuideContainerThreadLocal.setGuideFragmentHolder(previousPrefixId, bindPrefixForFragmentPrevious, fragmentModelRootPrevious, i18nPrevious);
}
return;
} else {
obj = this.create(n, currentRecursionLevel + 1, maxRecursionLevels, jsonCreationOptions, parentSOM);
if (obj == null) return;
parent.put(ResourceUtil.getName((Resource)n), (Object)obj);
}
}
private static boolean recursionLevelActive(int currentRecursionLevel, int maxRecursionLevels) {
return maxRecursionLevels < 0 || currentRecursionLevel < maxRecursionLevels;
}
private static void createProperty(JSONObject obj, ValueMap valueMap, String key, Object value, I18n i18n, Resource resource) throws JSONException {
Object[] values = null;
if (value.getClass().isArray() && (values = (Object[])value).length == 0) {
obj.put(key, (Object)new JSONArray());
return;
}
if (value instanceof InputStream || values != null && values[0] instanceof InputStream) {
if (values == null) {
obj.put(":" + key, JsonObjectCreatorImpl.getLength(valueMap, -1, key, (InputStream)value));
} else {
JSONArray result = new JSONArray();
for (int i = 0; i < values.length; ++i) {
result.put(JsonObjectCreatorImpl.getLength(valueMap, i, key, (InputStream)values[i]));
}
obj.put(":" + key, (Object)result);
}
return;
}
if (!value.getClass().isArray()) {
Resource optionPath;
boolean isGuideOptionsListPath;
JSONArray result;
Object[] optionsArray;
obj.put(key, JsonObjectCreatorImpl.getValue(value));
boolean bl = isGuideOptionsListPath = valueMap.containsKey((Object)"guideNodeClass") && "optionsLoadPath".equals(key);
if (isGuideOptionsListPath && (optionPath = resource.getResourceResolver().getResource((String)JsonObjectCreatorImpl.getValue(value))) != null && (result = JsonObjectCreatorImpl.getItemsJSONFromList(optionsArray = (String[])optionPath.adaptTo(String[].class), i18n, true)) != null) {
obj.put("options", (Object)result);
}
} else {
JSONArray result;
boolean isGuideOptions;
boolean bl = isGuideOptions = valueMap.containsKey((Object)"guideNodeClass") && "options".equals(key);
if (isGuideOptions && !obj.has("options")) {
JSONArray result2 = JsonObjectCreatorImpl.getItemsJSONFromList(values, i18n, true);
if (result2 != null) {
obj.put(key, (Object)result2);
}
} else if (!isGuideOptions && (result = JsonObjectCreatorImpl.getItemsJSONFromList(values, i18n, false)) != null) {
obj.put(key, (Object)result);
}
}
}
private static JSONArray getItemsJSONFromList(Object[] values, I18n i18n, boolean isGuideOptions) {
if (values == null) {
return null;
}
JSONArray result = new JSONArray();
for (Object v : values) {
String[] valueStringArray;
boolean optionAdded = false;
if (isGuideOptions && (valueStringArray = v.toString().split("=")).length > 1) {
String keyString = valueStringArray[0];
String valueString = valueStringArray[1];
String translatedString = GuideUtils.translateOrReturnOriginal(valueString, i18n);
result.put((Object)(StringUtils.trimToEmpty((String)keyString) + "=" + StringUtils.trimToEmpty((String)translatedString)));
optionAdded = true;
}
if (optionAdded) continue;
Object value = JsonObjectCreatorImpl.getValue(v);
if (value instanceof String) {
String valueString = value.toString();
String translatedString = GuideUtils.translateOrReturnOriginal(valueString, i18n);
result.put((Object)translatedString);
continue;
}
result.put(value);
}
return result;
}
private static long getLength(ValueMap valueMap, int index, String key, InputStream stream) {
try {
stream.close();
}
catch (IOException ignore) {
log.trace("Error in getLength, ignoring it." + ignore.getMessage(), (Throwable)ignore);
}
long length = -1;
if (valueMap != null) {
if (index == -1) {
length = (Long)valueMap.get(key, (Object)length);
} else {
Long[] lengths = (Long[])valueMap.get(key, Long[].class);
if (lengths != null && lengths.length > index) {
length = lengths[index];
}
}
}
return length;
}
private static String handleMinMaxOccursAndBindRefForFragments(Map propertyMap, JSONObject obj) {
String oldBindRef = null;
String newBindRef = null;
if (propertyMap.containsKey("bindRef")) {
oldBindRef = (String)propertyMap.get("bindRef");
}
try {
newBindRef = JsonObjectCreatorImpl.handleBindRefForFragments(propertyMap);
obj.put("bindRef", (Object)newBindRef);
if (StringUtils.isNotEmpty((CharSequence)oldBindRef) && StringUtils.isEmpty((CharSequence)newBindRef)) {
obj.put("minOccur", 1);
obj.put("maxOccur", 1);
}
}
catch (Exception e) {
log.error("Exception while handling bindRef or Min Max for " + obj.toString(), (Throwable)e);
}
return newBindRef;
}
private static String handleBindRefForFragments(Map propertyMap) {
String bindRef = null;
if (propertyMap.containsKey("bindRef")) {
bindRef = (String)propertyMap.get("bindRef");
GuideFragmentHolder guideFragmentHolder = null;
try {
guideFragmentHolder = GuideContainerThreadLocal.getGuideFragmentHolder();
}
catch (Exception e) {
log.error("Error while getting bind prefix map ", (Throwable)e);
}
if (guideFragmentHolder != null) {
String bindRefPrefixForFragment = guideFragmentHolder.getBindRefPrefixForFragment();
String fragmentRoot = guideFragmentHolder.getFragmentModelRoot();
return GuideUtils.manipulateBindRefForFragments(bindRefPrefixForFragment, bindRef, fragmentRoot);
}
}
return bindRef;
}
protected void bindResourceBundleProvider(ResourceBundleProvider resourceBundleProvider) {
this.resourceBundleProvider = resourceBundleProvider;
}
protected void unbindResourceBundleProvider(ResourceBundleProvider resourceBundleProvider) {
if (this.resourceBundleProvider == resourceBundleProvider) {
this.resourceBundleProvider = null;
}
}
protected void bindGuideModuleImporter(GuideModuleImporter guideModuleImporter) {
this.guideModuleImporter = guideModuleImporter;
}
protected void unbindGuideModuleImporter(GuideModuleImporter guideModuleImporter) {
if (this.guideModuleImporter == guideModuleImporter) {
this.guideModuleImporter = null;
}
}
protected void bindXfaModelTransformerService(XFAModelTransformer xFAModelTransformer) {
this.xfaModelTransformerService = xFAModelTransformer;
}
protected void unbindXfaModelTransformerService(XFAModelTransformer xFAModelTransformer) {
if (this.xfaModelTransformerService == xFAModelTransformer) {
this.xfaModelTransformerService = null;
}
}
protected void bindGuideModelImporterService(GuideModelImporter guideModelImporter) {
this.guideModelImporterService = guideModelImporter;
}
protected void unbindGuideModelImporterService(GuideModelImporter guideModelImporter) {
if (this.guideModelImporterService == guideModelImporter) {
this.guideModelImporterService = null;
}
}
protected void bindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
this.guideModelTransformer = guideModelTransformer;
}
protected void unbindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
if (this.guideModelTransformer == guideModelTransformer) {
this.guideModelTransformer = null;
}
}
protected void bindAdaptiveFormConfigurationService(AdaptiveFormConfigurationService adaptiveFormConfigurationService) {
this.adaptiveFormConfigurationService = adaptiveFormConfigurationService;
}
protected void unbindAdaptiveFormConfigurationService(AdaptiveFormConfigurationService adaptiveFormConfigurationService) {
if (this.adaptiveFormConfigurationService == adaptiveFormConfigurationService) {
this.adaptiveFormConfigurationService = null;
}
}
}