OpenOffice2PdfCaller.java
18 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.native2pdf.bmc.ResultStruct
* 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.FileUtilities
* com.adobe.pdfg.common.Guid
* com.adobe.pdfg.common.JobConfiguration
* com.adobe.pdfg.common.StreamGobbler
* com.adobe.pdfg.common.Utils
* com.adobe.pdfg.exception.ConversionException
* com.adobe.pdfg.exception.ErrorCode
* com.adobe.pdfg.exception.FileFormatNotSupportedException
* com.adobe.pdfg.exception.InvalidParameterException
* com.adobe.pdfg.logging.PDFGLogger
* com.adobe.service.ConnectionFactory
*/
package com.adobe.pdfg.impl;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.native2pdf.bmc.ResultStruct;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.native2pdf.xml.SecuritySettings;
import com.adobe.pdfg.callbacks.OpenOfficeToPDFTransactionCallback;
import com.adobe.pdfg.common.FileUtilities;
import com.adobe.pdfg.common.Guid;
import com.adobe.pdfg.common.JobConfiguration;
import com.adobe.pdfg.common.StreamGobbler;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.exception.ConversionException;
import com.adobe.pdfg.exception.ErrorCode;
import com.adobe.pdfg.exception.FileFormatNotSupportedException;
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.logging.PDFGLogger;
import com.adobe.pdfg.postprocess.PostProcessFileInfo;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.service.ConnectionFactory;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;
import org.omg.CORBA.COMM_FAILURE;
public class OpenOffice2PdfCaller
extends BMCCaller {
static final long serialVersionUID = 2301;
static int oo_pool_size = 1;
private static Semaphore ooConversionLock = null;
private static String m_osname = System.getProperty("os.name").toLowerCase();
private String OPENOFFICE_IN_FILE_NAME = "openoffice-in";
/*
* 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
* Converted monitor instructions to comments
* Lifted jumps to return sites
*/
public Map createPDF(GeneratePDFServiceImpl coreSvcImpl, Document sourceFileDoc, String inputFileName, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, String jobConfigurationString, Document xmpDoc, String[] openOfficeData) throws InvalidParameterException, ConversionException, FileFormatNotSupportedException {
debugMsgsLogged = false;
jobIdentityId = (String)Utils.threadLocalValue.get();
debugMsgs = new StringBuilder();
debugMsgs.append("\nInside openOffice2PdfCaller.createPDF for job=" + jobIdentityId);
xmpFile = null;
success = true;
waitStartTime = 0;
waitEndTime = 0;
if (sourceFileDoc == null) {
throw new InvalidParameterException(11025);
}
errorCode = -1;
startTime = System.currentTimeMillis();
this.pdfgLogger.info("001-001", new Object[]{inputFileName});
this.pdfgLogger.info("001-024", new Object[]{inputFileName, new Date(startTime), jobIdentityId});
this.pdfgLogger.info("001-016", new Object[]{inputFileName, "OpenOffice to PDF"});
extension = inputFileName.substring(inputFileName.lastIndexOf("."), inputFileName.length());
pdfgTmpDir = null;
try {
pdfgTmpDir = FileUtilities.createGuidDir((String)new Guid().toString());
}
catch (IOException e2) {
throw new ConversionException(1000, (Throwable)e2);
}
sourceFile = new File(pdfgTmpDir, this.OPENOFFICE_IN_FILE_NAME + extension);
try {
sourceFileDoc.copyToFile(sourceFile);
}
catch (IOException e3) {
throw new ConversionException(1000, (Throwable)e3);
}
if (sourceFile.length() == 0) {
throw new ConversionException(11019);
}
errorCode = this.initializeConfiguration(coreSvcImpl, settingsDoc, jobConfigurationString, errorCode);
debugMsgs.append("\nafter calling initializeConfiguration() for job=" + jobIdentityId);
sourcePathOrURL = null;
try {
sourcePathOrURL = sourceFile.getCanonicalPath();
}
catch (IOException e1) {
throw new ConversionException(9001, (Throwable)e1);
}
this.pdfgLogger.info("001-022", new Object[]{inputFileName, this.config.getSecuritySettings().getName()});
this.pdfgLogger.info("001-023", new Object[]{inputFileName, this.config.getFiletypeSettings().getName()});
jobOptionFile = null;
suffix = ".joboptions";
errorCode = 1002;
jobOptionFile = this.validateConfigAndWriteJobOptions(coreSvcImpl, this.config, this.jobOptionName, ".joboptions", false, this.appConfig, pdfgTmpDir);
this.jobOptionName = this.getJobOptionNameFromFile(jobOptionFile, ".joboptions");
debugMsgs.append("\nafter calling getJobOptionNameFromFile() for job=" + jobIdentityId);
destinationPath = null;
try {
try {
path = System.getenv("OpenOffice_PATH");
v0 = bOpenOfficePathSet = path != null && "".equals(path.trim()) == false;
if (!bOpenOfficePathSet) {
throw new ConversionException(11030);
}
usersMap = coreSvcImpl.getUserAccountsMap();
if ((OpenOffice2PdfCaller.m_osname.contains("2008") || OpenOffice2PdfCaller.m_osname.contains("vista") || OpenOffice2PdfCaller.m_osname.contains("windows 7")) && (usersMap == null || usersMap.isEmpty())) {
this.pdfgLogger.info("Conversion failed as no user is defined.");
throw new ConversionException(80036);
}
results = null;
byteArrayOutputStream = new ByteArrayOutputStream();
objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(openOfficeData);
parentDir = pdfgTmpDir.getParent();
destinationPath = parentDir + File.separator + new Guid().toString() + ".pdf";
if (!OpenOffice2PdfCaller.m_osname.contains("win")) {
this.changeTmpDirPermissions(parentDir);
}
debugMsgs.append("\nbefore calling OpenOfficeToPDFTransactionCallback.initConnectionFactory() for job=" + jobIdentityId);
transactionCallback = new OpenOfficeToPDFTransactionCallback(coreSvcImpl.getOpenOfficeToPdfFactory());
debugMsgs.append("\nafter calling OpenOfficeToPDFTransactionCallback.initConnectionFactory() for job=" + jobIdentityId);
transactionCallback.initOpenOfficeToPdfFactory(usersMap);
transactionCallback.setTimeoutSeconds(this.timeoutSeconds);
transactionCallback.setOpenOfficeData(byteArrayOutputStream.toByteArray());
transactionCallback.setSourcePath(sourcePathOrURL);
transactionCallback.setDestinationPath(destinationPath);
OpenOffice2PdfCaller.oo_pool_size = transactionCallback.getPoolSize();
if (OpenOffice2PdfCaller.ooConversionLock == null) {
var38_42 = OpenOffice2PdfCaller.class;
// MONITORENTER : com.adobe.pdfg.impl.OpenOffice2PdfCaller.class
if (OpenOffice2PdfCaller.ooConversionLock == null) {
OpenOffice2PdfCaller.ooConversionLock = new Semaphore(OpenOffice2PdfCaller.oo_pool_size, true);
debugMsgs.append("\nafter creating semaphore for OpenOffice for job=" + jobIdentityId);
}
// MONITOREXIT : var38_42
}
debugMsgs.append("\nTrying to acquire semaphore lock for OpenOffice for job=" + jobIdentityId);
waitStartTime = System.currentTimeMillis();
OpenOffice2PdfCaller.ooConversionLock.acquire();
waitEndTime = System.currentTimeMillis();
debugMsgs.append("\nAcquired semaphore lock for OpenOffice for job=" + jobIdentityId);
try {
try {
debugMsgs.append("\nAbout to call invokeInSMT() for job=" + jobIdentityId);
this.pdfgLogger.debug(debugMsgs.toString());
debugMsgsLogged = true;
results = this.invokeInSMT(transactionCallback, coreSvcImpl);
debugMsgs = new StringBuilder();
debugMsgsLogged = false;
debugMsgs.append("\nAfter Calline invokeInSMT() for job=" + jobIdentityId);
}
catch (COMM_FAILURE cf) {
this.pdfgLogger.trace(cf.getMessage(), null, (Throwable)cf);
endTime = System.currentTimeMillis();
if ((long)this.timeoutSeconds >= (endTime - startTime) / 1000) throw new ConversionException(1000);
throw new ConversionException(ErrorCode.JOB_TIMEOUT_ERROR);
}
var42_44 = null;
debugMsgs.append("\nBefore releasing semaphore lock for job=" + jobIdentityId);
OpenOffice2PdfCaller.ooConversionLock.release();
debugMsgs.append("\nAfter releasing semaphore lock for job=" + jobIdentityId);
}
catch (Throwable var41_48) {
var42_45 = null;
debugMsgs.append("\nBefore releasing semaphore lock for job=" + jobIdentityId);
OpenOffice2PdfCaller.ooConversionLock.release();
debugMsgs.append("\nAfter releasing semaphore lock for job=" + jobIdentityId);
throw var41_48;
}
debugMsgs.append("\nBefore calling checkResult() for job=" + jobIdentityId);
errorCode = this.checkResult(results, errorCode);
debugMsgs.append("\nAfter calling checkResult(). errorCode=" + errorCode + " for job=" + jobIdentityId);
if (xmpDoc != null) {
xmpFile = new File(pdfgTmpDir, this.OPENOFFICE_IN_FILE_NAME + ".xmp");
xmpDoc.copyToFile(xmpFile);
}
errorCode = this.setDistillerParams(coreSvcImpl, "OpenOffice", errorCode);
debugMsgs.append("\nAfter calling setDistillerParams(). errorCode=" + errorCode + " for job=" + jobIdentityId);
filePaths = new PostProcessFileInfo();
filePaths.pdfFilePath = destinationPath;
debugMsgs.append("\nBefore calling doPostProcess() for job=" + jobIdentityId);
this.pdfgLogger.debug(debugMsgs.toString());
debugMsgsLogged = true;
errorCode = this.doPostProcess("OpenOffice", "OpenOffice", xmpFile, destinationPath, coreSvcImpl, jobOptionFile, errorCode, filePaths, false, false, null, 1, GeneratePDFUtil.applyWaterMark());
debugMsgs = new StringBuilder();
debugMsgsLogged = false;
debugMsgs.append("\nAfter calling doPostProcess() for job=" + jobIdentityId);
convertedDoc = filePaths.postProcessedDoc;
pdfFile = null;
if (convertedDoc == null) {
pdfFile = new File(filePaths.pdfFilePath);
}
fileName = inputFileName.substring(0, inputFileName.lastIndexOf(".") + 1) + "pdf";
if (pdfFile != null && pdfFile.exists() && pdfFile.length() > 0) {
convertedDoc = new Document(pdfFile, false);
}
if (convertedDoc == null) throw new ConversionException(1000);
convertedDoc.setAttribute("file", (Object)fileName);
map = new HashMap<String, Document>();
map.put("ConvertedDoc", convertedDoc);
debugMsgs.append("\nconvertedDoc is not null. Returning from OpenOffice2PdfCaller.createPDF() for job=" + jobIdentityId);
var43_51 = map;
var45_52 = null;
if (pdfgTmpDir != null) {
GeneratePDFServiceImpl.deleteSubFiles(pdfgTmpDir);
}
if (jobOptionFile != null) {
try {
jobOptionFile.delete();
jobOptionFile = null;
}
catch (Exception t) {
this.pdfgLogger.trace("001-007", null, (Throwable)t);
}
}
endTime = System.currentTimeMillis();
if (success) {
this.pdfgLogger.info("001-027", new Object[]{inputFileName});
} else {
this.pdfgLogger.info("001-028", new Object[]{inputFileName});
}
this.pdfgLogger.info("001-025", new Object[]{inputFileName, new Date(endTime), jobIdentityId});
this.pdfgLogger.info("001-030", new Object[]{inputFileName, waitEndTime - waitStartTime, jobIdentityId});
this.pdfgLogger.info("001-026", new Object[]{inputFileName, endTime - startTime - (waitEndTime - waitStartTime), jobIdentityId});
if (debugMsgsLogged != false) return var43_51;
this.pdfgLogger.debug(debugMsgs.toString());
return var43_51;
}
catch (ConversionException e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
success = false;
throw e;
}
catch (InvalidParameterException e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
success = false;
throw e;
}
catch (FileFormatNotSupportedException e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
success = false;
throw e;
}
catch (Exception e) {
success = false;
throw new ConversionException(1000, (Throwable)e);
}
}
catch (Throwable var44_58) {
block42 : {
var45_53 = null;
if (pdfgTmpDir != null) {
GeneratePDFServiceImpl.deleteSubFiles(pdfgTmpDir);
}
if (jobOptionFile != null) {
** try [egrp 8[TRYBLOCK] [18 : 1765->1777)] {
lbl190: // 1 sources:
jobOptionFile.delete();
jobOptionFile = null;
break block42;
lbl193: // 1 sources:
catch (Exception t) {
this.pdfgLogger.trace("001-007", null, (Throwable)t);
}
}
}
endTime = System.currentTimeMillis();
if (success) {
this.pdfgLogger.info("001-027", new Object[]{inputFileName});
} else {
this.pdfgLogger.info("001-028", new Object[]{inputFileName});
}
this.pdfgLogger.info("001-025", new Object[]{inputFileName, new Date(endTime), jobIdentityId});
this.pdfgLogger.info("001-030", new Object[]{inputFileName, waitEndTime - waitStartTime, jobIdentityId});
this.pdfgLogger.info("001-026", new Object[]{inputFileName, endTime - startTime - (waitEndTime - waitStartTime), jobIdentityId});
if (debugMsgsLogged != false) throw var44_58;
this.pdfgLogger.debug(debugMsgs.toString());
throw var44_58;
}
}
private void changeTmpDirPermissions(String parentDir) throws ConversionException {
try {
this.pdfgLogger.info("Changing the permission of dir " + parentDir);
String[] cmd = new String[]{"chmod", "-R", "a+wx", parentDir};
this.runCmd(cmd);
}
catch (Exception e) {
throw new ConversionException(17002, parentDir, (Throwable)e);
}
}
private int runCmd(String[] cmd) {
int retVal;
Process proc = null;
try {
proc = Runtime.getRuntime().exec(cmd);
}
catch (IOException e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
return -1;
}
try {
proc.getOutputStream().close();
}
catch (IOException e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
}
String cmdLine = Utils.unsplit((String[])cmd);
StreamGobbler errorGobbler = new StreamGobbler("error stream consumer for cmd: " + cmdLine, proc.getErrorStream(), (OutputStream)System.err);
errorGobbler.start();
StreamGobbler outputGobbler = new StreamGobbler("output stream consumer for cmd: " + cmdLine, proc.getInputStream(), null);
outputGobbler.start();
do {
try {
retVal = proc.waitFor();
break;
}
catch (InterruptedException e) {
this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
continue;
}
break;
} while (true);
errorGobbler.collectThread();
outputGobbler.collectThread();
return retVal;
}
protected boolean checkLinearizationForPostProcessing() {
return true;
}
}