NativeToPDFTransactionCallback.java
10.9 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.bedrock.internal.OSGiUtils
* com.adobe.native2pdf.bmc.AppMonData
* com.adobe.native2pdf.bmc.ConverterAgent
* com.adobe.native2pdf.bmc.ConverterAgentHelper
* com.adobe.native2pdf.bmc.ResultStruct
* com.adobe.pdfg.common.AESProperties
* com.adobe.pdfg.common.Utils
* com.adobe.pdfg.logging.PDFGLogger
* com.adobe.service.ConnectionFactory
* com.jniwrapper.DefaultLibraryLoader
* com.jniwrapper.win32.registry.RegistryKey
* com.jniwrapper.win32.registry.RegistryKeyValues
*/
package com.adobe.pdfg.callbacks;
import com.adobe.aemds.bedrock.internal.OSGiUtils;
import com.adobe.native2pdf.bmc.AppMonData;
import com.adobe.native2pdf.bmc.ConverterAgent;
import com.adobe.native2pdf.bmc.ConverterAgentHelper;
import com.adobe.native2pdf.bmc.ResultStruct;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.service.ConnectionFactory;
import com.jniwrapper.DefaultLibraryLoader;
import com.jniwrapper.win32.registry.RegistryKey;
import com.jniwrapper.win32.registry.RegistryKeyValues;
import java.util.Map;
import org.omg.CORBA.Object;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class NativeToPDFTransactionCallback
implements TransactionCallback {
private static final int MAX_RETRY_COUNT = 5;
private static final long WAIT_TIME = 60000;
private static final String officeRegEntry = "Software\\Microsoft\\Office";
private static final String addInLocation = "Addins\\PDFMaker.OfficeAddin";
private static final String pathSep = "\\";
private static final boolean nonAdminEffective = System.getProperty("os.name").toLowerCase().indexOf("windows") > -1 && System.getenv("PDFG_NON_ADMIN_ENABLED") != null;
private static int m_pdfMakerpoolSize = 1;
private static PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(NativeToPDFTransactionCallback.class);
private String m_strSourceFilePath = null;
private String m_strDestFilePath = null;
private String appName = null;
private int m_iTimeoutSeconds = 270;
private byte[] m_securityConfig = null;
private String m_strJobOptionsName = null;
private byte[] m_appSpecificConfig = null;
private AppMonData m_appMonConfig = null;
private boolean m_bApplyWatermark = false;
private boolean m_bUseNative = true;
private boolean m_bCreatePDFA = false;
private int startPage;
private int endPage;
private String m_ocrlanguageChosen;
private ConnectionFactory nativeToPdfFactory;
private ConnectionFactory pdfMakerFactory;
public NativeToPDFTransactionCallback(ConnectionFactory nativeToPdfFactory, ConnectionFactory pdfMakerFactory) {
this.nativeToPdfFactory = nativeToPdfFactory;
this.pdfMakerFactory = pdfMakerFactory;
this.nativeToPdfFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
this.pdfMakerFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
}
public void initNativeToPDFFactory(Map usersMap) throws Exception {
String jobIdentityId = (String)Utils.threadLocalValue.get();
StringBuilder debugMsgs = new StringBuilder();
debugMsgs.append("\nInside NativeToPDFTransactionCallback.initNativeToPDFFactory for job=" + jobIdentityId);
if (usersMap != null && !usersMap.isEmpty()) {
this.nativeToPdfFactory.setImpersonationIdentities(usersMap);
}
debugMsgs.append("\nabout to exit initNativeToPDFFactory() for job=" + jobIdentityId);
}
public void initPDFMToPDFFactory(Map usersMap) throws Exception {
String jobIdentityId = (String)Utils.threadLocalValue.get();
StringBuilder debugMsgs = new StringBuilder();
debugMsgs.append("\nInside NativeToPDFTransactionCallback.initPDFMToPDFFactory for job=" + jobIdentityId);
if (usersMap != null && !usersMap.isEmpty()) {
m_pdfMakerpoolSize = usersMap.size();
this.pdfMakerFactory.setImpersonationIdentities(usersMap);
}
debugMsgs.append("\nabout to exit initPDFMToPDFFactory() for job=" + jobIdentityId);
}
protected void resetOfficeAddinLoadBehaviorRegistryValue(String app) {
if (nonAdminEffective) {
StringBuilder regPath = null;
try {
Long keyVal;
pdfgLogger.debug("Inside resetOfficeAddinLoadBehaviorRegistryValue");
regPath = new StringBuilder("Software\\Microsoft\\Office").append("\\");
regPath.append(app).append("\\");
regPath.append("Addins\\PDFMaker.OfficeAddin");
RegistryKey localMachine = RegistryKey.LOCAL_MACHINE;
RegistryKey officeOptions = localMachine.openSubKey(regPath.toString(), true);
RegistryKeyValues keyValues = officeOptions.values();
if (keyValues.containsKey((java.lang.Object)"LoadBehavior") && (keyVal = (Long)keyValues.get((java.lang.Object)"LoadBehavior")) != 3) {
keyValues.put((java.lang.Object)"LoadBehavior", (java.lang.Object)3);
pdfgLogger.debug("Re-enabling the Adobe Acrobat PDFMaker add-in (changed the value of Load Behaviour) for MS Office.", "");
}
}
catch (Exception ex) {
pdfgLogger.info(ex.getLocalizedMessage(), "");
}
}
}
public java.lang.Object doInTransaction() {
pdfgLogger.debug("inside doInTransaction() for job=" + (String)Utils.threadLocalValue.get());
if (this.m_bUseNative) {
return this.convertToPdf(this.nativeToPdfFactory);
}
return this.convertToPdf(this.pdfMakerFactory);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private ResultStruct convertToPdf(ConnectionFactory connectionFactory) {
ResultStruct resultStruct;
boolean debugMsgsLogged;
StringBuilder debugMsgs;
block9 : {
ConverterAgent agent = null;
String jobIdentityId = (String)Utils.threadLocalValue.get();
debugMsgs = new StringBuilder();
debugMsgsLogged = false;
debugMsgs.append("\nInside NativeToPDFTransactionCallback.convertToPdf for job=" + jobIdentityId);
try {
debugMsgs.append("\nbefore obtaining a CORBA connection for job=" + jobIdentityId);
Object connection = (Object)connectionFactory.getConnection();
debugMsgs.append("\nbefore narrowing the CORBA connection for job=" + jobIdentityId);
agent = ConverterAgentHelper.narrow((Object)connection);
debugMsgs.append("\nbefore agent.convertToPdf for job=" + jobIdentityId);
pdfgLogger.debug(debugMsgs.toString());
debugMsgsLogged = true;
if (this.m_ocrlanguageChosen == null) {
this.m_ocrlanguageChosen = "";
}
this.resetOfficeAddinLoadBehaviorRegistryValue(this.appName);
resultStruct = agent.convertToPdf(this.m_strSourceFilePath, this.m_strDestFilePath, this.appName, this.m_iTimeoutSeconds, this.m_securityConfig, this.m_strJobOptionsName, this.m_appSpecificConfig, this.m_appMonConfig, this.m_bApplyWatermark, this.m_bCreatePDFA, jobIdentityId, this.startPage, this.endPage, this.m_ocrlanguageChosen);
java.lang.Object var9_8 = null;
if (agent == null) break block9;
}
catch (Throwable var8_12) {
java.lang.Object var9_9 = null;
if (agent != null) {
try {
agent.cleanUp();
}
catch (Exception t) {
pdfgLogger.trace(t.getMessage(), null, (Throwable)t);
}
}
if (!debugMsgsLogged) {
pdfgLogger.debug(debugMsgs.toString());
}
throw var8_12;
}
try {
agent.cleanUp();
}
catch (Exception t) {
pdfgLogger.trace(t.getMessage(), null, (Throwable)t);
}
}
if (!debugMsgsLogged) {
pdfgLogger.debug(debugMsgs.toString());
}
return resultStruct;
}
public void setApplyWatermark(boolean applyWatermark) {
this.m_bApplyWatermark = applyWatermark;
}
public void setAppMonConfig(AppMonData appMonConfig) {
this.m_appMonConfig = appMonConfig;
}
public void setAppName(String appName) {
this.appName = appName;
}
public void setAppSpecificConfig(byte[] appSpecificConfig) {
this.m_appSpecificConfig = appSpecificConfig;
}
public void setDestFilePath(String destFilePath) {
this.m_strDestFilePath = destFilePath;
}
public void setDistillerJobOptionsName(String distillerJobOptionsName) {
this.m_strJobOptionsName = distillerJobOptionsName;
}
public void setSecurityConfig(byte[] securityConfig) {
this.m_securityConfig = securityConfig;
}
public void setSourceFilePath(String sourceFilePath) {
this.m_strSourceFilePath = sourceFilePath;
}
public void setTimeoutSeconds(int timeoutSeconds) {
this.m_iTimeoutSeconds = timeoutSeconds;
}
public void setUseNative(boolean usePDFM) {
this.m_bUseNative = usePDFM;
}
public void setCreatePDFA(boolean createPDFA) {
this.m_bCreatePDFA = createPDFA;
}
public void setStartPage(int startPage) {
this.startPage = startPage;
}
public void setEndPage(int endPage) {
this.endPage = endPage;
}
public int getPDFMakerPoolSize() {
return m_pdfMakerpoolSize;
}
public void setNativeToPdfFactory(ConnectionFactory nativeToPdfFactory) {
this.nativeToPdfFactory = nativeToPdfFactory;
}
public void setPdfMakerFactory(ConnectionFactory pdfMakerFactory) {
this.pdfMakerFactory = pdfMakerFactory;
}
public void modifyUserAccountsMapForPDFM(Map<String, String> usersMap) throws Exception {
if (usersMap != null && !usersMap.isEmpty()) {
this.pdfMakerFactory.setImpersonationIdentities(usersMap);
}
}
public void setOCRLanguage(String ocrLanguageChosen) {
this.m_ocrlanguageChosen = ocrLanguageChosen;
}
public String getOCRLanguage() {
return this.m_ocrlanguageChosen;
}
static {
if (nonAdminEffective) {
StringBuilder dllPath = new StringBuilder(OSGiUtils.getCoreConfigService().getServerNativeDir());
dllPath.append("\\");
dllPath.append("Native2PDFSvc").append("\\");
dllPath.append("bin").append("\\");
dllPath.append("dll");
DefaultLibraryLoader.getInstance().addPath(dllPath.toString());
}
}
}