GuideInternalSubmitServlet.java
7.6 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.i18n.I18n
* javax.servlet.Servlet
* javax.servlet.ServletException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* 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.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.servlet;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.service.XFAModelTransformer;
import com.adobe.aemds.guide.taglibs.GuideELUtils;
import com.adobe.aemds.guide.utils.SubmitDataCollector;
import com.adobe.aemds.guide.utils.XsdSubmitDataCollector;
import com.day.cq.i18n.I18n;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
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.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={Servlet.class})
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"fd/af/components/guideContainer"}), @Property(name="sling.servlet.methods", value={"POST"}), @Property(name="service.description", value={"Adaptive Form Internal Submit"}), @Property(name="sling.servlet.selectors", value={"af.internalsubmit"})})
public class GuideInternalSubmitServlet
extends SlingAllMethodsServlet {
private Logger logger = LoggerFactory.getLogger(GuideInternalSubmitServlet.class);
@Reference(policy=ReferencePolicy.DYNAMIC, cardinality=ReferenceCardinality.OPTIONAL_UNARY)
private XFAModelTransformer xfaModelTransformerService;
@Reference
private GuideModelTransformer guideModelTransformer;
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
I18n i18n = GuideELUtils.getI18n(request, request.getResource());
String guideState = request.getParameter("guideState");
String xdpRef = null;
String xsdRef = null;
String guidePrefillXml = null;
java.lang.Object dorTemplateRef = null;
String submissionInfo = null;
java.lang.Object computedData = null;
boolean isLazyXml = false;
try {
JSONObject templateJson = this.guideModelTransformer.exportGuideJsonObject(request.getResource(), i18n);
JSONObject jsonObject = new JSONObject(guideState);
JSONObject guide = new JSONObject(jsonObject.getString("guideState"));
JSONObject guideJson = null;
String guideDom = null;
if (guide.has("guideDom")) {
guideDom = guide.getString("guideDom");
guideJson = new JSONObject(guideDom);
}
if (guide.has("guideContext")) {
JSONObject guideContext = new JSONObject(guide.getString("guideContext"));
if (guideContext.has("xdpRef")) {
xdpRef = guideContext.getString("xdpRef");
}
if (guideContext.has("xsdRef")) {
xsdRef = guideContext.getString("xsdRef");
}
if (guideContext.has("guidePrefillXml")) {
guidePrefillXml = guideContext.getString("guidePrefillXml");
}
if (guideContext.has("afSubmissionInfo")) {
submissionInfo = guideContext.getString("afSubmissionInfo");
}
}
if (guide.has("guideLiveXml")) {
guidePrefillXml = guide.getString("guideLiveXml");
isLazyXml = true;
}
SubmitDataCollector submitDataCollector = null;
boolean hasEmbeddedXsdForms = templateJson.optBoolean("isHasEmbeddedXsdForm");
if (xsdRef != null || xdpRef == null && hasEmbeddedXsdForms) {
submitDataCollector = new XsdSubmitDataCollector(guideDom, templateJson, guidePrefillXml, submissionInfo, isLazyXml);
} else {
String xfaResult = "";
if (xdpRef != null && guide.has("xfaState")) {
JSONObject xfaState = guide.getJSONObject("xfaState");
String xfaDom = "";
String xfaPrefillXml = "";
if (xfaState.has("xfaDom")) {
xfaDom = xfaState.getString("xfaDom");
}
if (xfaState.has("renderContext")) {
JSONObject xfaRenderContext = new JSONObject(xfaState.getString("renderContext"));
String string = xfaPrefillXml = xfaRenderContext.has("data") ? xfaRenderContext.getString("data") : null;
if (guidePrefillXml == null) {
guidePrefillXml = xfaPrefillXml;
}
}
try {
xfaResult = this.xfaModelTransformerService.getDataXMLFromXfaDom(guideJson.getString("xdpRef"), xfaDom, xfaPrefillXml);
}
catch (Exception e) {
xfaResult = null;
this.logger.info("AF: Unable to getDataXML from XFA DOM. Setting it to null", (Throwable)e);
}
}
submitDataCollector = new SubmitDataCollector(guideDom, templateJson, guidePrefillXml, xfaResult, submissionInfo, isLazyXml);
}
JSONObject submitData = submitDataCollector.collectSubmitData();
PrintWriter out = response.getWriter();
out.write(submitData.toString());
}
catch (Exception e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException(e);
}
}
protected void bindXfaModelTransformerService(XFAModelTransformer xFAModelTransformer) {
this.xfaModelTransformerService = xFAModelTransformer;
}
protected void unbindXfaModelTransformerService(XFAModelTransformer xFAModelTransformer) {
if (this.xfaModelTransformerService == xFAModelTransformer) {
this.xfaModelTransformerService = null;
}
}
protected void bindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
this.guideModelTransformer = guideModelTransformer;
}
protected void unbindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
if (this.guideModelTransformer == guideModelTransformer) {
this.guideModelTransformer = null;
}
}
}