GeneratePDFServiceImpl.java 80.5 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 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.aemfd.docmanager.TempFileManager
 *  com.adobe.native2pdf.xml.FiletypeSettings
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$AdobeFlash
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$Html2Pdf
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$Image
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$OpenOffice
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$OpenOffice$General
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$OpenOffice$Images
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$OpenOffice$Pages
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$PDFExport
 *  com.adobe.native2pdf.xml.Html2PdfSettings
 *  com.adobe.native2pdf.xml.InitialView
 *  com.adobe.native2pdf.xml.SecuritySettings
 *  com.adobe.native2pdf.xml.SecuritySettings$Settings
 *  com.adobe.pdfg.common.Constants
 *  com.adobe.pdfg.common.FileUtilities
 *  com.adobe.pdfg.common.Guid
 *  com.adobe.pdfg.common.JobConfiguration
 *  com.adobe.pdfg.common.PDFGGlobalCache
 *  com.adobe.pdfg.common.SettingValidator
 *  com.adobe.pdfg.common.Utils
 *  com.adobe.pdfg.common.Utils$ValidateOption
 *  com.adobe.pdfg.exception.ConfigException
 *  com.adobe.pdfg.exception.ConversionException
 *  com.adobe.pdfg.exception.ErrorCode
 *  com.adobe.pdfg.exception.FileFormatNotSupportedException
 *  com.adobe.pdfg.exception.InvalidParameterException
 *  com.adobe.pdfg.exception.PDFGBaseException
 *  com.adobe.pdfg.logging.PDFGLogger
 *  com.adobe.pdfg.result.CreatePDFResult
 *  com.adobe.pdfg.result.ExportPDFResult
 *  com.adobe.pdfg.result.HtmlToPdfResult
 *  com.adobe.pdfg.result.OptimizePDFResult
 *  com.adobe.pdfg.service.api.GeneratePDFService
 *  com.adobe.pdfg.service.api.PDFGConfigService
 *  com.adobe.service.ConnectionFactory
 *  com.day.cq.dam.handler.gibson.fontmanager.FontManagerService
 *  javax.transaction.TransactionManager
 *  org.apache.commons.io.IOUtils
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.commons.osgi.OsgiUtil
 */
package com.adobe.pdfg.impl;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.aemfd.docmanager.TempFileManager;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.native2pdf.xml.Html2PdfSettings;
import com.adobe.native2pdf.xml.InitialView;
import com.adobe.native2pdf.xml.SecuritySettings;
import com.adobe.pdfg.common.Constants;
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.SettingValidator;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.exception.ConfigException;
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.exception.PDFGBaseException;
import com.adobe.pdfg.impl.GeneratePDFUtil;
import com.adobe.pdfg.impl.Html2PDFConvertorHelper;
import com.adobe.pdfg.impl.Native2PdfCaller;
import com.adobe.pdfg.impl.OpenOffice2PdfCaller;
import com.adobe.pdfg.impl.PaperCaptureCaller;
import com.adobe.pdfg.impl.utils.AdjustableSemaphore;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.postprocess.PdfPostProcessorImpl;
import com.adobe.pdfg.postprocess.PostProcessFileInfo;
import com.adobe.pdfg.result.CreatePDFResult;
import com.adobe.pdfg.result.ExportPDFResult;
import com.adobe.pdfg.result.HtmlToPdfResult;
import com.adobe.pdfg.result.OptimizePDFResult;
import com.adobe.pdfg.service.api.GeneratePDFService;
import com.adobe.pdfg.service.api.PDFGConfigService;
import com.adobe.pdfg.transaction.TransactionTemplate;
import com.adobe.service.ConnectionFactory;
import com.day.cq.dam.handler.gibson.fontmanager.FontManagerService;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.naming.NameNotFoundException;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLHandshakeException;
import javax.transaction.TransactionManager;
import javax.xml.bind.JAXBException;
import org.apache.commons.io.IOUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.omg.CORBA.COMM_FAILURE;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
@Component(metatype=1, immediate=0, label="%pdfg.gen.name", description="%pdfg.gen.description")
@Service(value={GeneratePDFService.class})
public class GeneratePDFServiceImpl
implements GeneratePDFService {
    protected PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(GeneratePDFServiceImpl.class);
    private TransactionTemplate m_txTemplate;
    private static volatile Map m_userMap = null;
    private static String java_awt_headless_set = System.getProperty("java.awt.headless");
    static String acrobatPathValue = System.getenv("Acrobat_PATH");
    static boolean isAcrobatPathValueValid = acrobatPathValue == null ? false : acrobatPathValue.toLowerCase().endsWith("acrobat.exe");
    static boolean doesAcrobatExeExistOnPath = isAcrobatPathValueValid ? new File(acrobatPathValue).exists() : false;
    private static final String UNZIP_FOLDER_NAME = "unzip";
    private static final String FILE_NAME_WITHOUT_EXTN = "fileNameWithoutExtn";
    private static final String FILE_EXTN = "fileExtn";
    private static final String PDFG_HTML2PDF_PRIMARY_ROUTE = "pdfg_html2pdf_primary_route";
    private static final String PDFG_HTML2PDF_SECONDARY_ROUTE = "pdfg_html2pdf_secondary_route";
    private static final String PDFG_ACROBAT_IMAGE_CONVERSION = "pdfg_acrobat_image_conv";
    private static final String PDFG_ACROBAT_AUTOCAD = "pdfg_acrobat_autocad";
    private static final String PDFG_ILLEGAL_CHARACTERS_FILTER = "pdfg_illegal_characters_filter";
    private static final String PDFG_FALLBACK_FONTS = "pdfg_fallback_fonts";
    private static final String PDFG_RETRY_LOGIC = "pdfg_retry_logic";
    private static final String PDFG_INVOCATION_WAIT_TIMEOUT = "pdfg_invocation_wait_timeout";
    private Html2PDFConvertorHelper myConversionHelper = new Html2PDFConvertorHelper();
    private boolean m_useAcrobatImageConversion = false;
    private boolean m_enableAcrobatAutocadConversion = false;
    private int m_swf2pdf_dpi = 110;
    private Native2PdfCaller m_native2PdfCaller = null;
    private OpenOffice2PdfCaller openOffice2PdfCaller = null;
    private PaperCaptureCaller paperCaptureCaller = null;
    private static Map m_productInfo = null;
    private String m_osname = System.getProperty("os.name").toLowerCase();
    private boolean myIsWindows = this.m_osname.indexOf("windows") >= 0;
    private boolean myIsLinux = this.m_osname.indexOf("linux") >= 0;
    private static Pattern m_illegalCharInUsrNamePattern = null;
    private static Matcher m_matcher = null;
    private static boolean m_usrContainsIllegalChar = false;
    private static boolean m_isRegExIllegalCharModified = false;
    private static String m_regExIllegalUserIdFilter = null;
    private static String m_usePDFGHTMLFont = "";
    private boolean myUseWebCapture = false;
    private boolean impersonationPasswordsSet;
    @Reference
    private TransactionManager transactionManager;
    @Reference
    private TempFileManager tfm;
    @Reference
    private FontManagerService fontManager;
    @Reference
    private PDFGConfigService configService;
    @Reference(target="(bmc.service.name=HtmlToPdfSvc)")
    private ConnectionFactory htmlToPdfFactory;
    @Reference(target="(bmc.service.name=Img2PDFSvc)")
    private ConnectionFactory imageToPdfFactory;
    @Reference(target="(bmc.service.name=Native2PDFSvc)")
    private ConnectionFactory nativeToPdfFactory;
    @Reference(target="(bmc.service.name=OpenOffice2PDFSvc)")
    private ConnectionFactory openOfficeToPdfFactory;
    @Reference(target="(bmc.service.name=PaperCaptureSvc)")
    private ConnectionFactory paperCaptureFactory;
    @Reference(target="(bmc.service.name=PDFMakerSvc)")
    private ConnectionFactory pdfMakerFactory;
    private static AdjustableSemaphore htmlToPdfConversionLock = null;
    private static int m_HtmlToPdfPoolSize = 4;
    private static final int DEFAULT_HTML_TO_PDF_POOL_SIZE = 4;
    @Property(intValue={4})
    private static final String HTML_TO_PDF_POOL_SIZE = "pdfg.htmlToPdfPoolSize";
    private static AdjustableSemaphore paperCaptureConversionLock = null;
    private static int m_PaperCapturePoolSize = 4;
    private static final int DEFAULT_PAPER_CAPTURE_POOL_SIZE = 4;
    @Property(intValue={4})
    private static final String PAPER_CAPTURE_POOL_SIZE = "pdfg.paperCapturePoolSize";

    @Activate
    private void activate(Map<String, Object> config) throws ConfigException {
        int htmlToPdfPoolSize = OsgiUtil.toInteger((Object)config.get("pdfg.htmlToPdfPoolSize"), (int)4);
        int paperCapturePoolSize = OsgiUtil.toInteger((Object)config.get("pdfg.paperCapturePoolSize"), (int)4);
        if (htmlToPdfConversionLock == null) {
            this.setHtmlToPdfPoolSize(htmlToPdfPoolSize);
            this.initializeHtmlToPdfConversionLock();
        } else {
            if (htmlToPdfPoolSize > this.getHtmlToPdfPoolSize()) {
                htmlToPdfConversionLock.release(htmlToPdfPoolSize - this.getHtmlToPdfPoolSize());
            } else if (htmlToPdfPoolSize < this.getHtmlToPdfPoolSize()) {
                htmlToPdfConversionLock.reducePermits(this.getHtmlToPdfPoolSize() - htmlToPdfPoolSize);
            }
            this.setHtmlToPdfPoolSize(htmlToPdfPoolSize);
        }
        if (paperCaptureConversionLock == null) {
            this.setPaperCapturePoolSize(paperCapturePoolSize);
            this.initializePaperCaptureConversionLock();
        } else {
            if (paperCapturePoolSize > this.getPaperCapturePoolSize()) {
                paperCaptureConversionLock.release(paperCapturePoolSize - this.getPaperCapturePoolSize());
            } else if (paperCapturePoolSize < this.getPaperCapturePoolSize()) {
                paperCaptureConversionLock.reducePermits(this.getPaperCapturePoolSize() - paperCapturePoolSize);
            }
            this.setPaperCapturePoolSize(paperCapturePoolSize);
        }
        Map generalConfigMap = this.configService.getGeneralConfigMap();
        this.initConfig(generalConfigMap);
    }

    public void initializeHtmlToPdfConversionLock() {
        htmlToPdfConversionLock = new AdjustableSemaphore(this.getHtmlToPdfPoolSize(), true);
    }

    public void initializePaperCaptureConversionLock() {
        paperCaptureConversionLock = new AdjustableSemaphore(this.getPaperCapturePoolSize(), true);
    }

    private void initConfig(Map<String, String[]> generalConfigMap) {
        String html2pdfPrimaryRoute = generalConfigMap.get("pdfg_html2pdf_primary_route")[0];
        String html2pdfSecondaryRoute = generalConfigMap.get("pdfg_html2pdf_secondary_route")[0];
        boolean useAcrobatImageConversion = Boolean.parseBoolean(generalConfigMap.get("pdfg_acrobat_image_conv")[0]);
        boolean enableAcrobatAutocadConversion = Boolean.parseBoolean(generalConfigMap.get("pdfg_acrobat_autocad")[0]);
        String regExIllegalUserIdFilter = generalConfigMap.get("pdfg_illegal_characters_filter")[0];
        String fallbackFontForHTMLConversions = generalConfigMap.get("pdfg_fallback_fonts")[0];
        String retryLogic = generalConfigMap.get("pdfg_retry_logic")[0];
        this.updatePrimarySecondaryRoute(html2pdfPrimaryRoute, html2pdfSecondaryRoute);
        this.setUseAcrobatImageConversion(useAcrobatImageConversion);
        this.setEnableAcrobatAutocadConversion(enableAcrobatAutocadConversion);
        this.setRegExIllegalUserIdFilter(regExIllegalUserIdFilter);
        this.setFallbackFontForHTMLConversions(fallbackFontForHTMLConversions);
        this.setRetryLogic(retryLogic);
    }

    private void processImpersonationSettings() {
        if (this.impersonationPasswordsSet) {
            return;
        }
        Map credentials = null;
        try {
            credentials = this.configService.getAllValidUsersAccounts();
        }
        catch (ConfigException e) {
            throw new RuntimeException((Throwable)e);
        }
        if (this.myIsWindows) {
            this.pdfMakerFactory.setImpersonationIdentities(credentials);
            this.nativeToPdfFactory.setImpersonationIdentities(credentials);
        }
        this.openOfficeToPdfFactory.setImpersonationIdentities(credentials);
        this.impersonationPasswordsSet = true;
    }

    public void updateGeneralConfig(Map<String, String[]> generalConfig) {
        this.initConfig(generalConfig);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public CreatePDFResult createPDF2(Document inputDoc, String inputFileExtension, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, Document xmpDoc) throws InvalidParameterException, ConversionException, FileFormatNotSupportedException {
        CreatePDFResult ret = new CreatePDFResult();
        Map res = this.createPDFCommon(inputDoc, inputFileExtension, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, xmpDoc, Utils.ValidateOption.VALIDATE_FILE_EXTENSION);
        ret.setCreatedDocument((Document)res.get("ConvertedDoc"));
        Document logDoc = (Document)res.get("LogDoc");
        ret.setLogDocument(logDoc);
        InputStream is = null;
        try {
            block4 : {
                try {
                    if (logDoc == null) break block4;
                    is = logDoc.getInputStream();
                    StringWriter writer = new StringWriter();
                    IOUtils.copy((InputStream)is, (Writer)writer, (String)"UTF-8");
                    String logDocString = writer.toString();
                    this.pdfgLogger.debug("Conversion Log: " + logDocString);
                }
                catch (IOException ioe) {
                    Object var15_16 = null;
                    IOUtils.closeQuietly((InputStream)is);
                    return ret;
                }
            }
            Object var15_15 = null;
            IOUtils.closeQuietly((InputStream)is);
            return ret;
        }
        catch (Throwable var14_18) {
            Object var15_17 = null;
            IOUtils.closeQuietly((InputStream)is);
            throw var14_18;
        }
    }

    public Map createPDF(Document inputDoc, String inputFilename, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, Document xmpDoc) throws InvalidParameterException, ConversionException, FileFormatNotSupportedException {
        return this.createPDFCommon(inputDoc, inputFilename, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, xmpDoc, Utils.ValidateOption.VALIDATE_FILENAME);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    private Map createPDFCommon(Document inputDoc, String inputFilenameOrExtension, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, Document xmpDoc, Utils.ValidateOption validateOption) throws InvalidParameterException, ConversionException, FileFormatNotSupportedException {
        String jobConfigurationString = null;
        String fileAttr = null;
        JobConfiguration config = null;
        boolean debugMsgsLogged = false;
        StringBuilder debugMsgs = null;
        String jobIdentityId = null;
        this.processImpersonationSettings();
        try {
            Map e5;
            block24 : {
                try {
                    try {
                        fileAttr = Utils.validate((Document)inputDoc, (String)inputFilenameOrExtension, (Utils.ValidateOption)validateOption);
                    }
                    catch (InvalidParameterException e) {
                        this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                        fileAttr = "File";
                    }
                    jobIdentityId = fileAttr + new Guid().toString();
                    Utils.threadLocalValue.set(jobIdentityId);
                    debugMsgs = new StringBuilder();
                    this.pdfgLogger.info("\nJob ID for the submitted createPDF job =" + jobIdentityId, "");
                    debugMsgs.append("\nentered GeneratePDFImpl.createPDFCommon() for job=" + jobIdentityId);
                    if (!Utils.isCallerAuthorizedUser()) {
                        throw new ConversionException(80015, "GeneratePDFService.createPDF()");
                    }
                    if (inputDoc == null) {
                        throw new InvalidParameterException(11025);
                    }
                    jobConfigurationString = GeneratePDFUtil.getJobConfigurationString(this.configService, settingsDoc, fileTypeSettings, pdfSettings, securitySettings);
                    debugMsgs.append("\nJobConfigurationString--" + jobConfigurationString + "--for job=" + jobIdentityId);
                    try {
                        config = PDFGGlobalCache.getJobConfiguration((String)jobConfigurationString);
                    }
                    catch (JAXBException e5) {
                        throw new InvalidParameterException(1001, (Throwable)e5);
                    }
                    e5 = this.createPDFInternal(inputDoc, inputFilenameOrExtension, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, xmpDoc, Utils.ValidateOption.VALIDATE_FILENAME, config, fileAttr, jobConfigurationString, false);
                    Object var22_19 = null;
                    if (debugMsgsLogged) return e5;
                    if (debugMsgs == null) break block24;
                }
                catch (Exception e) {
                    Map ex4;
                    ConversionException exc;
                    String lowerCaseName;
                    String addedDetail = "";
                    if (e instanceof ConversionException && (exc = (ConversionException)e).getConversionLog() != null) {
                        addedDetail = exc.getConversionLog();
                    }
                    addedDetail = e.getMessage() + addedDetail;
                    this.pdfgLogger.info("Conversion failed : " + addedDetail);
                    this.pdfgLogger.debug(e.getMessage(), null, (Throwable)e);
                    if (!(e instanceof PDFGBaseException)) {
                        throw new ConversionException(1000, (Throwable)e);
                    }
                    if (e instanceof FileFormatNotSupportedException) {
                        this.throwpdfgException(e);
                    }
                    if (e instanceof InvalidParameterException) {
                        this.throwpdfgException(e);
                    }
                    this.pdfgLogger.info("Trying to find a fallback route if available");
                    try {
                        Serializable appConfig;
                        String extn;
                        FiletypeSettings.Settings fileSettings = config.getFiletypeSettings();
                        if (fileSettings == null) {
                            this.pdfgLogger.info("No filetype settings specified. Cannot try fallback route");
                            this.throwpdfgException(e);
                        }
                        if ((appConfig = config.getAppConfigByExtension(fileSettings, extn = (lowerCaseName = fileAttr.toLowerCase()).substring(lowerCaseName.lastIndexOf(".") + 1), true)) == null) {
                            this.pdfgLogger.info("Couldn't obtain fallback filetype setting. Cannot try fallback route");
                            this.throwpdfgException(e);
                        } else {
                            this.pdfgLogger.info("fallback appconfig found :" + appConfig.getClass().getName());
                        }
                    }
                    catch (Exception ex4) {
                        this.pdfgLogger.trace(ex4.getMessage(), null, (Throwable)ex4);
                        this.throwpdfgException(e);
                    }
                    try {
                        ex4 = this.createPDFInternal(inputDoc, inputFilenameOrExtension, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, xmpDoc, Utils.ValidateOption.VALIDATE_FILENAME, config, fileAttr, jobConfigurationString, true);
                    }
                    catch (Exception e1) {
                        this.throwpdfgFallbackException(e, e1);
                        lowerCaseName = null;
                        Object var22_21 = null;
                        if (debugMsgsLogged) return lowerCaseName;
                        if (debugMsgs != null) {
                            this.pdfgLogger.debug(debugMsgs.toString());
                            return lowerCaseName;
                        }
                        return lowerCaseName;
                    }
                    Object var22_20 = null;
                    if (debugMsgsLogged) return ex4;
                    if (debugMsgs != null) {
                        this.pdfgLogger.debug(debugMsgs.toString());
                        return ex4;
                    }
                    return ex4;
                }
                this.pdfgLogger.debug(debugMsgs.toString());
                return e5;
            }
            return e5;
        }
        catch (Throwable var21_30) {
            Object var22_22 = null;
            if (!debugMsgsLogged && debugMsgs != null) {
                this.pdfgLogger.debug(debugMsgs.toString());
                debugMsgsLogged = true;
            }
            throw var21_30;
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private Map createPDFInternal(Document inputDoc, String inputFilenameOrExtension, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, Document xmpDoc, Utils.ValidateOption validateOption, JobConfiguration config, String fileAttr, String jobConfigurationString, boolean tryFallback) throws InvalidParameterException, ConversionException, FileFormatNotSupportedException {
        Object fileSettings;
        String jobIdentityId;
        block36 : {
            Map resultMap;
            String lowerCaseName;
            boolean debugMsgsLogged;
            StringBuilder debugMsgs;
            block30 : {
                Map map;
                block35 : {
                    Serializable appConfig;
                    String extn;
                    block33 : {
                        Map pdfInputDoc;
                        block34 : {
                            block31 : {
                                Map map2;
                                block32 : {
                                    debugMsgsLogged = false;
                                    debugMsgs = new StringBuilder();
                                    jobIdentityId = null;
                                    resultMap = null;
                                    if (config == null) break block30;
                                    debugMsgs.append("\nJobConfiguration object is not null for job=" + jobIdentityId);
                                    fileSettings = config.getFiletypeSettings();
                                    if (fileSettings == null) break block30;
                                    lowerCaseName = fileAttr.toLowerCase();
                                    int indexOfDot = lowerCaseName.lastIndexOf(".");
                                    extn = "";
                                    if (indexOfDot != -1) {
                                        extn = lowerCaseName.substring(indexOfDot + 1);
                                    }
                                    if ((appConfig = config.getAppConfigByExtension((FiletypeSettings.Settings)fileSettings, extn, tryFallback)) instanceof FiletypeSettings.Settings.AdobeFlash) {
                                        this.m_swf2pdf_dpi = ((FiletypeSettings.Settings.AdobeFlash)appConfig).getDpi();
                                        break block30;
                                    }
                                    if (!this.myIsWindows || !(appConfig instanceof FiletypeSettings.Settings.PDFExport) || !fileSettings.getImage().isUseOCR()) break block31;
                                    if (this.paperCaptureCaller == null) {
                                        this.paperCaptureCaller = new PaperCaptureCaller();
                                    }
                                    map2 = this.paperCaptureCaller.createPDF(this, inputDoc, fileAttr, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, jobConfigurationString, xmpDoc);
                                    Object var42_26 = null;
                                    if (debugMsgsLogged) break block32;
                                    this.pdfgLogger.debug(debugMsgs.toString());
                                }
                                this.pdfgLogger.debug("returned after executing xxxCaller.createPDF(). Exiting GeneratePDFImpl for job=" + jobIdentityId);
                                return map2;
                            }
                            if (!(appConfig instanceof FiletypeSettings.Settings.Image)) break block33;
                            if (this.m_native2PdfCaller == null) {
                                this.m_native2PdfCaller = new Native2PdfCaller();
                            }
                            resultMap = this.m_native2PdfCaller.createPDF(this, inputDoc, fileAttr, false, null, settingsDoc, jobConfigurationString, xmpDoc, tryFallback);
                            resultMap = this.setContentTypeInDocuments(resultMap);
                            if (fileSettings.getImage().isUseOCR()) {
                                pdfInputDoc = (Document)resultMap.get("ConvertedDoc");
                                int dotIndex = fileAttr.lastIndexOf(".");
                                String pdfFileAttr = (dotIndex == -1 ? fileAttr : fileAttr.substring(0, dotIndex)) + ".pdf";
                                resultMap = this.createPDFInternal((Document)pdfInputDoc, inputFilenameOrExtension, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, xmpDoc, validateOption, config, pdfFileAttr, jobConfigurationString, tryFallback);
                            }
                            pdfInputDoc = resultMap;
                            Object var42_27 = null;
                            if (debugMsgsLogged) break block34;
                            this.pdfgLogger.debug(debugMsgs.toString());
                        }
                        this.pdfgLogger.debug("returned after executing xxxCaller.createPDF(). Exiting GeneratePDFImpl for job=" + jobIdentityId);
                        return pdfInputDoc;
                    }
                    if (!(appConfig instanceof FiletypeSettings.Settings.OpenOffice)) break block30;
                    debugMsgs.append("\nappConfig instanceof OpenOfficeType for job=" + jobIdentityId);
                    if ("aix".equals(this.m_osname)) {
                        throw new FileFormatNotSupportedException(1015);
                    }
                    if (this.openOffice2PdfCaller == null) {
                        this.openOffice2PdfCaller = new OpenOffice2PdfCaller();
                    }
                    HashMap openOffMap = new HashMap();
                    FiletypeSettings.Settings.OpenOffice openOfficeType = fileSettings.getOpenOffice();
                    FiletypeSettings.Settings.OpenOffice.Pages pages = openOfficeType.getPages();
                    FiletypeSettings.Settings.OpenOffice.General general = openOfficeType.getGeneral();
                    FiletypeSettings.Settings.OpenOffice.Images images = openOfficeType.getImages();
                    String range = pages.getRange();
                    String rangeValue = pages.getRangeValue();
                    if (range == null || !range.equalsIgnoreCase(Constants.RANGE_OPTIONS[1]) || rangeValue == null) {
                        rangeValue = null;
                    }
                    String losslessCompression = "false";
                    String compression = images.getCompression();
                    int compressionValue = images.getCompressionValue();
                    if (compression.equalsIgnoreCase(Constants.COMPRESSION_OPTIONS[0])) {
                        losslessCompression = "true";
                    }
                    String isLandscape = "false";
                    String pageOrientation = openOfficeType.getPageOrientation();
                    if (pageOrientation != null && pageOrientation.equalsIgnoreCase("Landscape")) {
                        isLandscape = "true";
                    }
                    int reduceImageResolutionValue = images.getReduceImageResolutionValue();
                    String exportNotes = "false";
                    String exportNotesPages = "false";
                    if (general.isExportNotes().booleanValue()) {
                        if (extn.equalsIgnoreCase("ppt")) {
                            exportNotesPages = "true";
                        } else {
                            exportNotes = "true";
                        }
                    }
                    String formsTypeInt = "-1";
                    String formsFormat = general.getFormsFormat();
                    if (!(general.isSetCreatePDFA() && general.isCreatePDFA().booleanValue() || formsFormat == null)) {
                        if (formsFormat.equalsIgnoreCase(Constants.FORMS_FORMAT_OPTIONS[0])) {
                            formsTypeInt = "0";
                        } else if (formsFormat.equalsIgnoreCase(Constants.FORMS_FORMAT_OPTIONS[1])) {
                            formsTypeInt = "1";
                        } else if (formsFormat.equalsIgnoreCase(Constants.FORMS_FORMAT_OPTIONS[2])) {
                            formsTypeInt = "2";
                        } else if (formsFormat.equalsIgnoreCase(Constants.FORMS_FORMAT_OPTIONS[3])) {
                            formsTypeInt = "3";
                        }
                    }
                    String[] arrstring = new String[12];
                    arrstring[0] = rangeValue;
                    arrstring[1] = losslessCompression;
                    arrstring[2] = "" + compressionValue + "";
                    arrstring[3] = "" + reduceImageResolutionValue + "";
                    arrstring[4] = "" + general.isTaggedPDF();
                    arrstring[5] = exportNotes;
                    arrstring[6] = exportNotesPages;
                    arrstring[7] = "" + general.isUseTransitionEffects();
                    arrstring[8] = formsTypeInt;
                    arrstring[9] = "" + (general.isExportBlankPages() == false);
                    arrstring[10] = "" + general.isCreatePDFA();
                    arrstring[11] = isLandscape;
                    String[] openOfficeData = arrstring;
                    debugMsgs.append("\ncalling openOffice2PdfCaller.createPDF() for job=" + jobIdentityId);
                    this.pdfgLogger.debug(debugMsgs.toString());
                    debugMsgsLogged = true;
                    resultMap = this.openOffice2PdfCaller.createPDF(this, inputDoc, fileAttr, fileTypeSettings, pdfSettings, securitySettings, settingsDoc, jobConfigurationString, xmpDoc, openOfficeData);
                    map = resultMap = this.setContentTypeInDocuments(resultMap);
                    Object var42_28 = null;
                    if (debugMsgsLogged) break block35;
                    this.pdfgLogger.debug(debugMsgs.toString());
                }
                this.pdfgLogger.debug("returned after executing xxxCaller.createPDF(). Exiting GeneratePDFImpl for job=" + jobIdentityId);
                return map;
            }
            try {
                this.checkExtension(fileAttr);
                if (this.m_native2PdfCaller == null) {
                    this.m_native2PdfCaller = new Native2PdfCaller();
                }
                debugMsgs.append("\ncalling native2PdfCaller.createPDF() for job=" + jobIdentityId);
                this.pdfgLogger.debug(debugMsgs.toString());
                debugMsgsLogged = true;
                resultMap = this.m_native2PdfCaller.createPDF(this, inputDoc, fileAttr, false, null, settingsDoc, jobConfigurationString, xmpDoc, tryFallback);
                resultMap = this.setContentTypeInDocuments(resultMap);
                fileSettings = resultMap;
                Object var42_29 = null;
                if (debugMsgsLogged) break block36;
            }
            catch (Exception e) {
                block37 : {
                    try {
                        this.pdfgLogger.severe(e.getMessage(), "");
                        this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                        this.throwpdfgException(e);
                        lowerCaseName = null;
                        Object var42_30 = null;
                        if (debugMsgsLogged) break block37;
                    }
                    catch (Throwable var41_52) {
                        Object var42_31 = null;
                        if (!debugMsgsLogged) {
                            this.pdfgLogger.debug(debugMsgs.toString());
                        }
                        this.pdfgLogger.debug("returned after executing xxxCaller.createPDF(). Exiting GeneratePDFImpl for job=" + jobIdentityId);
                        throw var41_52;
                    }
                    this.pdfgLogger.debug(debugMsgs.toString());
                }
                this.pdfgLogger.debug("returned after executing xxxCaller.createPDF(). Exiting GeneratePDFImpl for job=" + jobIdentityId);
                return lowerCaseName;
            }
            this.pdfgLogger.debug(debugMsgs.toString());
        }
        this.pdfgLogger.debug("returned after executing xxxCaller.createPDF(). Exiting GeneratePDFImpl for job=" + jobIdentityId);
        return fileSettings;
    }

    private void throwpdfgException(Exception e) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        if (e instanceof ConversionException) {
            throw (ConversionException)e;
        }
        if (e instanceof FileFormatNotSupportedException) {
            throw (FileFormatNotSupportedException)e;
        }
        if (e instanceof InvalidParameterException) {
            throw (InvalidParameterException)e;
        }
        if (e instanceof PDFGBaseException) {
            throw new ConversionException(((PDFGBaseException)e).getErrorCode());
        }
        throw new ConversionException(1000, (Throwable)e);
    }

    private void throwpdfgFallbackException(Exception mainRouteException, Exception fallbackConverterException) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        PDFGBaseException fallbackPBE = null;
        PDFGBaseException mainroutePBE = null;
        mainroutePBE = mainRouteException instanceof PDFGBaseException ? (PDFGBaseException)mainRouteException : new ConversionException(1000, (Throwable)mainRouteException);
        fallbackPBE = fallbackConverterException instanceof PDFGBaseException ? (PDFGBaseException)fallbackConverterException : new ConversionException(1000, (Throwable)fallbackConverterException);
        mainroutePBE.setFallbackConversionException(fallbackPBE);
        this.throwpdfgException((Exception)mainroutePBE);
    }

    private Map setContentTypeInDocuments(Map resultMap) {
        Document logDoc;
        Document convertedDoc = (Document)resultMap.get("ConvertedDoc");
        if (convertedDoc != null) {
            convertedDoc.setContentType("application/pdf");
        }
        if ((logDoc = (Document)resultMap.get("LogDoc")) != null) {
            logDoc.setContentType("text/plain");
        }
        resultMap.put("ConvertedDoc", convertedDoc);
        resultMap.put("LogDoc", logDoc);
        return resultMap;
    }

    public boolean isImageExtension(String ext) {
        if (Constants.VALID_IMAGE_EXTENSION_MAP.get(ext.toLowerCase()) != null) {
            return true;
        }
        return false;
    }

    public String getImageDecoderType(String ext) {
        return (String)Constants.VALID_IMAGE_EXTENSION_MAP.get(ext.toLowerCase());
    }

    public void pdfPostProcess(PostProcessFileInfo filePaths, String attachmentName, InitialView initialView, SecuritySettings.Settings encryptionSettings, boolean doWebOptimization, String targetPdfVersion, String pdfProducerString, boolean applyWatermark) throws ConversionException {
        PdfPostProcessorImpl pdfPostProcessor;
        int errorCode;
        if (filePaths.xmpFilePath == null) {
            filePaths.xmpFilePath = "";
        }
        if (filePaths.attachmentFilePath == null) {
            filePaths.attachmentFilePath = "";
        }
        if (filePaths.logFilePath == null) {
            filePaths.logFilePath = "";
        }
        if (attachmentName == null) {
            attachmentName = "";
        }
        if (targetPdfVersion == null) {
            targetPdfVersion = "";
        }
        if (pdfProducerString == null) {
            pdfProducerString = "";
        }
        if ((errorCode = (pdfPostProcessor = new PdfPostProcessorImpl()).doPostProcess(filePaths, attachmentName, initialView, encryptionSettings, doWebOptimization, false, false, targetPdfVersion, false, pdfProducerString, 1, applyWatermark)) != 0) {
            throw new ConversionException(errorCode);
        }
    }

    private void checkExtension(String fileName) throws FileFormatNotSupportedException {
        String lowerCaseName = fileName.toLowerCase();
        if (lowerCaseName.endsWith(".ps") || lowerCaseName.endsWith(".eps") || lowerCaseName.endsWith(".prn")) {
            throw new FileFormatNotSupportedException(1015, "PostScript and Enhanced PostScript are not supported");
        }
    }

    String getLicenceString() {
        this.initializeProductInfo();
        String licenseType = null;
        if (m_productInfo != null) {
            licenseType = (String)m_productInfo.get("PDFG_LICENSE_TYPE");
        }
        return licenseType;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private void initializeProductInfo() {
        if (m_productInfo != null) return;
        Class<GeneratePDFServiceImpl> class_ = GeneratePDFServiceImpl.class;
        synchronized (GeneratePDFServiceImpl.class) {
            if (m_productInfo != null) return;
            {
                try {
                    m_productInfo = this.configService.getPDFGProductInfo();
                }
                catch (Exception ex) {
                    this.pdfgLogger.trace("Problem in getting product info: " + ex.getMessage(), null, (Throwable)ex);
                }
            }
            // ** MonitorExit[var1_1] (shouldn't be in output)
            return;
        }
    }

    String getOSName() {
        return this.m_osname;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public HtmlToPdfResult htmlFileToPdf(Document inputDoc, String fileTypeSettingsName, String securitySettingsName, Document settingsDoc, Document xmpDoc) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        boolean success = true;
        File pdfgTmpDir = null;
        String urlName = null;
        String inputFileOrURLName = null;
        int spideringLevel = -1;
        int GET_ENTIRE_SITE = 100;
        String guidString = null;
        try {
            HtmlToPdfResult htmlToPdfResult;
            try {
                String inputFileExtn;
                if (inputDoc == null) {
                    throw new InvalidParameterException(11025);
                }
                String contentType = inputDoc.getContentType();
                try {
                    inputFileOrURLName = Utils.validateFilename((Document)inputDoc, (String)null);
                }
                catch (InvalidParameterException e) {
                    this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                    if (contentType == null || "".equals(contentType.trim()) || contentType.equalsIgnoreCase("application/zip") || contentType.equalsIgnoreCase("application/octet-stream")) {
                        inputFileOrURLName = "File.zip";
                    }
                    if (!contentType.equalsIgnoreCase("text/html")) {
                        throw e;
                    }
                    inputFileOrURLName = "File.html";
                }
                guidString = new Guid().toString();
                Utils.threadLocalValue.set(guidString);
                Map<String, String> fileNameAttr = this.getFileNameAttributes(inputFileOrURLName);
                String orginalInputFileExtn = inputFileExtn = fileNameAttr.get("fileExtn");
                String inputFileNameWithoutExtn = fileNameAttr.get("fileNameWithoutExtn");
                if (!(inputFileExtn.equalsIgnoreCase("htm") || inputFileExtn.equalsIgnoreCase("html") || inputFileExtn.equalsIgnoreCase("txt") || inputFileExtn.equalsIgnoreCase("zip"))) {
                    if (contentType == null || "".equals(contentType.trim()) || contentType.equalsIgnoreCase("application/zip") || contentType.equalsIgnoreCase("application/octet-stream")) {
                        inputFileExtn = "zip";
                        inputFileOrURLName = inputFileNameWithoutExtn + ".zip";
                    } else if (contentType.equalsIgnoreCase("text/html")) {
                        inputFileExtn = "html";
                        inputFileOrURLName = inputFileNameWithoutExtn + ".html";
                    } else {
                        if (!contentType.equalsIgnoreCase("text/plain")) {
                            throw new InvalidParameterException(80020);
                        }
                        inputFileExtn = "txt";
                        inputFileOrURLName = inputFileNameWithoutExtn + ".txt";
                    }
                }
                this.pdfgLogger.info("\nJob ID for the submitted htmlFileToPDF job =" + guidString, "");
                try {
                    pdfgTmpDir = FileUtilities.createGuidDir((String)guidString);
                }
                catch (IOException ioe) {
                    throw new ConversionException(1003, (Throwable)ioe);
                }
                File tmpInputFile = new File(pdfgTmpDir, inputFileOrURLName);
                inputDoc.copyToFile(tmpInputFile);
                if (inputFileExtn.equalsIgnoreCase("zip")) {
                    File unzipFolder = new File(pdfgTmpDir, "unzip");
                    unzipFolder.mkdirs();
                    this.extractZipFile(tmpInputFile, unzipFolder);
                    File indexFile = this.getIndexFileInDir(unzipFolder);
                    if (indexFile == null) {
                        throw new ConversionException(80019, inputFileNameWithoutExtn + "." + orginalInputFileExtn);
                    }
                    urlName = indexFile.toURI().toURL().toExternalForm();
                } else {
                    if (!(inputFileExtn.equalsIgnoreCase("htm") || inputFileExtn.equalsIgnoreCase("html") || inputFileExtn.equalsIgnoreCase("txt"))) {
                        throw new FileFormatNotSupportedException(1015, inputFileExtn);
                    }
                    urlName = tmpInputFile.toURI().toURL().toExternalForm();
                }
                Map map = this.htmlURLToPdf(urlName, fileTypeSettingsName, securitySettingsName, settingsDoc, xmpDoc, pdfgTmpDir, spideringLevel, false);
                HtmlToPdfResult ret = new HtmlToPdfResult();
                Document convertedDoc = (Document)map.get("ConvertedDoc");
                convertedDoc.setAttribute("file", (Object)(inputFileNameWithoutExtn + ".pdf"));
                ret.setCreatedDocument(convertedDoc);
                htmlToPdfResult = ret;
                Object var24_30 = null;
                if (pdfgTmpDir == null) return htmlToPdfResult;
            }
            catch (ConversionException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw e;
            }
            catch (InvalidParameterException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw e;
            }
            catch (FileFormatNotSupportedException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw e;
            }
            catch (PDFGBaseException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw new ConversionException(e.getErrorCode());
            }
            catch (Exception e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw new ConversionException(1000, (Throwable)e);
            }
            GeneratePDFServiceImpl.deleteSubFiles(pdfgTmpDir);
            return htmlToPdfResult;
        }
        catch (Throwable var23_32) {
            Object var24_31 = null;
            if (pdfgTmpDir != null) {
                GeneratePDFServiceImpl.deleteSubFiles(pdfgTmpDir);
            }
            throw var23_32;
        }
    }

    private Map<String, String> getFileNameAttributes(String inputFileOrURLName) {
        HashMap<String, String> fileNameAttr = new HashMap<String, String>();
        int fileExtStartPoint = inputFileOrURLName.lastIndexOf(".");
        String inputFileNameWithoutExtn = inputFileOrURLName;
        String inputFileExtn = "";
        if (fileExtStartPoint != -1) {
            inputFileNameWithoutExtn = inputFileOrURLName.substring(0, fileExtStartPoint);
            inputFileExtn = inputFileOrURLName.toLowerCase().substring(fileExtStartPoint + 1);
        }
        fileNameAttr.put("fileNameWithoutExtn", inputFileNameWithoutExtn);
        fileNameAttr.put("fileExtn", inputFileExtn);
        return fileNameAttr;
    }

    private boolean isURL(Document inputDoc) {
        String urlName = (String)inputDoc.getAttribute("url");
        return urlName != null;
    }

    private File getIndexFileInDir(File pdfgTmpDir) {
        File[] filesList = pdfgTmpDir.listFiles();
        if (filesList != null && filesList.length != 0) {
            int noOfFiles = filesList.length;
            File firstFile = filesList[0];
            if (noOfFiles == 1 && firstFile.isDirectory()) {
                return this.getIndexFileInDir(firstFile);
            }
            int noOfHtmlFiles = 0;
            File lastHtmlFile = null;
            for (int i = 0; i < noOfFiles; ++i) {
                File file = filesList[i];
                String fileName = file.getName().toLowerCase();
                if (file.isDirectory() || !fileName.endsWith(".html") && !fileName.endsWith(".htm")) continue;
                if (fileName.equals("index.html") || fileName.equals("index.htm")) {
                    return file;
                }
                ++noOfHtmlFiles;
                lastHtmlFile = file;
            }
            if (noOfHtmlFiles == 1) {
                return lastHtmlFile;
            }
        }
        return null;
    }

    /*
     * Unable to fully structure code
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Lifted jumps to return sites
     */
    private void extractZipFile(File inputFile, File destinationFolder) throws Exception {
        zipInputStream = null;
        zipEntry = null;
        fileOutputStream = null;
        try {
            block22 : {
                try {
                    buf = new byte[1024];
                    zipInputStream = new ZipInputStream(new FileInputStream(inputFile));
                    zipEntry = zipInputStream.getNextEntry();
                    while (zipEntry != null) {
                        entryName = zipEntry.getName();
                        fileOutputStream = null;
                        newFile = new File(destinationFolder, entryName);
                        if (!newFile.getCanonicalPath().startsWith(destinationFolder.getCanonicalPath())) {
                            throw new ConversionException(80035);
                        }
                        if (zipEntry.isDirectory()) {
                            if (!newFile.exists()) {
                                newFile.mkdirs();
                            }
                            zipEntry = zipInputStream.getNextEntry();
                            continue;
                        }
                        if (newFile.exists()) {
                            newFile.delete();
                        }
                        if ((parentFile = newFile.getParentFile()) != null && !parentFile.exists()) {
                            parentFile.mkdirs();
                        }
                        newFile.createNewFile();
                        fileOutputStream = new FileOutputStream(newFile);
                        while ((noOfBytesRead = zipInputStream.read(buf)) > -1) {
                            fileOutputStream.write(buf, 0, noOfBytesRead);
                        }
                        fileOutputStream.close();
                        zipInputStream.closeEntry();
                        zipEntry = zipInputStream.getNextEntry();
                    }
                    var12_13 = null;
                    if (fileOutputStream == null) break block22;
                }
                catch (Exception e2) {
                    if (e2 instanceof ConversionException) {
                        throw e2;
                    }
                    errMsg = e2.getMessage();
                    if (errMsg != null) throw new ConversionException(80021, errMsg, (Throwable)e2);
                    errMsg = "";
                    throw new ConversionException(80021, errMsg, (Throwable)e2);
                }
                try {
                    fileOutputStream.close();
                }
                catch (Exception e) {
                    this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                }
            }
            if (zipInputStream == null) return;
            try {
                zipInputStream.closeEntry();
            }
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            }
            try {
                zipInputStream.close();
                return;
            }
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                return;
            }
        }
        catch (Throwable throwable) {
            block24 : {
                var12_14 = null;
                if (fileOutputStream != null) {
                    ** try [egrp 2[TRYBLOCK] [3 : 288->296)] { 
lbl66: // 1 sources:
                    fileOutputStream.close();
                    break block24;
lbl68: // 1 sources:
                    catch (Exception e) {
                        this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                    }
                }
            }
            if (zipInputStream == null) throw throwable;
            ** try [egrp 3[TRYBLOCK] [4 : 317->324)] { 
lbl73: // 1 sources:
            zipInputStream.closeEntry();
            ** GOTO lbl77
lbl75: // 1 sources:
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            }
lbl77: // 2 sources:
            ** try [egrp 4[TRYBLOCK] [5 : 341->348)] { 
lbl78: // 1 sources:
            zipInputStream.close();
            throw throwable;
lbl80: // 1 sources:
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            }
            throw throwable;
        }
    }

    public HtmlToPdfResult htmlToPdf2(String inputUrl, String fileTypeSettingsName, String securitySettingsName, Document settingsDoc, Document xmpDoc) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        boolean urlExists = false;
        if (inputUrl != null) {
            if (!inputUrl.trim().equals("") && inputUrl.toLowerCase().indexOf("http://") == -1 && inputUrl.toLowerCase().indexOf("https://") == -1) {
                inputUrl = "http://" + inputUrl.trim();
            }
            if (inputUrl.toLowerCase().indexOf("http://") == 0) {
                try {
                    HttpURLConnection.setFollowRedirects(true);
                    HttpURLConnection httpcon = (HttpURLConnection)new URL(inputUrl).openConnection();
                    httpcon.setRequestMethod("HEAD");
                    if (httpcon.getResponseCode() == 200) {
                        urlExists = true;
                    }
                }
                catch (Exception e) {
                    this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                }
            }
            if (inputUrl.toLowerCase().indexOf("https://") == 0 || !urlExists) {
                String testhttps = inputUrl;
                if (inputUrl.toLowerCase().indexOf("http://") == 0) {
                    testhttps = "https://" + inputUrl.substring(7);
                }
                try {
                    HttpsURLConnection.setFollowRedirects(true);
                    HttpsURLConnection httpscon = (HttpsURLConnection)new URL(testhttps).openConnection();
                    if (httpscon.getResponseCode() == 200) {
                        urlExists = true;
                    }
                }
                catch (UnknownHostException uhexception) {
                    this.pdfgLogger.trace(uhexception.getMessage(), null, (Throwable)uhexception);
                }
                catch (SSLHandshakeException sslException) {
                    this.pdfgLogger.trace(sslException.getMessage(), null, (Throwable)sslException);
                    urlExists = true;
                }
                catch (IOException ioexception) {
                    this.pdfgLogger.trace(ioexception.getMessage(), null, (Throwable)ioexception);
                    if (ioexception.getMessage().startsWith("HTTPS hostname wrong")) {
                        urlExists = true;
                    }
                }
                catch (Exception e) {
                    this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                }
            }
        }
        if (urlExists) {
            Map res = this.htmlToPdf(inputUrl, fileTypeSettingsName, securitySettingsName, settingsDoc, xmpDoc);
            HtmlToPdfResult ret = new HtmlToPdfResult();
            ret.setCreatedDocument((Document)res.get("ConvertedDoc"));
            return ret;
        }
        ConversionException convException = new ConversionException(ErrorCode.HTML_URL_INVALID_ERROR);
        this.pdfgLogger.info("Conversion failed : " + convException.getMessage());
        throw convException;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public Map htmlToPdf(String inputUrl, String fileTypeSettingsName, String securitySettingsName, Document settingsDoc, Document xmpDoc) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        boolean success = true;
        String guidString = new Guid().toString();
        Utils.threadLocalValue.set(guidString);
        File pdfgTmpDir = null;
        try {
            Map ioe2;
            try {
                this.pdfgLogger.info("\nJob ID for the submitted htmlToPDF job =" + guidString, "");
                try {
                    pdfgTmpDir = FileUtilities.createGuidDir((String)guidString);
                }
                catch (IOException ioe2) {
                    throw new ConversionException(1003, (Throwable)ioe2);
                }
                ioe2 = this.htmlURLToPdf(inputUrl, fileTypeSettingsName, securitySettingsName, settingsDoc, xmpDoc, pdfgTmpDir, -1, true);
                Object var11_15 = null;
                if (pdfgTmpDir == null) return ioe2;
            }
            catch (ConversionException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw e;
            }
            catch (InvalidParameterException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw e;
            }
            catch (PDFGBaseException e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                throw new ConversionException(e.getErrorCode());
            }
            catch (Exception e) {
                this.pdfgLogger.severe(e.getMessage(), "");
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                success = false;
                if (e instanceof COMM_FAILURE) {
                    throw new ConversionException(10010, (Throwable)e);
                }
                throw new ConversionException(1000, (Throwable)e);
            }
            GeneratePDFServiceImpl.deleteSubFiles(pdfgTmpDir);
            return ioe2;
        }
        catch (Throwable var10_17) {
            Object var11_16 = null;
            if (pdfgTmpDir != null) {
                GeneratePDFServiceImpl.deleteSubFiles(pdfgTmpDir);
            }
            throw var10_17;
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    private Map htmlURLToPdf(String inputUrl, String fileTypeSettingsName, String securitySettingsName, Document settingsDoc, Document xmpDoc, File pdfgTmpDir, int spideringLevel, boolean isURL) throws ConversionException, InvalidParameterException, PDFGBaseException, Exception {
        if (!Utils.isCallerAuthorizedUser()) {
            throw new ConversionException(80015, "GeneratePDFService.htmlToPDF()");
        }
        String configString = GeneratePDFUtil.getJobConfigurationString(this.configService, settingsDoc, fileTypeSettingsName, null, securitySettingsName);
        JobConfiguration config = null;
        try {
            config = PDFGGlobalCache.getJobConfiguration((String)configString);
        }
        catch (Exception e) {
            throw new InvalidParameterException(1001, (Throwable)e);
        }
        if (config == null) {
            throw new InvalidParameterException(80001);
        }
        SecuritySettings.Settings security = config.getSecuritySettings();
        boolean shouldApplySecurity = Utils.shouldApplySecurity((SecuritySettings.Settings)security);
        if (shouldApplySecurity) {
            SettingValidator validator = new SettingValidator(null, security);
            if (validator.areEncryptionPasswordsIdentical()) {
                throw new InvalidParameterException(80009);
            }
            GeneratePDFUtil.updateSecuritySettings(this.configService, security);
        }
        boolean debugMsgsLogged = false;
        Map result = null;
        StringBuilder debugMsgs = new StringBuilder();
        String jobIdentityId = (String)Utils.threadLocalValue.get();
        spideringLevel = config.getFiletypeSettings().getHtml2Pdf().getHtml2PdfSettings().getLevels();
        Html2PDFConvertorHelper.ROUTE primaryRoute = this.myConversionHelper.getPrimaryRoute();
        this.pdfgLogger.info("Trying the primary conversion via " + this.myConversionHelper.getPrimaryRoute().getRouteName());
        try {
            try {
                result = primaryRoute.getRouteProcessor().createPDF(this, inputUrl, fileTypeSettingsName, securitySettingsName, settingsDoc, xmpDoc, configString, pdfgTmpDir, spideringLevel, isURL);
            }
            catch (Exception e) {
                this.pdfgLogger.info("Conversion failed : " + e.getMessage());
                this.pdfgLogger.debug(e.getMessage(), null, (Throwable)e);
                Html2PDFConvertorHelper.ROUTE secondaryRoute = this.myConversionHelper.getSecondaryRoute();
                if (secondaryRoute != null && config.getFiletypeSettings().isSetHtml2Pdf() && config.getFiletypeSettings().getHtml2Pdf().isUseFallback()) {
                    this.pdfgLogger.info("Trying the secondary route conversion as fallback: " + this.myConversionHelper.getSecondaryRoute().getRouteName());
                    try {
                        result = secondaryRoute.getRouteProcessor().createPDF(this, inputUrl, fileTypeSettingsName, securitySettingsName, settingsDoc, xmpDoc, configString, pdfgTmpDir, spideringLevel, isURL);
                    }
                    catch (NameNotFoundException ex3) {
                        this.pdfgLogger.severe("003-011", ex3.getMessage());
                        this.throwpdfgFallbackException(e, (Exception)new ConversionException(52024));
                    }
                    catch (Exception e1) {
                        this.throwpdfgFallbackException(e, e1);
                    }
                    Object var22_21 = null;
                    if (debugMsgsLogged) return result;
                    this.pdfgLogger.debug(debugMsgs.toString());
                    return result;
                }
                this.pdfgLogger.debug("Fallback route disabled.");
                throw e;
            }
            Object var22_20 = null;
            if (debugMsgsLogged) return result;
            this.pdfgLogger.debug(debugMsgs.toString());
            return result;
        }
        catch (Throwable var21_27) {
            Object var22_22 = null;
            if (debugMsgsLogged) throw var21_27;
            this.pdfgLogger.debug(debugMsgs.toString());
            throw var21_27;
        }
    }

    public ExportPDFResult exportPDF2(Document inputDoc, String inputFileExtension, String formatType, Document settingsDoc) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        ExportPDFResult ret = new ExportPDFResult();
        Map res = this.exportPDFCommon(inputDoc, inputFileExtension, formatType, settingsDoc, Utils.ValidateOption.VALIDATE_FILE_EXTENSION);
        ret.setConvertedDocument((Document)res.get("ConvertedDoc"));
        return ret;
    }

    public Map exportPDF(Document inputDoc, String inputFilename, String formatType, Document settingsDoc) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        return this.exportPDFCommon(inputDoc, inputFilename, formatType, settingsDoc, Utils.ValidateOption.VALIDATE_FILENAME);
    }

    public Map exportPDFCommon(Document inputDoc, String inputFilenameOrExtension, String formatType, Document settingsDoc, Utils.ValidateOption validateOption) throws ConversionException, FileFormatNotSupportedException, InvalidParameterException {
        try {
            if (!Utils.isCallerAuthorizedUser()) {
                throw new ConversionException(80015, "GeneratePDFService.convertPDF()");
            }
            String fileName = Utils.validate((Document)inputDoc, (String)inputFilenameOrExtension, (Utils.ValidateOption)validateOption);
            if (formatType == null || "".equals(formatType.trim()) && settingsDoc == null) {
                Map defaultSettingsNames = this.configService.getDefaultSettingsNames();
                Map exportMap = (Map)defaultSettingsNames.get("pdfexportmap");
                formatType = (String)exportMap.get("exportto");
            }
            String jobIdentityId = fileName + new Guid().toString();
            Utils.threadLocalValue.set(jobIdentityId);
            this.pdfgLogger.info("\nJob ID for the submitted exportPDF job =" + jobIdentityId, "");
            return new Native2PdfCaller().exportPDF(this, inputDoc, fileName, formatType, settingsDoc);
        }
        catch (ConversionException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw e;
        }
        catch (FileFormatNotSupportedException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw e;
        }
        catch (InvalidParameterException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw e;
        }
        catch (PDFGBaseException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw new ConversionException(e.getErrorCode());
        }
        catch (Exception e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw new ConversionException(1000, (Throwable)e);
        }
    }

    public OptimizePDFResult optimizePDF(Document inputDoc, String fileTypeSettings, Document settingsDoc) throws ConversionException, InvalidParameterException, FileFormatNotSupportedException {
        try {
            String fileName;
            if (!Utils.isCallerAuthorizedUser()) {
                throw new ConversionException(80015, "GeneratePDFService.optimizePDF()");
            }
            if (inputDoc == null) {
                throw new InvalidParameterException(11025);
            }
            try {
                fileName = Utils.validate((Document)inputDoc, (String)null, (Utils.ValidateOption)Utils.ValidateOption.VALIDATE_FILE_EXTENSION);
            }
            catch (InvalidParameterException e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                fileName = "File.pdf";
            }
            String lowerCaseName = fileName.toLowerCase();
            if (!lowerCaseName.endsWith(".pdf")) {
                throw new FileFormatNotSupportedException(1015, "only PDF supported as input document");
            }
            String jobIdentityId = fileName + new Guid().toString();
            Utils.threadLocalValue.set(jobIdentityId);
            this.pdfgLogger.info("\nJob ID for the submitted optimizePDF job =" + jobIdentityId, "");
            String jobConfigurationString = GeneratePDFUtil.getJobConfigurationString(this.configService, settingsDoc, fileTypeSettings, null, null);
            Map resultMap = new Native2PdfCaller().optimizePDF(this, inputDoc, fileName, jobConfigurationString, settingsDoc);
            OptimizePDFResult result = new OptimizePDFResult();
            result.setConvertedDocument((Document)resultMap.get("ConvertedDoc"));
            return result;
        }
        catch (ConversionException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw e;
        }
        catch (FileFormatNotSupportedException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw e;
        }
        catch (InvalidParameterException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw e;
        }
        catch (PDFGBaseException e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw new ConversionException(e.getErrorCode());
        }
        catch (Exception e) {
            this.pdfgLogger.severe(e.getMessage(), "");
            this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            throw new ConversionException(1000, (Throwable)e);
        }
    }

    protected static void deleteSubFiles(File parentFolder) {
        File[] files = parentFolder.listFiles();
        if (files != null && files.length > 0) {
            for (int i = 0; i < files.length; ++i) {
                if (files[i].isDirectory()) {
                    GeneratePDFServiceImpl.deleteSubFiles(files[i]);
                    continue;
                }
                files[i].delete();
            }
        }
        parentFolder.delete();
    }

    public void setAdobePDFSettings(String adobePDFSettings) {
        if (!"".equals(adobePDFSettings)) {
            GeneratePDFUtil.setPDFSettings(adobePDFSettings);
        }
    }

    public void setSecuritySettings(String securitySettings) {
        if (!"".equals(securitySettings)) {
            GeneratePDFUtil.setSecuritySettings(securitySettings);
        }
    }

    public void setFileTypeSettings(String fileTypeSettings) {
        if (!"".equals(fileTypeSettings)) {
            GeneratePDFUtil.setFiletypeSettings(fileTypeSettings);
        }
    }

    public void setImageToPDFPoolSize(int poolSize) {
        if (poolSize > 0) {
            Native2PdfCaller.IMAGE_TO_PDF_POOL_SIZE = poolSize;
        }
    }

    public int getHtmlToPdfPoolSize() {
        return m_HtmlToPdfPoolSize;
    }

    public void setHtmlToPdfPoolSize(int poolSize) {
        if (poolSize > 0 && m_HtmlToPdfPoolSize != poolSize) {
            m_HtmlToPdfPoolSize = poolSize;
        }
    }

    public AdjustableSemaphore getHtmlToPdfConversionLock() {
        return htmlToPdfConversionLock;
    }

    public int getPaperCapturePoolSize() {
        return m_HtmlToPdfPoolSize;
    }

    public void setPaperCapturePoolSize(int poolSize) {
        if (poolSize > 0 && m_PaperCapturePoolSize != poolSize) {
            m_PaperCapturePoolSize = poolSize;
        }
    }

    public AdjustableSemaphore getPaperCaptureConversionLock() {
        return paperCaptureConversionLock;
    }

    public void setUseAcrobatImageConversion(boolean useAcrobatImageConversion) {
        this.m_useAcrobatImageConversion = useAcrobatImageConversion;
    }

    public boolean getUseAcrobatImageConversion() {
        return this.m_useAcrobatImageConversion;
    }

    public void setEnableAcrobatAutocadConversion(boolean useEnableAcrobatAutocadConversion) {
        this.m_enableAcrobatAutocadConversion = useEnableAcrobatAutocadConversion;
    }

    public boolean getEnableAcrobatAutocadConversion() {
        return this.m_enableAcrobatAutocadConversion;
    }

    public String getRegExIllegalUserIdFilter() {
        return m_regExIllegalUserIdFilter;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public void setRegExIllegalUserIdFilter(String regexIllegalCharInUsrName) {
        if (m_regExIllegalUserIdFilter != null && m_regExIllegalUserIdFilter.equals(regexIllegalCharInUsrName)) return;
        Class<GeneratePDFServiceImpl> class_ = GeneratePDFServiceImpl.class;
        synchronized (GeneratePDFServiceImpl.class) {
            if (m_regExIllegalUserIdFilter != null && m_regExIllegalUserIdFilter.equals(regexIllegalCharInUsrName)) return;
            {
                m_regExIllegalUserIdFilter = regexIllegalCharInUsrName;
                m_isRegExIllegalCharModified = true;
            }
            // ** MonitorExit[var2_2] (shouldn't be in output)
            return;
        }
    }

    private void updatePrimarySecondaryRoute(String html2pdfPrimaryRoute, String html2pdfSecondaryRoute) {
        if (this.myIsWindows) {
            if (html2pdfPrimaryRoute.equalsIgnoreCase("WebCapture")) {
                this.myConversionHelper.setPrimaryRoute("WEB_CAPTURE");
            } else if (html2pdfPrimaryRoute.equalsIgnoreCase("PhantomJS")) {
                this.myConversionHelper.setPrimaryRoute("PHANTOMJS");
            } else {
                this.myConversionHelper.setPrimaryRoute("WEBKIT");
            }
            if (html2pdfSecondaryRoute.equalsIgnoreCase("WebCapture")) {
                this.myConversionHelper.setSecondaryRoute("WEB_CAPTURE");
            } else if (html2pdfSecondaryRoute.equalsIgnoreCase("PhantomJS")) {
                this.myConversionHelper.setSecondaryRoute("PHANTOMJS");
            } else if (html2pdfSecondaryRoute.equalsIgnoreCase("Webkit")) {
                this.myConversionHelper.setSecondaryRoute("WEBKIT");
            } else {
                this.myConversionHelper.setSecondaryRoute(null);
            }
            if (html2pdfPrimaryRoute.equalsIgnoreCase(html2pdfSecondaryRoute)) {
                this.myConversionHelper.setSecondaryRoute(null);
            }
        } else if (this.myIsLinux) {
            if (html2pdfPrimaryRoute.equalsIgnoreCase("PhantomJS")) {
                this.myConversionHelper.setPrimaryRoute("PHANTOMJS");
            } else {
                this.myConversionHelper.setPrimaryRoute("WEBKIT");
            }
            if (html2pdfSecondaryRoute.equalsIgnoreCase("PhantomJS")) {
                this.myConversionHelper.setSecondaryRoute("PHANTOMJS");
            } else if (html2pdfSecondaryRoute.equalsIgnoreCase("Webkit")) {
                this.myConversionHelper.setSecondaryRoute("WEBKIT");
            } else {
                this.myConversionHelper.setSecondaryRoute(null);
            }
            if (html2pdfPrimaryRoute.equalsIgnoreCase(html2pdfSecondaryRoute)) {
                this.myConversionHelper.setSecondaryRoute(null);
            }
        } else {
            this.myConversionHelper.setPrimaryRoute("WEBKIT");
            this.myConversionHelper.setSecondaryRoute(null);
        }
    }

    public void setFallbackFontForHTMLConversions(String fallbackFont) {
        m_usePDFGHTMLFont = fallbackFont;
    }

    public String getFallbackFontForHTMLConversions() {
        return m_usePDFGHTMLFont;
    }

    public void setRetryLogic(String retryLogic) {
        Native2PdfCaller.setRetryLogic(retryLogic);
    }

    public void setPrimaryRoute(String primaryRoute) {
        this.myConversionHelper.setPrimaryRoute(primaryRoute);
    }

    public void setSecondaryRoute(String secondaryRoute) {
        this.myConversionHelper.setSecondaryRoute(secondaryRoute);
    }

    public TransactionTemplate getTransactionTemplate() {
        return new TransactionTemplate(this.transactionManager);
    }

    public Map getUserAccountsMap() throws Exception {
        if (m_userMap == null || m_userMap.isEmpty()) {
            m_userMap = this.configService.getAllValidUsersAccounts();
        }
        return m_userMap;
    }

    public int getSwf2pdf_dpi() {
        return this.m_swf2pdf_dpi;
    }

    public void setSwf2pdf_dpi(int m_swf2pdf_dpi) {
        this.m_swf2pdf_dpi = m_swf2pdf_dpi;
    }

    public ConnectionFactory getHtmlToPdfFactory() {
        return this.htmlToPdfFactory;
    }

    public void setHtmlToPdfFactory(ConnectionFactory htmlToPdfFactory) {
        this.htmlToPdfFactory = htmlToPdfFactory;
    }

    public ConnectionFactory getImageToPdfFactory() {
        return this.imageToPdfFactory;
    }

    public void setImageToPdfFactory(ConnectionFactory imageToPdfFactory) {
        this.imageToPdfFactory = imageToPdfFactory;
    }

    public ConnectionFactory getNativeToPdfFactory() {
        return this.nativeToPdfFactory;
    }

    public void setNativeToPdfFactory(ConnectionFactory nativeToPdfFactory) {
        this.nativeToPdfFactory = nativeToPdfFactory;
    }

    public ConnectionFactory getPdfMakerFactory() {
        return this.pdfMakerFactory;
    }

    public void setPdfMakerFactory(ConnectionFactory pdfMakerFactory) {
        this.pdfMakerFactory = pdfMakerFactory;
    }

    public ConnectionFactory getOpenOfficeToPdfFactory() {
        return this.openOfficeToPdfFactory;
    }

    public void setOpenOfficeToPdfFactory(ConnectionFactory openOfficeToPdfFactory) {
        this.openOfficeToPdfFactory = openOfficeToPdfFactory;
    }

    public ConnectionFactory getSwfToPdfFactory() {
        return null;
    }

    public ConnectionFactory getPaperCaptureFactory() {
        return this.paperCaptureFactory;
    }

    public void setPaperCaptureFactory(ConnectionFactory paperCaptureFactory) {
        this.paperCaptureFactory = paperCaptureFactory;
    }

    public PDFGConfigService getConfigService() {
        return this.configService;
    }

    public FontManagerService getFontManagerService() {
        return this.fontManager;
    }

    public TempFileManager getTempFileManager() {
        return this.tfm;
    }

    protected void bindTransactionManager(TransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }

    protected void unbindTransactionManager(TransactionManager transactionManager) {
        if (this.transactionManager == transactionManager) {
            this.transactionManager = null;
        }
    }

    protected void bindTfm(TempFileManager tempFileManager) {
        this.tfm = tempFileManager;
    }

    protected void unbindTfm(TempFileManager tempFileManager) {
        if (this.tfm == tempFileManager) {
            this.tfm = null;
        }
    }

    protected void bindFontManager(FontManagerService fontManagerService) {
        this.fontManager = fontManagerService;
    }

    protected void unbindFontManager(FontManagerService fontManagerService) {
        if (this.fontManager == fontManagerService) {
            this.fontManager = null;
        }
    }

    protected void bindConfigService(PDFGConfigService pDFGConfigService) {
        this.configService = pDFGConfigService;
    }

    protected void unbindConfigService(PDFGConfigService pDFGConfigService) {
        if (this.configService == pDFGConfigService) {
            this.configService = null;
        }
    }

    protected void bindHtmlToPdfFactory(ConnectionFactory connectionFactory) {
        this.htmlToPdfFactory = connectionFactory;
    }

    protected void unbindHtmlToPdfFactory(ConnectionFactory connectionFactory) {
        if (this.htmlToPdfFactory == connectionFactory) {
            this.htmlToPdfFactory = null;
        }
    }

    protected void bindImageToPdfFactory(ConnectionFactory connectionFactory) {
        this.imageToPdfFactory = connectionFactory;
    }

    protected void unbindImageToPdfFactory(ConnectionFactory connectionFactory) {
        if (this.imageToPdfFactory == connectionFactory) {
            this.imageToPdfFactory = null;
        }
    }

    protected void bindNativeToPdfFactory(ConnectionFactory connectionFactory) {
        this.nativeToPdfFactory = connectionFactory;
    }

    protected void unbindNativeToPdfFactory(ConnectionFactory connectionFactory) {
        if (this.nativeToPdfFactory == connectionFactory) {
            this.nativeToPdfFactory = null;
        }
    }

    protected void bindOpenOfficeToPdfFactory(ConnectionFactory connectionFactory) {
        this.openOfficeToPdfFactory = connectionFactory;
    }

    protected void unbindOpenOfficeToPdfFactory(ConnectionFactory connectionFactory) {
        if (this.openOfficeToPdfFactory == connectionFactory) {
            this.openOfficeToPdfFactory = null;
        }
    }

    protected void bindPaperCaptureFactory(ConnectionFactory connectionFactory) {
        this.paperCaptureFactory = connectionFactory;
    }

    protected void unbindPaperCaptureFactory(ConnectionFactory connectionFactory) {
        if (this.paperCaptureFactory == connectionFactory) {
            this.paperCaptureFactory = null;
        }
    }

    protected void bindPdfMakerFactory(ConnectionFactory connectionFactory) {
        this.pdfMakerFactory = connectionFactory;
    }

    protected void unbindPdfMakerFactory(ConnectionFactory connectionFactory) {
        if (this.pdfMakerFactory == connectionFactory) {
            this.pdfMakerFactory = null;
        }
    }
}