PaperCaptureCaller.java
11.7 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.native2pdf.xml.FiletypeSettings
* com.adobe.native2pdf.xml.FiletypeSettings$Settings
* com.adobe.native2pdf.xml.SecuritySettings
* com.adobe.native2pdf.xml.SecuritySettings$Settings
* com.adobe.pdfg.common.AESProperties
* com.adobe.pdfg.common.FileUtilities
* com.adobe.pdfg.common.Guid
* com.adobe.pdfg.common.JobConfiguration
* com.adobe.pdfg.common.PDFGGlobalCache
* com.adobe.pdfg.common.Utils
* com.adobe.pdfg.exception.ConversionException
* com.adobe.pdfg.exception.InvalidParameterException
* com.adobe.pdfg.logging.PDFGLogger
* com.adobe.pdfg.service.api.PDFGConfigService
* com.adobe.service.ConnectionFactory
*/
package com.adobe.pdfg.impl;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.native2pdf.xml.SecuritySettings;
import com.adobe.pdfg.callbacks.PaperCaptureTransactionCallback;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.FileUtilities;
import com.adobe.pdfg.common.Guid;
import com.adobe.pdfg.common.JobConfiguration;
import com.adobe.pdfg.common.PDFGGlobalCache;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.exception.ConversionException;
import com.adobe.pdfg.exception.InvalidParameterException;
import com.adobe.pdfg.impl.BMCCaller;
import com.adobe.pdfg.impl.GeneratePDFServiceImpl;
import com.adobe.pdfg.impl.GeneratePDFUtil;
import com.adobe.pdfg.impl.utils.AdjustableSemaphore;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.postprocess.PostProcessFileInfo;
import com.adobe.pdfg.service.api.PDFGConfigService;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.pdfg.transaction.TransactionTemplate;
import com.adobe.service.ConnectionFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;
public class PaperCaptureCaller
extends BMCCaller {
private static int poolSize = 3;
private static Semaphore conversionLock = null;
private String NATIVE_IN_XMP_FILENAME = "xmp-in.xmp";
protected boolean checkLinearizationForPostProcessing() {
return true;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public Map createPDF(GeneratePDFServiceImpl coreSvcImpl, Document sourceFileDoc, String inputFileName, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, String jobConfigurationString, Document xmpDoc) throws Exception {
File logFile;
int lastDot;
String jobIdentityId = new Guid().toString();
Utils.threadLocalValue.set(jobIdentityId);
long startTime = 0;
startTime = System.currentTimeMillis();
String configString = GeneratePDFUtil.getJobConfigurationString(coreSvcImpl.getConfigService(), settingsDoc, fileTypeSettings, pdfSettings, securitySettings);
JobConfiguration config = null;
this.pdfgLogger.info("001-024", new Object[]{inputFileName, new Date(startTime), jobIdentityId});
this.pdfgLogger.info("001-016", new Object[]{inputFileName, "OCR"});
try {
config = PDFGGlobalCache.getJobConfiguration((String)configString);
}
catch (Exception e) {
throw new InvalidParameterException(1001, (Throwable)e);
}
if (config == null) {
throw new InvalidParameterException(80001);
}
this.pdfgLogger.info("001-022", new Object[]{inputFileName, config.getSecuritySettings().getName()});
this.pdfgLogger.info("001-023", new Object[]{inputFileName, config.getFiletypeSettings().getName()});
int timeoutSeconds = AESProperties.getMaximumTimeout();
timeoutSeconds = Math.max(10, timeoutSeconds);
timeoutSeconds = config.getConversionTimeoutSetting(10, timeoutSeconds, timeoutSeconds);
File pdfgTmpDir = null;
try {
pdfgTmpDir = FileUtilities.createGuidDir((String)jobIdentityId);
}
catch (IOException ioe) {
throw new ConversionException(1003, (Throwable)ioe);
}
if (inputFileName == null || "".equals(inputFileName)) {
inputFileName = "PaperCaptureInput.pdf";
}
File inputFile = new File(pdfgTmpDir, inputFileName);
sourceFileDoc.copyToFile(inputFile);
if (inputFile.length() == 0) {
throw new ConversionException(11019);
}
File outputFile = inputFile;
String inputPdfPath = inputFile.getAbsolutePath();
String outputPdfPath = outputFile.getAbsolutePath();
File xmpFile = null;
if (xmpDoc != null) {
xmpFile = new File(pdfgTmpDir, this.NATIVE_IN_XMP_FILENAME);
xmpDoc.copyToFile(xmpFile);
this.pdfgLogger.info("001-020", new Object[]{inputFileName, xmpFile.getName()});
}
String logFilePath = (lastDot = outputPdfPath.lastIndexOf(".")) != -1 ? outputPdfPath.substring(0, lastDot) + ".log" : outputPdfPath + ".log";
PaperCaptureTransactionCallback transactionCallback = new PaperCaptureTransactionCallback(coreSvcImpl.getPaperCaptureFactory());
transactionCallback.setSourcePath(inputPdfPath);
transactionCallback.setDestinationPath(outputPdfPath);
transactionCallback.setLogPath(logFilePath);
transactionCallback.setTimeout(timeoutSeconds);
transactionCallback.setOCRParams(config);
try {
coreSvcImpl.getPaperCaptureConversionLock().acquire();
TransactionTemplate _txTemplate = coreSvcImpl.getTransactionTemplate();
_txTemplate.setPropagationBehavior(0);
_txTemplate.setTimeout(timeoutSeconds + 200);
this.pdfgLogger.debug("before calling _txTemplate.execute for job=" + jobIdentityId);
_txTemplate.execute(transactionCallback);
Object var27_28 = null;
}
catch (Throwable var26_30) {
Object var27_29 = null;
coreSvcImpl.getPaperCaptureConversionLock().release();
throw var26_30;
}
coreSvcImpl.getPaperCaptureConversionLock().release();
{
}
int errorCode = 0;
errorCode = this.initializeConfiguration(coreSvcImpl, settingsDoc, jobConfigurationString, errorCode);
errorCode = this.setDistillerParams(coreSvcImpl, "PaperCaptureService", errorCode);
PostProcessFileInfo filePaths = new PostProcessFileInfo();
filePaths.pdfFilePath = outputPdfPath;
filePaths.logFilePath = logFilePath;
File jobOptionFile = null;
try {
String suffix = ".joboptions";
errorCode = 1002;
jobOptionFile = this.validateConfigAndWriteJobOptions(coreSvcImpl, config, this.jobOptionName, ".joboptions", false, this.appConfig, pdfgTmpDir);
this.jobOptionName = this.getJobOptionNameFromFile(jobOptionFile, ".joboptions");
this.doPostProcess("PaperCaptureService", "PaperCaptureService", xmpFile, outputPdfPath, coreSvcImpl, jobOptionFile, errorCode, filePaths, false, false, null, 1, GeneratePDFUtil.applyWaterMark());
Object var30_33 = null;
if (jobOptionFile != null && jobOptionFile.exists()) {
jobOptionFile.delete();
}
}
catch (Throwable var29_36) {
Object var30_34 = null;
if (jobOptionFile != null && jobOptionFile.exists()) {
jobOptionFile.delete();
}
throw var29_36;
}
Document convertedDoc = filePaths.postProcessedDoc;
File pdfFile = null;
if (convertedDoc == null) {
pdfFile = new File(filePaths.pdfFilePath);
}
if (pdfFile != null && pdfFile.exists() && pdfFile.length() > 0) {
convertedDoc = new Document(pdfFile, false);
}
long endTime = System.currentTimeMillis();
if (convertedDoc != null) {
convertedDoc.setAttribute("file", (Object)inputFileName);
convertedDoc.setContentType("application/pdf");
}
Document logDoc = null;
if (logFilePath != null && (logFile = new File(logFilePath)).exists() && logFile.length() > 0) {
logDoc = new Document(logFile, true);
logDoc.setAttribute("file", (Object)logFilePath);
logDoc.setContentType("text/plain");
}
this.pdfgLogger.info("001-027", inputFileName);
this.pdfgLogger.info("001-025", new Object[]{inputFileName, new Date(endTime), jobIdentityId});
this.pdfgLogger.info("001-026", new Object[]{inputFileName, endTime - startTime, jobIdentityId});
HashMap<String, Document> map = new HashMap<String, Document>();
if (convertedDoc != null) {
map.put("ConvertedDoc", convertedDoc);
if (logDoc != null) {
map.put("LogDoc", logDoc);
}
} else {
ConversionException e = new ConversionException(11026);
if (logDoc != null) {
this.createConversionLog(e, logFilePath);
}
throw e;
}
return map;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Unable to fully structure code
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
* Lifted jumps to return sites
*/
private void createConversionLog(ConversionException conversionException, String logFilePath) {
if (logFilePath == null) {
return;
}
logFile = new File(logFilePath);
if (logFile.exists() == false) return;
if (logFile.isFile() == false) return;
if (logFile.length() <= 0) return;
if (logFile.canRead() == false) return;
fileReader = null;
stringWriter = null;
try {
try {
fileReader = new BufferedReader(new FileReader(logFile));
stringWriter = new StringWriter();
buffer = new char[256];
nCharacters = fileReader.read(buffer);
while (nCharacters != -1) {
stringWriter.write(buffer, 0, nCharacters);
nCharacters = fileReader.read(buffer);
}
conversionException.setConversionLog(stringWriter.toString());
}
catch (Exception e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
var9_10 = null;
if (fileReader == null) return;
try {}
catch (Exception e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
return;
}
fileReader.close();
return;
}
var9_9 = null;
if (fileReader == null) return;
fileReader.close();
return;
catch (Exception e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
return;
}
}
catch (Throwable throwable) {
var9_11 = null;
if (fileReader == null) throw throwable;
** try [egrp 2[TRYBLOCK] [4 : 173->181)] {
lbl46: // 1 sources:
fileReader.close();
throw throwable;
lbl48: // 1 sources:
catch (Exception e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
}
throw throwable;
}
}
}