GeneratePDFOutputProcess.java
4.99 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.fd.output.api.AcrobatVersion
* com.adobe.fd.output.api.OutputService
* com.adobe.fd.output.api.PDFOutputOptions
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.metadata.MetaDataMap
* 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.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.workflow.output.impl;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.output.api.AcrobatVersion;
import com.adobe.fd.output.api.OutputService;
import com.adobe.fd.output.api.PDFOutputOptions;
import com.adobe.fd.workflow.forms.internal.common.FormsUtil;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
@Properties(value={@Property(name="service.description", value={"GeneratePDFOutputProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"GeneratePDFOutputProcess"})})
public class GeneratePDFOutputProcess
extends AEMFDWorkflowProcess {
private static Logger logger = LoggerFactory.getLogger(GeneratePDFOutputProcess.class);
private static final String TEMPLATE_PARAM = "urlOrFileName";
private static final String DATA_PARAM = "data";
private static final String CONTENT_ROOT_PARAM = "contentroot";
private static final String LINEARIZED_PARAM = "linearized";
private static final String LOCALE_PARAM = "locale";
private static final String ACROBAT_VERSION_PARAM = "acrobatversion";
private static final String TAGGED_PARAM = "tagged";
private static final String XCI_PARAM = "xci";
private static final String OUTPUT_PARAM = "outputpdf";
@Reference
OutputService outputService;
@Override
protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
try {
String template = FormsUtil.getAbsolutePath(workItem, workflowSession, "urlOrFileName");
Document dataDoc = FormsUtil.getDocument(workItem, "data");
PDFOutputOptions options = this.createPDFOutputOptions(workItem, workflowSession, metaDataMap);
Document document = this.outputService.generatePDFOutput(template, dataDoc, options);
FormsUtil.saveDocument(workItem, workflowSession, document, "outputpdf");
}
catch (Exception e) {
throw new WorkflowException((Throwable)e);
}
}
private PDFOutputOptions createPDFOutputOptions(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
PDFOutputOptions options = new PDFOutputOptions();
options.setContentRoot(FormsUtil.getAbsolutePath(workItem, workflowSession, "contentroot"));
if (metaDataMap.get("tagged", Boolean.class) != null) {
logger.debug("tagged=" + metaDataMap.get("tagged", Boolean.class));
options.setTaggedPDF(((Boolean)metaDataMap.get("tagged", Boolean.class)).booleanValue());
}
if (metaDataMap.get("linearized", Boolean.class) != null) {
logger.debug("linearized=" + metaDataMap.get("linearized", Boolean.class));
options.setLinearizedPDF(((Boolean)metaDataMap.get("linearized", Boolean.class)).booleanValue());
}
if (metaDataMap.get("locale", String.class) != null) {
logger.debug("locale=" + (String)metaDataMap.get("locale", String.class));
options.setLocale((String)metaDataMap.get("locale", String.class));
}
String acrobatVersion = (String)metaDataMap.get("acrobatversion", String.class);
logger.debug("acrobatversion=" + acrobatVersion);
if (acrobatVersion != null) {
options.setAcrobatVersion(AcrobatVersion.valueOf((String)acrobatVersion));
}
options.setXci(FormsUtil.getDocument(workItem, "xci"));
return options;
}
protected void bindOutputService(OutputService outputService) {
this.outputService = outputService;
}
protected void unbindOutputService(OutputService outputService) {
if (this.outputService == outputService) {
this.outputService = null;
}
}
}