LetterJSONModelServlet.java
4.63 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.icc.dbforms.obj.Letter
* com.adobe.icc.dbforms.obj.LetterRenderOptionsSpec
* com.adobe.icc.ddg.api.LetterRenderService
* com.adobe.icc.render.obj.PDFResponseType
* com.adobe.icc.services.api.LetterService
* javax.servlet.ServletException
* org.apache.commons.lang3.StringUtils
* 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.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.adaddon.internal.servlet;
import com.adobe.fd.adaddon.internal.utils.LetterToJsonTransformer;
import com.adobe.icc.dbforms.obj.Letter;
import com.adobe.icc.dbforms.obj.LetterRenderOptionsSpec;
import com.adobe.icc.ddg.api.LetterRenderService;
import com.adobe.icc.render.obj.PDFResponseType;
import com.adobe.icc.services.api.LetterService;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringUtils;
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.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.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(label="Letter Model Servlet", description="Letter Model Servlet")
@Service
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"fd/adaddon/components/guideDocumentContainer"}), @Property(name="sling.servlet.extensions", value={"lettermodeljson"})})
public class LetterJSONModelServlet
extends SlingAllMethodsServlet {
private static final Logger log = LoggerFactory.getLogger(LetterJSONModelServlet.class);
@Reference
LetterService letterService;
@Reference
LetterRenderService letterRenderService;
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException {
ValueMap vm;
String letterRef = null;
Resource guideContainer = request.getResource();
if (guideContainer != null && (vm = (ValueMap)guideContainer.adaptTo(ValueMap.class)) != null) {
letterRef = (String)vm.get((Object)"letterRef");
}
if (StringUtils.isBlank((CharSequence)letterRef)) {
log.error("letterRef param is blank or is not provided");
throw new ServletException("letterRef param is blank or is not provided, letterRef : " + letterRef);
}
Letter letter = this.letterService.getLetter(letterRef);
LetterRenderOptionsSpec lros = new LetterRenderOptionsSpec();
lros.setMergeDataOnServer(false);
lros.setUseXFABullets(false);
PDFResponseType pdfResponseType = this.letterRenderService.renderLetter(letter, null, lros);
HashMap taFieldOrderMap = pdfResponseType.getTaFieldOrderMap();
if (taFieldOrderMap == null) {
log.error(" taFieldOrderMap is null " + taFieldOrderMap);
taFieldOrderMap = new HashMap();
}
LetterToJsonTransformer jsonGenerator = new LetterToJsonTransformer(letter, taFieldOrderMap);
String jsonString = jsonGenerator.getJsonString();
response.setContentType("application/json");
response.getWriter().write(jsonString);
}
protected void bindLetterService(LetterService letterService) {
this.letterService = letterService;
}
protected void unbindLetterService(LetterService letterService) {
if (this.letterService == letterService) {
this.letterService = null;
}
}
protected void bindLetterRenderService(LetterRenderService letterRenderService) {
this.letterRenderService = letterRenderService;
}
protected void unbindLetterRenderService(LetterRenderService letterRenderService) {
if (this.letterRenderService == letterRenderService) {
this.letterRenderService = null;
}
}
}