EmbeddedFormsXsdRootFixer.java
2.59 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.utils.guideJson;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.guideJson.GuideJsonVisitor;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EmbeddedFormsXsdRootFixer
implements GuideJsonVisitor {
private static final Logger log = LoggerFactory.getLogger(EmbeddedFormsXsdRootFixer.class);
private final Resource resource;
private final GuideModelTransformer guideModelTransformer;
private boolean hasEmbeddedForms = false;
private boolean isHasEmbeddedXsdForm = false;
public EmbeddedFormsXsdRootFixer(Resource resource, GuideModelTransformer guideModelTransformer) {
this.resource = resource;
this.guideModelTransformer = guideModelTransformer;
}
public void visitItem(JSONObject panel) {
try {
if (panel.optBoolean("isForm")) {
this.hasEmbeddedForms = true;
String fragRef = panel.optString("fragRef");
Resource formResource = GuideUtils.getFormResource(this.resource, fragRef);
JSONObject formJson = GuideUtils.getFormJson(formResource, this.guideModelTransformer);
if (formJson != null && StringUtils.isNotBlank((CharSequence)formJson.optString("xsdRef"))) {
this.isHasEmbeddedXsdForm = true;
String childXsdRootEl = formJson.optString("xsdRootElement");
panel.put("xsdRootElement", (Object)childXsdRootEl);
}
}
}
catch (JSONException e) {
log.error("Failed to handle embedded form Json", (Throwable)e);
}
catch (Exception e) {
log.error("Failed to fetch/modify embedded form Json", (Throwable)e);
}
}
public boolean isHasEmbeddedForms() {
return this.hasEmbeddedForms;
}
public boolean isHasEmbeddedXsdForm() {
return this.isHasEmbeddedXsdForm;
}
public void preRecurse(JSONObject obj) {
}
public void postRecurse(JSONObject obj) {
}
}