NativeToPDFTransactionCallback.java 10.9 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.bedrock.internal.OSGiUtils
 *  com.adobe.native2pdf.bmc.AppMonData
 *  com.adobe.native2pdf.bmc.ConverterAgent
 *  com.adobe.native2pdf.bmc.ConverterAgentHelper
 *  com.adobe.native2pdf.bmc.ResultStruct
 *  com.adobe.pdfg.common.AESProperties
 *  com.adobe.pdfg.common.Utils
 *  com.adobe.pdfg.logging.PDFGLogger
 *  com.adobe.service.ConnectionFactory
 *  com.jniwrapper.DefaultLibraryLoader
 *  com.jniwrapper.win32.registry.RegistryKey
 *  com.jniwrapper.win32.registry.RegistryKeyValues
 */
package com.adobe.pdfg.callbacks;

import com.adobe.aemds.bedrock.internal.OSGiUtils;
import com.adobe.native2pdf.bmc.AppMonData;
import com.adobe.native2pdf.bmc.ConverterAgent;
import com.adobe.native2pdf.bmc.ConverterAgentHelper;
import com.adobe.native2pdf.bmc.ResultStruct;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.common.Utils;
import com.adobe.pdfg.logging.PDFGLogger;
import com.adobe.pdfg.transaction.TransactionCallback;
import com.adobe.service.ConnectionFactory;
import com.jniwrapper.DefaultLibraryLoader;
import com.jniwrapper.win32.registry.RegistryKey;
import com.jniwrapper.win32.registry.RegistryKeyValues;
import java.util.Map;
import org.omg.CORBA.Object;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class NativeToPDFTransactionCallback
implements TransactionCallback {
    private static final int MAX_RETRY_COUNT = 5;
    private static final long WAIT_TIME = 60000;
    private static final String officeRegEntry = "Software\\Microsoft\\Office";
    private static final String addInLocation = "Addins\\PDFMaker.OfficeAddin";
    private static final String pathSep = "\\";
    private static final boolean nonAdminEffective = System.getProperty("os.name").toLowerCase().indexOf("windows") > -1 && System.getenv("PDFG_NON_ADMIN_ENABLED") != null;
    private static int m_pdfMakerpoolSize = 1;
    private static PDFGLogger pdfgLogger = PDFGLogger.getPDFGLogger(NativeToPDFTransactionCallback.class);
    private String m_strSourceFilePath = null;
    private String m_strDestFilePath = null;
    private String appName = null;
    private int m_iTimeoutSeconds = 270;
    private byte[] m_securityConfig = null;
    private String m_strJobOptionsName = null;
    private byte[] m_appSpecificConfig = null;
    private AppMonData m_appMonConfig = null;
    private boolean m_bApplyWatermark = false;
    private boolean m_bUseNative = true;
    private boolean m_bCreatePDFA = false;
    private int startPage;
    private int endPage;
    private String m_ocrlanguageChosen;
    private ConnectionFactory nativeToPdfFactory;
    private ConnectionFactory pdfMakerFactory;

    public NativeToPDFTransactionCallback(ConnectionFactory nativeToPdfFactory, ConnectionFactory pdfMakerFactory) {
        this.nativeToPdfFactory = nativeToPdfFactory;
        this.pdfMakerFactory = pdfMakerFactory;
        this.nativeToPdfFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
        this.pdfMakerFactory.setServiceTimeout((long)AESProperties.getGlobalTimeout());
    }

    public void initNativeToPDFFactory(Map usersMap) throws Exception {
        String jobIdentityId = (String)Utils.threadLocalValue.get();
        StringBuilder debugMsgs = new StringBuilder();
        debugMsgs.append("\nInside NativeToPDFTransactionCallback.initNativeToPDFFactory for job=" + jobIdentityId);
        if (usersMap != null && !usersMap.isEmpty()) {
            this.nativeToPdfFactory.setImpersonationIdentities(usersMap);
        }
        debugMsgs.append("\nabout to exit initNativeToPDFFactory() for job=" + jobIdentityId);
    }

    public void initPDFMToPDFFactory(Map usersMap) throws Exception {
        String jobIdentityId = (String)Utils.threadLocalValue.get();
        StringBuilder debugMsgs = new StringBuilder();
        debugMsgs.append("\nInside NativeToPDFTransactionCallback.initPDFMToPDFFactory for job=" + jobIdentityId);
        if (usersMap != null && !usersMap.isEmpty()) {
            m_pdfMakerpoolSize = usersMap.size();
            this.pdfMakerFactory.setImpersonationIdentities(usersMap);
        }
        debugMsgs.append("\nabout to exit initPDFMToPDFFactory() for job=" + jobIdentityId);
    }

    protected void resetOfficeAddinLoadBehaviorRegistryValue(String app) {
        if (nonAdminEffective) {
            StringBuilder regPath = null;
            try {
                Long keyVal;
                pdfgLogger.debug("Inside resetOfficeAddinLoadBehaviorRegistryValue");
                regPath = new StringBuilder("Software\\Microsoft\\Office").append("\\");
                regPath.append(app).append("\\");
                regPath.append("Addins\\PDFMaker.OfficeAddin");
                RegistryKey localMachine = RegistryKey.LOCAL_MACHINE;
                RegistryKey officeOptions = localMachine.openSubKey(regPath.toString(), true);
                RegistryKeyValues keyValues = officeOptions.values();
                if (keyValues.containsKey((java.lang.Object)"LoadBehavior") && (keyVal = (Long)keyValues.get((java.lang.Object)"LoadBehavior")) != 3) {
                    keyValues.put((java.lang.Object)"LoadBehavior", (java.lang.Object)3);
                    pdfgLogger.debug("Re-enabling the Adobe Acrobat PDFMaker add-in (changed the value of Load Behaviour) for MS Office.", "");
                }
            }
            catch (Exception ex) {
                pdfgLogger.info(ex.getLocalizedMessage(), "");
            }
        }
    }

    public java.lang.Object doInTransaction() {
        pdfgLogger.debug("inside doInTransaction() for job=" + (String)Utils.threadLocalValue.get());
        if (this.m_bUseNative) {
            return this.convertToPdf(this.nativeToPdfFactory);
        }
        return this.convertToPdf(this.pdfMakerFactory);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private ResultStruct convertToPdf(ConnectionFactory connectionFactory) {
        ResultStruct resultStruct;
        boolean debugMsgsLogged;
        StringBuilder debugMsgs;
        block9 : {
            ConverterAgent agent = null;
            String jobIdentityId = (String)Utils.threadLocalValue.get();
            debugMsgs = new StringBuilder();
            debugMsgsLogged = false;
            debugMsgs.append("\nInside NativeToPDFTransactionCallback.convertToPdf for job=" + jobIdentityId);
            try {
                debugMsgs.append("\nbefore obtaining a CORBA connection for job=" + jobIdentityId);
                Object connection = (Object)connectionFactory.getConnection();
                debugMsgs.append("\nbefore narrowing the CORBA connection for job=" + jobIdentityId);
                agent = ConverterAgentHelper.narrow((Object)connection);
                debugMsgs.append("\nbefore agent.convertToPdf for job=" + jobIdentityId);
                pdfgLogger.debug(debugMsgs.toString());
                debugMsgsLogged = true;
                if (this.m_ocrlanguageChosen == null) {
                    this.m_ocrlanguageChosen = "";
                }
                this.resetOfficeAddinLoadBehaviorRegistryValue(this.appName);
                resultStruct = agent.convertToPdf(this.m_strSourceFilePath, this.m_strDestFilePath, this.appName, this.m_iTimeoutSeconds, this.m_securityConfig, this.m_strJobOptionsName, this.m_appSpecificConfig, this.m_appMonConfig, this.m_bApplyWatermark, this.m_bCreatePDFA, jobIdentityId, this.startPage, this.endPage, this.m_ocrlanguageChosen);
                java.lang.Object var9_8 = null;
                if (agent == null) break block9;
            }
            catch (Throwable var8_12) {
                java.lang.Object var9_9 = null;
                if (agent != null) {
                    try {
                        agent.cleanUp();
                    }
                    catch (Exception t) {
                        pdfgLogger.trace(t.getMessage(), null, (Throwable)t);
                    }
                }
                if (!debugMsgsLogged) {
                    pdfgLogger.debug(debugMsgs.toString());
                }
                throw var8_12;
            }
            try {
                agent.cleanUp();
            }
            catch (Exception t) {
                pdfgLogger.trace(t.getMessage(), null, (Throwable)t);
            }
        }
        if (!debugMsgsLogged) {
            pdfgLogger.debug(debugMsgs.toString());
        }
        return resultStruct;
    }

    public void setApplyWatermark(boolean applyWatermark) {
        this.m_bApplyWatermark = applyWatermark;
    }

    public void setAppMonConfig(AppMonData appMonConfig) {
        this.m_appMonConfig = appMonConfig;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public void setAppSpecificConfig(byte[] appSpecificConfig) {
        this.m_appSpecificConfig = appSpecificConfig;
    }

    public void setDestFilePath(String destFilePath) {
        this.m_strDestFilePath = destFilePath;
    }

    public void setDistillerJobOptionsName(String distillerJobOptionsName) {
        this.m_strJobOptionsName = distillerJobOptionsName;
    }

    public void setSecurityConfig(byte[] securityConfig) {
        this.m_securityConfig = securityConfig;
    }

    public void setSourceFilePath(String sourceFilePath) {
        this.m_strSourceFilePath = sourceFilePath;
    }

    public void setTimeoutSeconds(int timeoutSeconds) {
        this.m_iTimeoutSeconds = timeoutSeconds;
    }

    public void setUseNative(boolean usePDFM) {
        this.m_bUseNative = usePDFM;
    }

    public void setCreatePDFA(boolean createPDFA) {
        this.m_bCreatePDFA = createPDFA;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    public int getPDFMakerPoolSize() {
        return m_pdfMakerpoolSize;
    }

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

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

    public void modifyUserAccountsMapForPDFM(Map<String, String> usersMap) throws Exception {
        if (usersMap != null && !usersMap.isEmpty()) {
            this.pdfMakerFactory.setImpersonationIdentities(usersMap);
        }
    }

    public void setOCRLanguage(String ocrLanguageChosen) {
        this.m_ocrlanguageChosen = ocrLanguageChosen;
    }

    public String getOCRLanguage() {
        return this.m_ocrlanguageChosen;
    }

    static {
        if (nonAdminEffective) {
            StringBuilder dllPath = new StringBuilder(OSGiUtils.getCoreConfigService().getServerNativeDir());
            dllPath.append("\\");
            dllPath.append("Native2PDFSvc").append("\\");
            dllPath.append("bin").append("\\");
            dllPath.append("dll");
            DefaultLibraryLoader.getInstance().addPath(dllPath.toString());
        }
    }
}