PDFGConfigHelper.java
22.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
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.pdfg.exception.ConfigCreateObjectException
* com.adobe.pdfg.exception.ConfigException
* com.adobe.pdfg.exception.ConversionException
* com.adobe.pdfg.exception.SettingBeingUsedException
* com.adobe.pdfg.logging.ErrorCodeConversion
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.pdfg.config;
import com.adobe.native2pdf.xml.File2PdfSettings;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.native2pdf.xml.Folder;
import com.adobe.native2pdf.xml.Html2PdfSettings;
import com.adobe.native2pdf.xml.InitialView;
import com.adobe.native2pdf.xml.JobOptions;
import com.adobe.native2pdf.xml.JobSources;
import com.adobe.native2pdf.xml.ObjectFactory;
import com.adobe.native2pdf.xml.PDFMaker;
import com.adobe.native2pdf.xml.Pop3Account;
import com.adobe.native2pdf.xml.SecuritySettings;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.Constants;
import com.adobe.pdfg.common.PDFGGlobalCache;
import com.adobe.pdfg.common.PDFGProductInfo;
import com.adobe.pdfg.common.SettingValidator;
import com.adobe.pdfg.exception.ConfigCreateObjectException;
import com.adobe.pdfg.exception.ConfigException;
import com.adobe.pdfg.exception.ConversionException;
import com.adobe.pdfg.exception.SettingBeingUsedException;
import com.adobe.pdfg.logging.ErrorCodeConversion;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PDFGConfigHelper {
private static final Logger logger = LoggerFactory.getLogger(PDFGConfigHelper.class);
static void filterConfig(File2PdfSettings config, PDFGProductInfo pinfo, File2PdfSettings originalConfig) {
try {
ObjectFactory factory = new ObjectFactory();
if (!config.isSetJobOptions()) {
config.setJobOptions(factory.createJobOptions());
}
if (config.getJobOptions().getJobOption().size() == 0) {
config.getJobOptions().getJobOption().add(PDFGConfigHelper.getDefaultJobOptionSettings(originalConfig));
}
if (!config.isSetSecuritySettings()) {
config.setSecuritySettings(factory.createSecuritySettings());
}
if (config.getSecuritySettings().getSettings().size() == 0) {
config.getSecuritySettings().getSettings().add(PDFGConfigHelper.getDefaultSecuritySettings(originalConfig));
}
boolean filetypeAdded = false;
if (!config.isSetFiletypeSettings()) {
config.setFiletypeSettings(factory.createFiletypeSettings());
}
if (config.getFiletypeSettings().getSettings().size() == 0) {
FiletypeSettings.Settings fset = PDFGConfigHelper.getDefaultFiletypeSettings(originalConfig);
config.getFiletypeSettings().getSettings().add(fset);
filetypeAdded = true;
}
PDFGConfigHelper.checkDefaultSettings(config, pinfo);
String fname = PDFGConfigHelper.getDefaultFiletypeSettings(config).getName();
File2PdfSettings.Action action = PDFGConfigHelper.getActionTag(PDFGConfigHelper.getDefaultSecuritySettings(config).getName(), PDFGConfigHelper.getDefaultJobOptionSettings(config).getName(), fname, AESProperties.getMaximumTimeout());
config.setAction(action);
if (config.isSetFiletypeSettings()) {
FiletypeSettings sett = config.getFiletypeSettings();
for (FiletypeSettings.Settings fs : sett.getSettings()) {
if (!pinfo.isUnix()) continue;
FiletypeSettings.Settings def = PDFGConfigHelper.getDefaultFiletypeSettings(originalConfig);
fs.unsetGenericApp();
fs.setAutoCAD(null);
fs.setMSExcel(null);
fs.setMSPowerpoint(null);
fs.setMSProject(null);
fs.setMSPublisher(null);
fs.setMSVisio(null);
fs.setMSWord(null);
fs.setAdobeFlash(null);
fs.setXPS(null);
fs.setPDFExport(null);
fs.setWebCapture(null);
}
}
}
catch (Exception e) {
logger.debug("An exception occured while trying to filter the configuration", (Throwable)e);
}
}
static void checkDefaultSettings(File2PdfSettings editConfig, PDFGProductInfo pinfo) throws ConfigException {
List settingsList = null;
Iterator iter = null;
boolean foundDefault = false;
settingsList = editConfig.getJobOptions().getJobOption();
iter = settingsList.iterator();
foundDefault = false;
JobOptions.JobOption jopt = null;
while (iter.hasNext()) {
jopt = iter.next();
if (!jopt.isDefault()) continue;
if (foundDefault) {
jopt.setDefault(false);
continue;
}
foundDefault = true;
}
if (!foundDefault) {
jopt = settingsList.get(0);
jopt.setDefault(true);
}
settingsList = editConfig.getSecuritySettings().getSettings();
iter = settingsList.iterator();
foundDefault = false;
SecuritySettings.Settings sset = null;
while (iter.hasNext()) {
sset = (SecuritySettings.Settings)iter.next();
if (!sset.isDefault()) continue;
if (foundDefault) {
sset.setDefault(false);
continue;
}
foundDefault = true;
}
if (!foundDefault) {
sset = (SecuritySettings.Settings)settingsList.get(0);
sset.setDefault(true);
}
settingsList = editConfig.getFiletypeSettings().getSettings();
iter = settingsList.iterator();
foundDefault = false;
FiletypeSettings.Settings fset = null;
while (iter.hasNext()) {
fset = (FiletypeSettings.Settings)iter.next();
if (!fset.isDefault()) continue;
if (foundDefault) {
fset.setDefault(false);
continue;
}
foundDefault = true;
}
if (!foundDefault) {
fset = (FiletypeSettings.Settings)settingsList.get(0);
fset.setDefault(true);
}
}
static SecuritySettings.Settings getDefaultSecuritySettings(File2PdfSettings editConfig) {
if (editConfig.getSecuritySettings() != null) {
List<SecuritySettings.Settings> ssList = editConfig.getSecuritySettings().getSettings();
ListIterator<SecuritySettings.Settings> liter = ssList.listIterator();
SecuritySettings.Settings sec = null;
SecuritySettings.Settings hardSec = null;
while (liter.hasNext()) {
sec = liter.next();
if (sec.isDefault()) {
return sec;
}
if (!PDFGConfigHelper.areEqual(ErrorCodeConversion.getErrorString((int)2, (Locale)AESProperties.getLocale()), sec.getName())) continue;
hardSec = sec;
}
if (hardSec != null) {
return hardSec;
}
return sec;
}
return null;
}
static JobOptions.JobOption getDefaultJobOptionSettings(File2PdfSettings editConfig) {
if (editConfig.getJobOptions() != null) {
List<JobOptions.JobOption> joList = editConfig.getJobOptions().getJobOption();
ListIterator<JobOptions.JobOption> liter = joList.listIterator();
JobOptions.JobOption jopt = null;
JobOptions.JobOption hardJopt = null;
while (liter.hasNext()) {
jopt = liter.next();
if (jopt.isDefault()) {
return jopt;
}
if (!PDFGConfigHelper.areEqual(ErrorCodeConversion.getErrorString((int)1, (Locale)AESProperties.getLocale()), jopt.getName())) continue;
hardJopt = jopt;
}
if (hardJopt != null) {
return hardJopt;
}
return jopt;
}
return null;
}
static FiletypeSettings.Settings getDefaultFiletypeSettings(File2PdfSettings editConfig) {
if (editConfig.getFiletypeSettings() != null) {
List<FiletypeSettings.Settings> fsList = editConfig.getFiletypeSettings().getSettings();
ListIterator<FiletypeSettings.Settings> liter = fsList.listIterator();
FiletypeSettings.Settings fset = null;
FiletypeSettings.Settings hardFset = null;
while (liter.hasNext()) {
fset = liter.next();
if (fset.isDefault()) {
return fset;
}
if (!PDFGConfigHelper.areEqual(ErrorCodeConversion.getErrorString((int)3, (Locale)AESProperties.getLocale()), fset.getName())) continue;
hardFset = fset;
}
if (hardFset != null) {
return hardFset;
}
return fset;
}
return null;
}
private static boolean areEqual(String name1, String name2) {
if (PDFGConfigHelper.isEmpty(name1) && PDFGConfigHelper.isEmpty(name2)) {
return true;
}
if (!PDFGConfigHelper.isEmpty(name1) && !PDFGConfigHelper.isEmpty(name2)) {
return name1.equals(name2);
}
return false;
}
private static boolean isEmpty(String str) {
return str == null || str.trim().length() == 0;
}
static byte[] getFileBytes(String filename) throws ConfigException {
try {
int i;
InputStream is = PDFGConfigHelper.getFileInputStream("/" + filename);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((i = is.read()) != -1) {
bos.write(new byte[]{(byte)i});
}
return bos.toByteArray();
}
catch (Exception e) {
throw new ConfigException((Throwable)e);
}
}
static InputStream getFileInputStream(String filename) throws ConfigException {
try {
return PDFGConfigHelper.class.getResourceAsStream(filename);
}
catch (Exception e) {
throw new ConfigException((Throwable)e);
}
}
static PDFGProductInfo getPDFGProductType(String bundleName) throws ConfigException {
return PDFGProductInfo.getInstance();
}
static void setDefaultExportMap(Map m, int type) {
if (type == 0) {
m.put("fsgray", Constants.FT_JPG_COMPRESSION_OPTIONS[2]);
m.put("fscolor", Constants.FT_JPG_COMPRESSION_OPTIONS[2]);
m.put("fsformat", Constants.FT_JPG_FORMAT_OPTIONS[0]);
} else if (type == 1) {
m.put("fsinterl", Constants.FT_PNG_INTERLACE_OPTIONS[0]);
m.put("fsfilter", Constants.FT_PNG_FILTER_OPTIONS[5]);
} else if (type == 2) {
m.put("fsmono", Constants.FT_TIFF_MONOCOMPRESSION_OPTIONS[2]);
m.put("fsgray", Constants.FT_TIFF_CGCOMPRESSION_OPTIONS[1]);
m.put("fscolor", Constants.FT_TIFF_CGCOMPRESSION_OPTIONS[1]);
}
m.put("rgb", Constants.FT_CM_OPTIONS[0]);
m.put("cmyk", Constants.FT_CM_OPTIONS[1]);
m.put("gray", Constants.FT_CM_OPTIONS[1]);
m.put("cspace", Constants.FT_CV_COLORSPACE_OPTIONS[0]);
m.put("resolution", Constants.FT_CV_RESOLUTION_OPTIONS[0]);
}
static void setDefaultAcrobatMap(Map m) {
m.put("useocr", String.valueOf(Boolean.FALSE));
m.put("ocrlanguage", Constants.FT_OCR_LANGUAGE_OPTIONS[8]);
m.put("ocroutputstyle", Constants.FT_OCR_OUTPUTSTYLE_OPTIONS[1]);
m.put("ocrdownsample", Constants.FT_OCR_DOWNSAMPLETYPE_OPTIONS[0]);
}
static long getCurrentTime() {
return System.currentTimeMillis();
}
static FiletypeSettings.Settings createFiletypeSettingObject(boolean isWindows) throws ConfigException {
FiletypeSettings.Settings settings = null;
try {
ObjectFactory factory = new ObjectFactory();
settings = factory.createFiletypeSettingsSettings();
if (isWindows) {
settings.setPDFExport(factory.createFiletypeSettingsSettingsPDFExport());
settings.setAutoCAD(factory.createFiletypeSettingsSettingsAutoCAD());
settings.getAutoCAD().setPDFMaker(factory.createPDFMaker());
settings.setMSExcel(factory.createFiletypeSettingsSettingsMSExcel());
settings.getMSExcel().setPDFMaker(factory.createPDFMaker());
settings.setMSPowerpoint(factory.createFiletypeSettingsSettingsMSPowerpoint());
settings.getMSPowerpoint().setPDFMaker(factory.createPDFMaker());
settings.setMSProject(factory.createFiletypeSettingsSettingsMSProject());
settings.getMSProject().setPDFMaker(factory.createPDFMaker());
settings.setMSVisio(factory.createFiletypeSettingsSettingsMSVisio());
settings.getMSVisio().setPDFMaker(factory.createPDFMaker());
settings.setMSWord(factory.createFiletypeSettingsSettingsMSWord());
settings.getMSWord().setPDFMaker(factory.createPDFMaker());
settings.setMSPublisher(factory.createFiletypeSettingsSettingsMSPublisher());
settings.getMSPublisher().setPDFMaker(factory.createPDFMaker());
settings.setAdobeFlash(factory.createFiletypeSettingsSettingsAdobeFlash());
settings.setXPS(factory.createFiletypeSettingsSettingsXPS());
FiletypeSettings.Settings.Optimizer optimizer = factory.createFiletypeSettingsSettingsOptimizer();
optimizer.setDiscardObjects(factory.createFiletypeSettingsSettingsOptimizerDiscardObjects());
optimizer.setDiscardUserData(factory.createFiletypeSettingsSettingsOptimizerDiscardUserData());
optimizer.setCleanUp(factory.createFiletypeSettingsSettingsOptimizerCleanUp());
FiletypeSettings.Settings.Optimizer.Fonts fontSettings = factory.createFiletypeSettingsSettingsOptimizerFonts();
fontSettings.setUmembeddingOptions(factory.createFiletypeSettingsSettingsOptimizerFontsUmembeddingOptions());
optimizer.setFonts(fontSettings);
optimizer.setTransparency(factory.createFiletypeSettingsSettingsOptimizerTransparency());
settings.setOptimizer(optimizer);
}
settings.setImage(factory.createFiletypeSettingsSettingsImage());
settings.setOpenOffice(factory.createFiletypeSettingsSettingsOpenOffice());
settings.getOpenOffice().setImages(factory.createFiletypeSettingsSettingsOpenOfficeImages());
settings.getOpenOffice().setPages(factory.createFiletypeSettingsSettingsOpenOfficePages());
settings.getOpenOffice().setGeneral(factory.createFiletypeSettingsSettingsOpenOfficeGeneral());
}
catch (Exception e) {
throw new ConfigCreateObjectException(e);
}
return settings;
}
static SecuritySettings.Settings createSecuritySettingObject() throws ConfigException {
SecuritySettings.Settings settings = null;
try {
settings = new ObjectFactory().createSecuritySettingsSettings();
}
catch (Exception e) {
throw new ConfigCreateObjectException(e);
}
return settings;
}
static InitialView createInitialViewObject() throws ConfigException {
InitialView settings = null;
try {
ObjectFactory of = new ObjectFactory();
settings = of.createInitialView();
settings.setDocumentOptions(of.createInitialViewDocumentOptions());
settings.getDocumentOptions().setZoomType(of.createInitialViewDocumentOptionsZoomType());
settings.setWindowOptions(of.createInitialViewWindowOptions());
settings.setUiOptions(of.createInitialViewUiOptions());
}
catch (Exception e) {
throw new ConfigCreateObjectException(e);
}
return settings;
}
static FiletypeSettings.Settings.Html2Pdf createHtml2pdfObject(boolean createIv) throws ConfigException {
FiletypeSettings.Settings.Html2Pdf settings = null;
try {
ObjectFactory factory = new ObjectFactory();
settings = factory.createFiletypeSettingsSettingsHtml2Pdf();
settings.setHtml2PdfSettings(factory.createHtml2PdfSettings());
if (createIv) {
settings.setInitialView(PDFGConfigHelper.createInitialViewObject());
}
}
catch (Exception e) {
throw new ConfigCreateObjectException(e);
}
return settings;
}
static JobOptions.JobOption createJobOptionsObject() throws ConfigException {
JobOptions.JobOption settings = null;
try {
ObjectFactory of = new ObjectFactory();
settings = of.createJobOptionsJobOption();
settings.setInitialView(PDFGConfigHelper.createInitialViewObject());
}
catch (Exception e) {
throw new ConfigCreateObjectException(e);
}
return settings;
}
static void createFiletypeSettingsNode(File2PdfSettings config) throws ConfigException {
try {
ObjectFactory factory = new ObjectFactory();
config.setFiletypeSettings(factory.createFiletypeSettings());
}
catch (Exception e) {
logger.trace(e.getMessage(), (Throwable)e);
throw new ConfigCreateObjectException();
}
}
static File2PdfSettings createExportSettingsObject(boolean filetypes) throws ConfigException {
ObjectFactory factory = new ObjectFactory();
File2PdfSettings exportSettings = null;
try {
exportSettings = factory.createFile2PdfSettings();
exportSettings.setSecuritySettings(factory.createSecuritySettings());
exportSettings.setJobOptions(factory.createJobOptions());
if (filetypes) {
exportSettings.setFiletypeSettings(factory.createFiletypeSettings());
}
}
catch (Exception e) {
throw new ConfigException((Throwable)e);
}
return exportSettings;
}
static void setDefaultInitialViewMap(Map map) {
map.put("documentshow", Constants.IVDEF_DOCUMENTSHOW);
map.put("pagelayout", Constants.IVDEF_PAGELAYOUT);
map.put("magnification", "Default");
map.put("pagenumber", new Integer("1"));
map.put("resizewindow", Constants.IVDEF_RESIZEWINDOW);
map.put("centerwindow", Constants.IVDEF_CENTERWINDOW);
map.put("fullscreenmode", Constants.IVDEF_FULLSCREENMODE);
map.put("windowshow", "Document Title");
map.put("hidemenubar", Constants.IVDEF_HIDEMENUBAR);
map.put("hidetoolbars", Constants.IVDEF_HIDETOOLBARS);
map.put("hidewindowcontrols", Constants.IVDEF_HIDEWINDOWCONTROLS);
}
static int getCompatibility(Integer i) {
return i == null || i < 3 || i > 10 ? 5 : i;
}
static void checkSettingsUsage(String name, File2PdfSettings config, int type) throws ConfigException {
JobSources sources = config.getJobSources();
if (sources != null && sources.getWatchedFolders() != null) {
List<Folder> wf = sources.getWatchedFolders().getFolder();
for (Folder folder : wf) {
if (type == 0) {
if (!name.equals(folder.getSecuritySettings())) continue;
throw new SettingBeingUsedException(folder.getPath(), "jobsource.watched-folder", name, "type.security-setting");
}
if (type == 1) {
if (!name.equals(folder.getJobOptions())) continue;
throw new SettingBeingUsedException(folder.getPath(), "jobsource.watched-folder", name, "type.joboption-setting");
}
if (type != 2 || !name.equals(folder.getFiletypeSettings())) continue;
throw new SettingBeingUsedException(folder.getPath(), "jobsource.watched-folder", name, "type.filetype-setting");
}
}
if (sources != null && sources.getEmailSources() != null) {
List<Pop3Account> es = sources.getEmailSources().getPop3Account();
for (Pop3Account pop3 : es) {
if (type == 0) {
if (!name.equals(pop3.getSecuritySettings())) continue;
throw new SettingBeingUsedException(pop3.getUsername() + "@" + pop3.getHost(), "jobsource.email-source", name, "type.security-setting");
}
if (type == 1) {
if (!name.equals(pop3.getJobOptions())) continue;
throw new SettingBeingUsedException(pop3.getUsername() + "@" + pop3.getHost(), "jobsource.email-source", name, "type.joboption-setting");
}
if (type != 2 || !name.equals(pop3.getFiletypeSettings())) continue;
throw new SettingBeingUsedException(pop3.getUsername() + "@" + pop3.getHost(), "jobsource.email-source", name, "type.filetype-setting");
}
}
}
static String getPassword(String prevPassword, String newPassword, boolean usePassword, boolean passwordChanged, boolean createNew) {
if (!usePassword) {
return "";
}
if (createNew) {
return newPassword;
}
if (passwordChanged) {
return newPassword;
}
return prevPassword;
}
static void checkCompatibility(JobOptions.JobOption jobOptions, SecuritySettings.Settings security, String sourceKey) throws ConfigException, ConversionException {
SettingValidator validator = new SettingValidator(PDFGGlobalCache.getJobOptionsMap(jobOptions.getOptionData()), security);
if (!validator.areJobOptionsCompatible()) {
throw new ConversionException(1016);
}
if (!validator.areSecuritySettingsCompatible()) {
throw new ConversionException(1017);
}
}
static File2PdfSettings.Action getActionTag(String sn, String jn, String fn, int timeout) throws ConfigException {
ObjectFactory factory = new ObjectFactory();
File2PdfSettings.Action action = factory.createFile2PdfSettingsAction();
action.setSecuritySetting(sn);
action.setJobOptionSetting(jn);
if (fn != null) {
action.setFiletypeSetting(fn);
}
action.setTimeout(timeout);
return action;
}
}