PsToPdfProcess.java 4.61 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.granite.workflow.WorkflowException
 *  com.adobe.granite.workflow.WorkflowSession
 *  com.adobe.granite.workflow.exec.WorkItem
 *  com.adobe.granite.workflow.metadata.MetaDataMap
 *  com.adobe.pdfg.result.CreatePDFResult
 *  com.adobe.pdfg.service.api.DistillerService
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.fd.workflow.pdfg;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
import com.adobe.fd.workflow.utils.DocumentUtils;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.pdfg.result.CreatePDFResult;
import com.adobe.pdfg.service.api.DistillerService;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@Service
@Properties(value={@Property(name="service.description", value={"PsToPdfProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"PsToPdfProcess"})})
public class PsToPdfProcess
extends AEMFDWorkflowProcess {
    private static Logger LOGGER = LoggerFactory.getLogger(PsToPdfProcess.class);
    private static final String INDOC_PARAM = "inDoc";
    private static final String FILE_EXTENSION_PARAM = "fileExtension";
    private static final String PDF_SETTINGS_PARAM = "pdfSettings";
    private static final String SECURITY_SETTINGS_PARAM = "securitySettings";
    private static final String SETTINGS_DOC_PARAM = "settingsDoc";
    private static final String XMP_DOC_PARAM = "xmpDoc";
    private static final String OUT_DOC_PARAM = "outDoc";
    @Reference
    DistillerService distillerService;

    @Override
    protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        try {
            CreatePDFResult conversionResult;
            Document inputDoc = DocumentUtils.getInputDocument(workItem, "inDoc");
            String inputFileExtension = null;
            String pdfSettings = null;
            String securitySettings = null;
            Document settingsDoc = null;
            Document xmpDoc = null;
            if (metaDataMap.get("fileExtension", String.class) != null) {
                inputFileExtension = (String)metaDataMap.get("fileExtension", String.class);
                LOGGER.debug("fileExtension= " + inputFileExtension);
            }
            if (metaDataMap.get("pdfSettings", String.class) != null) {
                pdfSettings = (String)metaDataMap.get("pdfSettings", String.class);
                LOGGER.debug("pdfSettings= " + pdfSettings);
            }
            if (metaDataMap.get("securitySettings", String.class) != null) {
                securitySettings = (String)metaDataMap.get("securitySettings", String.class);
                LOGGER.debug("securitySettings= " + securitySettings);
            }
            if (metaDataMap.get("settingsDoc", Document.class) != null) {
                settingsDoc = (Document)metaDataMap.get("settingsDoc", Document.class);
            }
            if (metaDataMap.get("xmpDoc", Document.class) != null) {
                xmpDoc = (Document)metaDataMap.get("xmpDoc", Document.class);
            }
            if ((conversionResult = this.distillerService.createPDF2(inputDoc, inputFileExtension, pdfSettings, securitySettings, settingsDoc, xmpDoc)).getCreatedDocument() != null) {
                DocumentUtils.saveOutputDocument(workItem, workflowSession, "outDoc", conversionResult.getCreatedDocument());
            }
        }
        catch (Exception e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    protected void bindDistillerService(DistillerService distillerService) {
        this.distillerService = distillerService;
    }

    protected void unbindDistillerService(DistillerService distillerService) {
        if (this.distillerService == distillerService) {
            this.distillerService = null;
        }
    }
}