PaperCaptureTransactionCallback.java
11.3 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.native2pdf.xml.FiletypeSettings
* com.adobe.native2pdf.xml.FiletypeSettings$Settings
* com.adobe.native2pdf.xml.FiletypeSettings$Settings$Image
* com.adobe.pdfg.common.AESProperties
* com.adobe.pdfg.common.JobConfiguration
* com.adobe.pdfg.common.Utils
* com.adobe.pdfg.exception.PDFGError
* com.adobe.pdfg.exception.PDFGRuntimeException
* com.adobe.pdfg.logging.PDFGLogger
* com.adobe.pdfg.papercapture.OCRDownsample
* com.adobe.pdfg.papercapture.OCRLibraryFormat
* com.adobe.pdfg.papercapture.OCRLibraryLanguage
* com.adobe.pdfg.papercapture.OCROptions
* com.adobe.pdfg.papercapture.PaperCaptureService
* com.adobe.pdfg.papercapture.PaperCaptureServiceHelper
* com.adobe.service.ConnectionFactory
*/
package com.adobe.pdfg.callbacks;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.JobConfiguration;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.exception.PDFGError;
import com.adobe.pdfg.exception.PDFGRuntimeException;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.papercapture.OCRDownsample;
import com.adobe.pdfg.papercapture.OCRLibraryFormat;
import com.adobe.pdfg.papercapture.OCRLibraryLanguage;
import com.adobe.pdfg.papercapture.OCROptions;
import com.adobe.pdfg.papercapture.PaperCaptureService;
import com.adobe.pdfg.papercapture.PaperCaptureServiceHelper;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.service.ConnectionFactory;
import org.omg.CORBA.COMM_FAILURE;
import org.omg.CORBA.Object;
public class PaperCaptureTransactionCallback
implements TransactionCallback {
private ConnectionFactory m_ocrToPdfFactory;
private static final int MAX_RETRY_COUNT = 5;
private static final long WAIT_TIME = 60000;
String m_strSourcePath = null;
String m_strDestinationPath = null;
String m_strLogPath = null;
long m_ltimeout = 480000;
OCROptions m_ocrSettings = new OCROptions();
private PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(PaperCaptureTransactionCallback.class);
public PaperCaptureTransactionCallback(ConnectionFactory paperCaptureFactory) {
this.m_ocrToPdfFactory = paperCaptureFactory;
this.m_ocrToPdfFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
}
public java.lang.Object doInTransaction() {
Boolean bl;
block6 : {
String jobIdentityId = (String)Utils.threadLocalValue.get();
StringBuilder debugMsgs = new StringBuilder();
boolean debugMsgsLogged = false;
try {
debugMsgs.append("\nInside PaperCaptureTransactionCallback.doInTransaction() for job=" + jobIdentityId);
Object connection = (Object)this.m_ocrToPdfFactory.getConnection();
debugMsgs.append("\nafter m_ocrToPdfFactory.getConnection() for job=" + jobIdentityId);
PaperCaptureService service = PaperCaptureServiceHelper.narrow((Object)connection);
debugMsgs.append("\nbefore service.convertToPdf() for job=" + jobIdentityId);
this.pdfgLogger.debug(debugMsgs.toString());
debugMsgsLogged = true;
boolean returnVal = service.recognizeTextInPdf(this.m_strSourcePath, this.m_strDestinationPath, this.m_strLogPath, this.m_ocrSettings, this.m_ltimeout);
bl = returnVal;
java.lang.Object var9_11 = null;
if (debugMsgsLogged) break block6;
}
catch (Exception ex) {
try {
if (ex != null && ex instanceof COMM_FAILURE) {
PDFGError error = new PDFGError(10010, (Throwable)ex);
throw new PDFGRuntimeException(error);
}
PDFGError error = new PDFGError(10001, (Throwable)ex);
throw new PDFGRuntimeException(error);
}
catch (Throwable var8_13) {
java.lang.Object var9_12 = null;
if (!debugMsgsLogged) {
this.pdfgLogger.debug(debugMsgs.toString());
}
throw var8_13;
}
}
this.pdfgLogger.debug(debugMsgs.toString());
}
return bl;
}
public void setTimeout(int timeout) {
this.m_ltimeout = (long)timeout * 1000;
}
public void setDestinationPath(String destinationPath) {
this.m_strDestinationPath = destinationPath;
}
public void setLogPath(String logPath) {
this.m_strLogPath = logPath;
}
public void setSourcePath(String sourcePath) {
this.m_strSourcePath = sourcePath;
}
public void setOCRParams(JobConfiguration config) {
FiletypeSettings.Settings.Image ocr2pdf = null;
ocr2pdf = config.getFiletypeSettings().getImage();
if (ocr2pdf != null) {
String downsampling = ocr2pdf.getOcrDownsampleType();
String outputStyle = ocr2pdf.getOcrOutputStyle();
String lang = ocr2pdf.getOcrLanguage();
this.m_ocrSettings.downsampling = this.getOCRDownsample(downsampling);
this.m_ocrSettings.format = this.getOCRLibraryFormat(outputStyle);
this.m_ocrSettings.language = this.getOCRLibraryLanguage(lang);
}
}
private OCRDownsample getOCRDownsample(String downsampling) {
if ("Lowest".equals(downsampling)) {
return OCRDownsample.OCRDownsample600;
}
if ("Low".equals(downsampling)) {
return OCRDownsample.OCRDownsample300;
}
if ("Medium".equals(downsampling)) {
return OCRDownsample.OCRDownsample150;
}
if ("High".equals(downsampling)) {
return OCRDownsample.OCRDownsample72;
}
return OCRDownsample.OCRDownsampleNone;
}
private OCRLibraryFormat getOCRLibraryFormat(String format) {
if ("Searchable-Exact".equals(format)) {
return OCRLibraryFormat.OCRLibraryImageExact;
}
if ("Searchable-Compact".equals(format)) {
return OCRLibraryFormat.OCRLibraryImage;
}
if ("Formatted-Text".equals(format)) {
return OCRLibraryFormat.OCRLibraryClearScan;
}
return OCRLibraryFormat.OCRLibraryDefaultFormat;
}
private OCRLibraryLanguage getOCRLibraryLanguage(String language) {
OCRLibraryLanguage ocrLang = OCRLibraryLanguage.OCRLANG_HOST;
if ("Basque".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_BASQUE;
} else if ("Brazilian-Portuguese".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_BRAZILIANPORTUGUESE;
} else if ("Bulgarian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_BULGARIAN;
} else if ("Catalan".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_CATALAN;
} else if ("Croatian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_CROATIAN;
} else if ("Czechoslovakian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_CZECH;
} else if ("Czech".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_CZECH;
} else if ("Danish".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_DANISH;
} else if ("Dutch".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_DUTCH;
} else if ("English(UK)".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_ENGLISHUK;
} else if ("English(US)".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_ENGLISHUS;
} else if ("Estonian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_ESTONIAN;
} else if ("Finnish".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_FINNISH;
} else if ("French".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_FRENCH;
} else if ("Galacian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_GALICIAN;
} else if ("German".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_GERMAN;
} else if ("Greek".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_GREEK;
} else if ("Hebrew".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_HEBREW;
} else if ("Hungarian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_HUNGARIAN;
} else if ("Italian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_ITALIAN;
} else if ("Japanese".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_JAPANESE;
} else if ("Korean".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_KOREAN;
} else if ("Latvian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_LATVIAN;
} else if ("Lithuanian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_LITHUANIAN;
} else if ("Macedonian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_MACEDONIAN;
} else if ("Maltese".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_MALTESE;
} else if ("Norwegian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_NORWEGIAN;
} else if ("Nynorsk".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_NYNORSK;
} else if ("Occitan".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_OCCITAN;
} else if ("Polish".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_POLISH;
} else if ("Portuguese".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_PORTUGUESE;
} else if ("Romanian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_ROMANIAN;
} else if ("Russian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_RUSSIAN;
} else if ("Serbian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SERBIAN;
} else if ("Simplified Chinese".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SIMPLIFIEDCHINESE;
} else if ("Slovak".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SLOVAK;
} else if ("Slovenian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SLOVENIAN;
} else if ("Spanish".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SPANISH;
} else if ("Swedish".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SWEDISH;
} else if ("Swiss-German".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_SWISSGERMAN;
} else if ("Turkish".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_TURKISH;
} else if ("Traditional Chinese".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_TRADITIONALCHINESE;
} else if ("Ukrainian".equals(language)) {
ocrLang = OCRLibraryLanguage.OCRLANG_UKRAINIAN;
}
return ocrLang;
}
public void setOcrToPdfFactory(ConnectionFactory m_ocrToPdfFactory) {
this.m_ocrToPdfFactory = m_ocrToPdfFactory;
}
}