OptimizePdfProcess.java
3.67 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.metadata.MetaDataMap
* com.adobe.pdfg.result.OptimizePDFResult
* com.adobe.pdfg.service.api.GeneratePDFService
* 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.pdfg;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
import com.adobe.fd.workflow.utils.DocumentUtils;
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 com.adobe.pdfg.result.OptimizePDFResult;
import com.adobe.pdfg.service.api.GeneratePDFService;
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={"OptimizePdfProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"OptimizePdfProcess"})})
public class OptimizePdfProcess
extends AEMFDWorkflowProcess {
private static Logger LOGGER = LoggerFactory.getLogger(OptimizePdfProcess.class);
private static final String INDOC_PARAM = "inDoc";
private static final String FILETYPE_SETTINGS_PARAM = "filetypeSettings";
private static final String SETTINGS_DOC_PARAM = "settingsDoc";
private static final String OUT_DOC_PARAM = "outDoc";
@Reference
GeneratePDFService generatePdfService;
@Override
protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
try {
OptimizePDFResult result;
Document inputDoc = DocumentUtils.getInputDocument(workItem, "inDoc");
String fileTypeSettings = null;
Document settingsDoc = null;
if (metaDataMap.get("filetypeSettings", String.class) != null) {
fileTypeSettings = (String)metaDataMap.get("filetypeSettings", String.class);
LOGGER.debug("filetypeSettings= " + fileTypeSettings);
}
if (metaDataMap.get("settingsDoc", Document.class) != null) {
settingsDoc = (Document)metaDataMap.get("settingsDoc", Document.class);
}
if ((result = this.generatePdfService.optimizePDF(inputDoc, fileTypeSettings, settingsDoc)) != null && result.getConvertedDocument() != null) {
DocumentUtils.saveOutputDocument(workItem, workflowSession, "outDoc", result.getConvertedDocument());
}
}
catch (Exception e) {
throw new WorkflowException((Throwable)e);
}
}
protected void bindGeneratePdfService(GeneratePDFService generatePDFService) {
this.generatePdfService = generatePDFService;
}
protected void unbindGeneratePdfService(GeneratePDFService generatePDFService) {
if (this.generatePdfService == generatePDFService) {
this.generatePdfService = null;
}
}
}