PaperCaptureCaller.java 11.7 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.native2pdf.xml.FiletypeSettings
 *  com.adobe.native2pdf.xml.FiletypeSettings$Settings
 *  com.adobe.native2pdf.xml.SecuritySettings
 *  com.adobe.native2pdf.xml.SecuritySettings$Settings
 *  com.adobe.pdfg.common.AESProperties
 *  com.adobe.pdfg.common.FileUtilities
 *  com.adobe.pdfg.common.Guid
 *  com.adobe.pdfg.common.JobConfiguration
 *  com.adobe.pdfg.common.PDFGGlobalCache
 *  com.adobe.pdfg.common.Utils
 *  com.adobe.pdfg.exception.ConversionException
 *  com.adobe.pdfg.exception.InvalidParameterException
 *  com.adobe.pdfg.logging.PDFGLogger
 *  com.adobe.pdfg.service.api.PDFGConfigService
 *  com.adobe.service.ConnectionFactory
 */
package com.adobe.pdfg.impl;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.native2pdf.xml.FiletypeSettings;
import com.adobe.native2pdf.xml.SecuritySettings;
import com.adobe.pdfg.callbacks.PaperCaptureTransactionCallback;
import com.adobe.pdfg.common.AESProperties;
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.Utils;
import com.adobe.pdfg.exception.ConversionException;
import com.adobe.pdfg.exception.InvalidParameterException;
import com.adobe.pdfg.impl.BMCCaller;
import com.adobe.pdfg.impl.GeneratePDFServiceImpl;
import com.adobe.pdfg.impl.GeneratePDFUtil;
import com.adobe.pdfg.impl.utils.AdjustableSemaphore;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.postprocess.PostProcessFileInfo;
import com.adobe.pdfg.service.api.PDFGConfigService;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.pdfg.transaction.TransactionTemplate;
import com.adobe.service.ConnectionFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;

public class PaperCaptureCaller
extends BMCCaller {
    private static int poolSize = 3;
    private static Semaphore conversionLock = null;
    private String NATIVE_IN_XMP_FILENAME = "xmp-in.xmp";

    protected boolean checkLinearizationForPostProcessing() {
        return true;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public Map createPDF(GeneratePDFServiceImpl coreSvcImpl, Document sourceFileDoc, String inputFileName, String fileTypeSettings, String pdfSettings, String securitySettings, Document settingsDoc, String jobConfigurationString, Document xmpDoc) throws Exception {
        File logFile;
        int lastDot;
        String jobIdentityId = new Guid().toString();
        Utils.threadLocalValue.set(jobIdentityId);
        long startTime = 0;
        startTime = System.currentTimeMillis();
        String configString = GeneratePDFUtil.getJobConfigurationString(coreSvcImpl.getConfigService(), settingsDoc, fileTypeSettings, pdfSettings, securitySettings);
        JobConfiguration config = null;
        this.pdfgLogger.info("001-024", new Object[]{inputFileName, new Date(startTime), jobIdentityId});
        this.pdfgLogger.info("001-016", new Object[]{inputFileName, "OCR"});
        try {
            config = PDFGGlobalCache.getJobConfiguration((String)configString);
        }
        catch (Exception e) {
            throw new InvalidParameterException(1001, (Throwable)e);
        }
        if (config == null) {
            throw new InvalidParameterException(80001);
        }
        this.pdfgLogger.info("001-022", new Object[]{inputFileName, config.getSecuritySettings().getName()});
        this.pdfgLogger.info("001-023", new Object[]{inputFileName, config.getFiletypeSettings().getName()});
        int timeoutSeconds = AESProperties.getMaximumTimeout();
        timeoutSeconds = Math.max(10, timeoutSeconds);
        timeoutSeconds = config.getConversionTimeoutSetting(10, timeoutSeconds, timeoutSeconds);
        File pdfgTmpDir = null;
        try {
            pdfgTmpDir = FileUtilities.createGuidDir((String)jobIdentityId);
        }
        catch (IOException ioe) {
            throw new ConversionException(1003, (Throwable)ioe);
        }
        if (inputFileName == null || "".equals(inputFileName)) {
            inputFileName = "PaperCaptureInput.pdf";
        }
        File inputFile = new File(pdfgTmpDir, inputFileName);
        sourceFileDoc.copyToFile(inputFile);
        if (inputFile.length() == 0) {
            throw new ConversionException(11019);
        }
        File outputFile = inputFile;
        String inputPdfPath = inputFile.getAbsolutePath();
        String outputPdfPath = outputFile.getAbsolutePath();
        File xmpFile = null;
        if (xmpDoc != null) {
            xmpFile = new File(pdfgTmpDir, this.NATIVE_IN_XMP_FILENAME);
            xmpDoc.copyToFile(xmpFile);
            this.pdfgLogger.info("001-020", new Object[]{inputFileName, xmpFile.getName()});
        }
        String logFilePath = (lastDot = outputPdfPath.lastIndexOf(".")) != -1 ? outputPdfPath.substring(0, lastDot) + ".log" : outputPdfPath + ".log";
        PaperCaptureTransactionCallback transactionCallback = new PaperCaptureTransactionCallback(coreSvcImpl.getPaperCaptureFactory());
        transactionCallback.setSourcePath(inputPdfPath);
        transactionCallback.setDestinationPath(outputPdfPath);
        transactionCallback.setLogPath(logFilePath);
        transactionCallback.setTimeout(timeoutSeconds);
        transactionCallback.setOCRParams(config);
        try {
            coreSvcImpl.getPaperCaptureConversionLock().acquire();
            TransactionTemplate _txTemplate = coreSvcImpl.getTransactionTemplate();
            _txTemplate.setPropagationBehavior(0);
            _txTemplate.setTimeout(timeoutSeconds + 200);
            this.pdfgLogger.debug("before calling _txTemplate.execute for job=" + jobIdentityId);
            _txTemplate.execute(transactionCallback);
            Object var27_28 = null;
        }
        catch (Throwable var26_30) {
            Object var27_29 = null;
            coreSvcImpl.getPaperCaptureConversionLock().release();
            throw var26_30;
        }
        coreSvcImpl.getPaperCaptureConversionLock().release();
        {
        }
        int errorCode = 0;
        errorCode = this.initializeConfiguration(coreSvcImpl, settingsDoc, jobConfigurationString, errorCode);
        errorCode = this.setDistillerParams(coreSvcImpl, "PaperCaptureService", errorCode);
        PostProcessFileInfo filePaths = new PostProcessFileInfo();
        filePaths.pdfFilePath = outputPdfPath;
        filePaths.logFilePath = logFilePath;
        File jobOptionFile = null;
        try {
            String suffix = ".joboptions";
            errorCode = 1002;
            jobOptionFile = this.validateConfigAndWriteJobOptions(coreSvcImpl, config, this.jobOptionName, ".joboptions", false, this.appConfig, pdfgTmpDir);
            this.jobOptionName = this.getJobOptionNameFromFile(jobOptionFile, ".joboptions");
            this.doPostProcess("PaperCaptureService", "PaperCaptureService", xmpFile, outputPdfPath, coreSvcImpl, jobOptionFile, errorCode, filePaths, false, false, null, 1, GeneratePDFUtil.applyWaterMark());
            Object var30_33 = null;
            if (jobOptionFile != null && jobOptionFile.exists()) {
                jobOptionFile.delete();
            }
        }
        catch (Throwable var29_36) {
            Object var30_34 = null;
            if (jobOptionFile != null && jobOptionFile.exists()) {
                jobOptionFile.delete();
            }
            throw var29_36;
        }
        Document convertedDoc = filePaths.postProcessedDoc;
        File pdfFile = null;
        if (convertedDoc == null) {
            pdfFile = new File(filePaths.pdfFilePath);
        }
        if (pdfFile != null && pdfFile.exists() && pdfFile.length() > 0) {
            convertedDoc = new Document(pdfFile, false);
        }
        long endTime = System.currentTimeMillis();
        if (convertedDoc != null) {
            convertedDoc.setAttribute("file", (Object)inputFileName);
            convertedDoc.setContentType("application/pdf");
        }
        Document logDoc = null;
        if (logFilePath != null && (logFile = new File(logFilePath)).exists() && logFile.length() > 0) {
            logDoc = new Document(logFile, true);
            logDoc.setAttribute("file", (Object)logFilePath);
            logDoc.setContentType("text/plain");
        }
        this.pdfgLogger.info("001-027", inputFileName);
        this.pdfgLogger.info("001-025", new Object[]{inputFileName, new Date(endTime), jobIdentityId});
        this.pdfgLogger.info("001-026", new Object[]{inputFileName, endTime - startTime, jobIdentityId});
        HashMap<String, Document> map = new HashMap<String, Document>();
        if (convertedDoc != null) {
            map.put("ConvertedDoc", convertedDoc);
            if (logDoc != null) {
                map.put("LogDoc", logDoc);
            }
        } else {
            ConversionException e = new ConversionException(11026);
            if (logDoc != null) {
                this.createConversionLog(e, logFilePath);
            }
            throw e;
        }
        return map;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Unable to fully structure code
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     * Lifted jumps to return sites
     */
    private void createConversionLog(ConversionException conversionException, String logFilePath) {
        if (logFilePath == null) {
            return;
        }
        logFile = new File(logFilePath);
        if (logFile.exists() == false) return;
        if (logFile.isFile() == false) return;
        if (logFile.length() <= 0) return;
        if (logFile.canRead() == false) return;
        fileReader = null;
        stringWriter = null;
        try {
            try {
                fileReader = new BufferedReader(new FileReader(logFile));
                stringWriter = new StringWriter();
                buffer = new char[256];
                nCharacters = fileReader.read(buffer);
                while (nCharacters != -1) {
                    stringWriter.write(buffer, 0, nCharacters);
                    nCharacters = fileReader.read(buffer);
                }
                conversionException.setConversionLog(stringWriter.toString());
            }
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                var9_10 = null;
                if (fileReader == null) return;
                try {}
                catch (Exception e) {
                    this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                    return;
                }
                fileReader.close();
                return;
            }
            var9_9 = null;
            if (fileReader == null) return;
            fileReader.close();
            return;
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
                return;
            }
        }
        catch (Throwable throwable) {
            var9_11 = null;
            if (fileReader == null) throw throwable;
            ** try [egrp 2[TRYBLOCK] [4 : 173->181)] { 
lbl46: // 1 sources:
            fileReader.close();
            throw throwable;
lbl48: // 1 sources:
            catch (Exception e) {
                this.pdfgLogger.trace(e.getMessage(), null, (Throwable)e);
            }
            throw throwable;
        }
    }
}