NonInteractivePDFRenderService.java
6.49 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.forms.option.LCFormsOptions
* com.adobe.forms.service.AEMFormsHelperService
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
*/
package com.adobe.fd.output.internal;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.forms.internal.utils.Utils;
import com.adobe.fd.output.api.BatchOptions;
import com.adobe.fd.output.api.BatchResult;
import com.adobe.fd.output.internal.XFABatchForPrintService;
import com.adobe.fd.output.internal.XFAPAExecuteService;
import com.adobe.fd.output.internal.utils.DebugDumper;
import com.adobe.forms.option.LCFormsOptions;
import com.adobe.forms.service.AEMFormsHelperService;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
@Component(label="NonInteractive PDF Render Service", description="renders flat pdf from XDP")
@Service(value={NonInteractivePDFRenderService.class})
public class NonInteractivePDFRenderService {
@Reference
AEMFormsHelperService aemFormsHelperService;
@Reference
XFAPAExecuteService xfapaExecuteService;
@Reference
XFABatchForPrintService xfaNativeBatchService;
public Document render(byte[] template, Document data, LCFormsOptions lcOptions, String imageResources, boolean signablePDF, boolean retainFormState) throws Exception {
String[] renderRequestType = lcOptions.getRenderType().split("\\.");
String renderType = renderRequestType[renderRequestType.length - 1];
byte[] xciBytes = this.aemFormsHelperService.xciString(lcOptions, renderType).getBytes("utf-8");
byte[] userXci = this.aemFormsHelperService.userXCI(lcOptions);
DebugDumper dd = new DebugDumper(lcOptions.getDebugDir());
dd.dump("template.xml", template);
dd.dump("data.xml", data);
dd.dump("xci.xml", xciBytes);
dd.dump("user_xci.xml", userXci);
dd.dump("resources.xml", imageResources.getBytes());
List<byte[]> ret = this.xfapaExecuteService.paExecute(template, retainFormState ? template : Utils.getBytes(data), xciBytes, new byte[0], retainFormState, true, userXci, imageResources.getBytes(), signablePDF, false);
dd.dump("procInfo.xml", ret.get(0));
dd.dump("output." + renderType, ret.get(1));
return new Document(ret.get(1));
}
public BatchResult renderBatch(Map<String, String> templates, Map<String, Document> data, LCFormsOptions lcOptions, BatchOptions options) throws Exception {
LinkedHashMap<String, byte[]> resolveTemplateMap = new LinkedHashMap<String, byte[]>();
String[] renderRequestType = lcOptions.getRenderType().split("\\.");
String renderType = renderRequestType[renderRequestType.length - 1];
LinkedHashMap<String, Document> dataMap = new LinkedHashMap<String, Document>();
DebugDumper dd = new DebugDumper(lcOptions.getDebugDir());
int dataCounter = 0;
int templateCounter = 0;
for (Map.Entry<String, String> entry : templates.entrySet()) {
lcOptions.setTemplate(entry.getValue());
byte[] resolvedTemplate = this.aemFormsHelperService.resolvedTemplate(lcOptions);
resolveTemplateMap.put(entry.getKey(), resolvedTemplate);
dd.dump("template_" + entry.getKey() + "_" + templateCounter + ".xml", resolvedTemplate);
if (data.get(entry.getKey()) != null) {
Document dataDoc = data.get(entry.getKey());
dataMap.put(entry.getKey(), dataDoc);
dd.dump("data_" + entry.getKey() + "_" + dataCounter + ".xml", dataDoc);
++dataCounter;
}
++templateCounter;
}
byte[] xciBytes = this.aemFormsHelperService.xciString(lcOptions, renderType).replace("<record></record>", "<record>2</record>").getBytes("utf-8");
byte[] userXci = this.aemFormsHelperService.userXCI(lcOptions);
dd.dump("xci.xml", xciBytes);
dd.dump("user_xci.xml", userXci);
Map<String, Object> ret = this.xfaNativeBatchService.renderBatchForPrint(resolveTemplateMap, dataMap, xciBytes, options.getGenerateManyFiles(), renderType, userXci, new byte[0]);
BatchResult br = this.toBatchResult(ret);
if (br.getGeneratedDocs() != null && br.getGeneratedDocs().size() > 0) {
for (int i = 0; i < br.getGeneratedDocs().size(); ++i) {
Document genDoc = br.getGeneratedDocs().get(i);
dd.dump("output_" + i + "." + renderType, genDoc);
}
}
if (br.getMetaDataDoc() != null) {
dd.dump("metadata.xml", br.getMetaDataDoc());
}
return br;
}
private BatchResult toBatchResult(Map map) {
BatchResult br = new BatchResult();
Object output_list = null;
if (map.get("metadata") != null) {
Document metadataDocument = (Document)map.get("metadata");
br.setMetaDataDoc(metadataDocument);
}
if (map.get("batch_output") != null) {
List outputDocumentList = (List)map.get("batch_output");
br.setGeneratedDocs(outputDocumentList);
}
return br;
}
protected void bindAemFormsHelperService(AEMFormsHelperService aEMFormsHelperService) {
this.aemFormsHelperService = aEMFormsHelperService;
}
protected void unbindAemFormsHelperService(AEMFormsHelperService aEMFormsHelperService) {
if (this.aemFormsHelperService == aEMFormsHelperService) {
this.aemFormsHelperService = null;
}
}
protected void bindXfapaExecuteService(XFAPAExecuteService xFAPAExecuteService) {
this.xfapaExecuteService = xFAPAExecuteService;
}
protected void unbindXfapaExecuteService(XFAPAExecuteService xFAPAExecuteService) {
if (this.xfapaExecuteService == xFAPAExecuteService) {
this.xfapaExecuteService = null;
}
}
protected void bindXfaNativeBatchService(XFABatchForPrintService xFABatchForPrintService) {
this.xfaNativeBatchService = xFABatchForPrintService;
}
protected void unbindXfaNativeBatchService(XFABatchForPrintService xFABatchForPrintService) {
if (this.xfaNativeBatchService == xFABatchForPrintService) {
this.xfaNativeBatchService = null;
}
}
}