ConvertToPDFAProcess.java
7.82 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.fd.assembler.client.PDFAConversionOptionSpec
* com.adobe.fd.assembler.client.PDFAConversionOptionSpec$ColorSpace
* com.adobe.fd.assembler.client.PDFAConversionOptionSpec$Compliance
* com.adobe.fd.assembler.client.PDFAConversionOptionSpec$OptionalContent
* com.adobe.fd.assembler.client.PDFAConversionOptionSpec$ResultLevel
* com.adobe.fd.assembler.client.PDFAConversionOptionSpec$Signatures
* com.adobe.fd.assembler.client.PDFAConversionResult
* com.adobe.fd.assembler.service.AssemblerService
* 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.assembler;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.assembler.client.PDFAConversionOptionSpec;
import com.adobe.fd.assembler.client.PDFAConversionResult;
import com.adobe.fd.assembler.service.AssemblerService;
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 java.util.Collections;
import java.util.List;
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={"ConvertToPDFAProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"ConvertToPDFAProcess"})})
public class ConvertToPDFAProcess
extends AEMFDWorkflowProcess {
private static Logger LOGGER = LoggerFactory.getLogger(ConvertToPDFAProcess.class);
private static final String INDOC_PARAM = "inDoc";
private static final String PDFADOC_PARAM = "pdfaDoc";
private static final String CONVERSION_LOG_PARAM = "conversionLog";
private static final String COMPLIANCE_PARAM = "compliance";
private static final String RESULT_LEVEL_PARAM = "resultLevel";
private static final String SIGNATURES_PARAM = "signatures";
private static final String COLOR_SPACE_PARAM = "colorspace";
private static final String OPTIONAL_CONTENT_PARAM = "optionalContent";
private static final String VERIFY_CONVERSION_PARAM = "verifyConversion";
private static final String LOG_LEVEL_PARAM = "logLevelParam";
private static final String METDATA_EXTENSION_SCHEMA_PARAM = "metadataExtensionSchema";
@Reference
AssemblerService assemblerService;
@Override
protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
try {
Document inDoc = DocumentUtils.getInputDocument(workItem, "inDoc");
PDFAConversionOptionSpec conversionOptions = this.createPDFAConversionOptions(workItem, workflowSession, metaDataMap);
PDFAConversionResult conversionResult = this.assemblerService.toPDFA(inDoc, conversionOptions);
if (!conversionResult.isPDFA()) {
LOGGER.info("Conversion to PDFA unsuccessfull");
} else {
LOGGER.info("Conversion to PDFA successfull");
}
DocumentUtils.saveOutputDocument(workItem, workflowSession, "pdfaDoc", conversionResult.getPDFADocument());
DocumentUtils.saveOutputDocument(workItem, workflowSession, "conversionLog", conversionResult.getConversionLog());
}
catch (Exception e) {
throw new WorkflowException((Throwable)e);
}
}
private PDFAConversionOptionSpec createPDFAConversionOptions(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
String colorspace;
PDFAConversionOptionSpec conversionOptions = new PDFAConversionOptionSpec();
if (metaDataMap.get("compliance", String.class) != null) {
String compliance = (String)metaDataMap.get("compliance", String.class);
LOGGER.debug("compliance= " + compliance);
conversionOptions.setCompliance(PDFAConversionOptionSpec.Compliance.valueOf((String)compliance));
}
if (metaDataMap.get("resultLevel", String.class) != null) {
String resultLevel = (String)metaDataMap.get("resultLevel", String.class);
LOGGER.debug("resultLevel= " + resultLevel);
conversionOptions.setResultLevel(PDFAConversionOptionSpec.ResultLevel.valueOf((String)resultLevel));
}
if (metaDataMap.get("signatures", String.class) != null) {
String signatures = (String)metaDataMap.get("signatures", String.class);
LOGGER.debug("signatures= " + signatures);
conversionOptions.setSignatures(PDFAConversionOptionSpec.Signatures.valueOf((String)signatures));
}
if (metaDataMap.get("colorspace", String.class) != null) {
colorspace = (String)metaDataMap.get("colorspace", String.class);
LOGGER.debug("colorspace= " + colorspace);
conversionOptions.setColorSpace(PDFAConversionOptionSpec.ColorSpace.valueOf((String)colorspace));
}
if (metaDataMap.get("colorspace", String.class) != null) {
colorspace = (String)metaDataMap.get("colorspace", String.class);
LOGGER.debug("colorspace= " + colorspace);
conversionOptions.setColorSpace(PDFAConversionOptionSpec.ColorSpace.valueOf((String)colorspace));
}
if (metaDataMap.get("optionalContent", String.class) != null) {
String optionalContent = (String)metaDataMap.get("optionalContent", String.class);
LOGGER.debug("optionalContent= " + optionalContent);
conversionOptions.setOptionalContent(PDFAConversionOptionSpec.OptionalContent.valueOf((String)optionalContent));
}
if (metaDataMap.get("verifyConversion", Boolean.class) != null) {
Boolean verifyConversion = (Boolean)metaDataMap.get("verifyConversion", Boolean.class);
LOGGER.debug("verifyConversion= " + verifyConversion);
conversionOptions.setVerify(verifyConversion.booleanValue());
}
if (metaDataMap.get("logLevelParam", String.class) != null) {
String logLevel = (String)metaDataMap.get("logLevelParam", String.class);
LOGGER.debug("logLevelParam= " + logLevel);
conversionOptions.setLogLevel(logLevel);
}
if (metaDataMap.get("metadataExtensionSchema", String.class) != null) {
String metadataSchemaPath = (String)metaDataMap.get("metadataExtensionSchema", String.class);
LOGGER.debug("metadataExtensionSchema= " + metadataSchemaPath);
if (!metadataSchemaPath.isEmpty()) {
conversionOptions.setMetadataSchemaExtensions(Collections.singletonList(new Document(metadataSchemaPath)));
}
}
return conversionOptions;
}
protected void bindAssemblerService(AssemblerService assemblerService) {
this.assemblerService = assemblerService;
}
protected void unbindAssemblerService(AssemblerService assemblerService) {
if (this.assemblerService == assemblerService) {
this.assemblerService = null;
}
}
}