PaperCaptureTransactionCallback.java 11.3 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.native2pdf.xml.FiletypeSettings
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings$Image
 *  com.adobe.pdfg.common.AESProperties
 *  com.adobe.pdfg.common.JobConfiguration
 *  com.adobe.pdfg.common.Utils
 *  com.adobe.pdfg.exception.PDFGError
 *  com.adobe.pdfg.exception.PDFGRuntimeException
 *  com.adobe.pdfg.logging.PDFGLogger
 *  com.adobe.pdfg.papercapture.OCRDownsample
 *  com.adobe.pdfg.papercapture.OCRLibraryFormat
 *  com.adobe.pdfg.papercapture.OCRLibraryLanguage
 *  com.adobe.pdfg.papercapture.OCROptions
 *  com.adobe.pdfg.papercapture.PaperCaptureService
 *  com.adobe.pdfg.papercapture.PaperCaptureServiceHelper
 *  com.adobe.service.ConnectionFactory
 */
package com.adobe.pdfg.callbacks;

import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.JobConfiguration;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.exception.PDFGError;
import com.adobe.pdfg.exception.PDFGRuntimeException;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.papercapture.OCRDownsample;
import com.adobe.pdfg.papercapture.OCRLibraryFormat;
import com.adobe.pdfg.papercapture.OCRLibraryLanguage;
import com.adobe.pdfg.papercapture.OCROptions;
import com.adobe.pdfg.papercapture.PaperCaptureService;
import com.adobe.pdfg.papercapture.PaperCaptureServiceHelper;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.service.ConnectionFactory;
import org.omg.CORBA.COMM_FAILURE;
import org.omg.CORBA.Object;

public class PaperCaptureTransactionCallback
implements TransactionCallback {
    private ConnectionFactory m_ocrToPdfFactory;
    private static final int MAX_RETRY_COUNT = 5;
    private static final long WAIT_TIME = 60000;
    String m_strSourcePath = null;
    String m_strDestinationPath = null;
    String m_strLogPath = null;
    long m_ltimeout = 480000;
    OCROptions m_ocrSettings = new OCROptions();
    private PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(PaperCaptureTransactionCallback.class);

    public PaperCaptureTransactionCallback(ConnectionFactory paperCaptureFactory) {
        this.m_ocrToPdfFactory = paperCaptureFactory;
        this.m_ocrToPdfFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
    }

    public java.lang.Object doInTransaction() {
        Boolean bl;
        block6 : {
            String jobIdentityId = (String)Utils.threadLocalValue.get();
            StringBuilder debugMsgs = new StringBuilder();
            boolean debugMsgsLogged = false;
            try {
                debugMsgs.append("\nInside PaperCaptureTransactionCallback.doInTransaction() for job=" + jobIdentityId);
                Object connection = (Object)this.m_ocrToPdfFactory.getConnection();
                debugMsgs.append("\nafter m_ocrToPdfFactory.getConnection() for job=" + jobIdentityId);
                PaperCaptureService service = PaperCaptureServiceHelper.narrow((Object)connection);
                debugMsgs.append("\nbefore service.convertToPdf() for job=" + jobIdentityId);
                this.pdfgLogger.debug(debugMsgs.toString());
                debugMsgsLogged = true;
                boolean returnVal = service.recognizeTextInPdf(this.m_strSourcePath, this.m_strDestinationPath, this.m_strLogPath, this.m_ocrSettings, this.m_ltimeout);
                bl = returnVal;
                java.lang.Object var9_11 = null;
                if (debugMsgsLogged) break block6;
            }
            catch (Exception ex) {
                try {
                    if (ex != null && ex instanceof COMM_FAILURE) {
                        PDFGError error = new PDFGError(10010, (Throwable)ex);
                        throw new PDFGRuntimeException(error);
                    }
                    PDFGError error = new PDFGError(10001, (Throwable)ex);
                    throw new PDFGRuntimeException(error);
                }
                catch (Throwable var8_13) {
                    java.lang.Object var9_12 = null;
                    if (!debugMsgsLogged) {
                        this.pdfgLogger.debug(debugMsgs.toString());
                    }
                    throw var8_13;
                }
            }
            this.pdfgLogger.debug(debugMsgs.toString());
        }
        return bl;
    }

    public void setTimeout(int timeout) {
        this.m_ltimeout = (long)timeout * 1000;
    }

    public void setDestinationPath(String destinationPath) {
        this.m_strDestinationPath = destinationPath;
    }

    public void setLogPath(String logPath) {
        this.m_strLogPath = logPath;
    }

    public void setSourcePath(String sourcePath) {
        this.m_strSourcePath = sourcePath;
    }

    public void setOCRParams(JobConfiguration config) {
        FiletypeSettings.Settings.Image ocr2pdf = null;
        ocr2pdf = config.getFiletypeSettings().getImage();
        if (ocr2pdf != null) {
            String downsampling = ocr2pdf.getOcrDownsampleType();
            String outputStyle = ocr2pdf.getOcrOutputStyle();
            String lang = ocr2pdf.getOcrLanguage();
            this.m_ocrSettings.downsampling = this.getOCRDownsample(downsampling);
            this.m_ocrSettings.format = this.getOCRLibraryFormat(outputStyle);
            this.m_ocrSettings.language = this.getOCRLibraryLanguage(lang);
        }
    }

    private OCRDownsample getOCRDownsample(String downsampling) {
        if ("Lowest".equals(downsampling)) {
            return OCRDownsample.OCRDownsample600;
        }
        if ("Low".equals(downsampling)) {
            return OCRDownsample.OCRDownsample300;
        }
        if ("Medium".equals(downsampling)) {
            return OCRDownsample.OCRDownsample150;
        }
        if ("High".equals(downsampling)) {
            return OCRDownsample.OCRDownsample72;
        }
        return OCRDownsample.OCRDownsampleNone;
    }

    private OCRLibraryFormat getOCRLibraryFormat(String format) {
        if ("Searchable-Exact".equals(format)) {
            return OCRLibraryFormat.OCRLibraryImageExact;
        }
        if ("Searchable-Compact".equals(format)) {
            return OCRLibraryFormat.OCRLibraryImage;
        }
        if ("Formatted-Text".equals(format)) {
            return OCRLibraryFormat.OCRLibraryClearScan;
        }
        return OCRLibraryFormat.OCRLibraryDefaultFormat;
    }

    private OCRLibraryLanguage getOCRLibraryLanguage(String language) {
        OCRLibraryLanguage ocrLang = OCRLibraryLanguage.OCRLANG_HOST;
        if ("Basque".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_BASQUE;
        } else if ("Brazilian-Portuguese".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_BRAZILIANPORTUGUESE;
        } else if ("Bulgarian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_BULGARIAN;
        } else if ("Catalan".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_CATALAN;
        } else if ("Croatian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_CROATIAN;
        } else if ("Czechoslovakian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_CZECH;
        } else if ("Czech".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_CZECH;
        } else if ("Danish".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_DANISH;
        } else if ("Dutch".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_DUTCH;
        } else if ("English(UK)".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_ENGLISHUK;
        } else if ("English(US)".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_ENGLISHUS;
        } else if ("Estonian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_ESTONIAN;
        } else if ("Finnish".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_FINNISH;
        } else if ("French".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_FRENCH;
        } else if ("Galacian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_GALICIAN;
        } else if ("German".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_GERMAN;
        } else if ("Greek".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_GREEK;
        } else if ("Hebrew".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_HEBREW;
        } else if ("Hungarian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_HUNGARIAN;
        } else if ("Italian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_ITALIAN;
        } else if ("Japanese".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_JAPANESE;
        } else if ("Korean".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_KOREAN;
        } else if ("Latvian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_LATVIAN;
        } else if ("Lithuanian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_LITHUANIAN;
        } else if ("Macedonian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_MACEDONIAN;
        } else if ("Maltese".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_MALTESE;
        } else if ("Norwegian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_NORWEGIAN;
        } else if ("Nynorsk".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_NYNORSK;
        } else if ("Occitan".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_OCCITAN;
        } else if ("Polish".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_POLISH;
        } else if ("Portuguese".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_PORTUGUESE;
        } else if ("Romanian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_ROMANIAN;
        } else if ("Russian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_RUSSIAN;
        } else if ("Serbian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SERBIAN;
        } else if ("Simplified Chinese".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SIMPLIFIEDCHINESE;
        } else if ("Slovak".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SLOVAK;
        } else if ("Slovenian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SLOVENIAN;
        } else if ("Spanish".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SPANISH;
        } else if ("Swedish".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SWEDISH;
        } else if ("Swiss-German".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_SWISSGERMAN;
        } else if ("Turkish".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_TURKISH;
        } else if ("Traditional Chinese".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_TRADITIONALCHINESE;
        } else if ("Ukrainian".equals(language)) {
            ocrLang = OCRLibraryLanguage.OCRLANG_UKRAINIAN;
        }
        return ocrLang;
    }

    public void setOcrToPdfFactory(ConnectionFactory m_ocrToPdfFactory) {
        this.m_ocrToPdfFactory = m_ocrToPdfFactory;
    }
}