HtmlToPdfProcess.java 4.74 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.HtmlToPdfResult
 *  com.adobe.pdfg.service.api.GeneratePDFService
 *  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.HtmlToPdfResult;
import com.adobe.pdfg.service.api.GeneratePDFService;
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={"HtmlToPdfProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"HtmlToPdfProcess"})})
public class HtmlToPdfProcess
extends AEMFDWorkflowProcess {
    private static Logger LOGGER = LoggerFactory.getLogger(HtmlToPdfProcess.class);
    private static final String INDOC_PARAM = "inDoc";
    private static final String INURL_PARAM = "inUrl";
    private static final String FILETYPE_SETTINGS_PARAM = "filetypeSettings";
    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
    GeneratePDFService generatePdfService;

    @Override
    protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        try {
            Document inputDoc = DocumentUtils.getInputDocument(workItem, "inDoc");
            String inputURL = null;
            String fileTypeSettings = null;
            String securitySettings = null;
            Document settingsDoc = null;
            Document xmpDoc = null;
            if (metaDataMap.get("inUrl", String.class) != null) {
                inputURL = (String)metaDataMap.get("inUrl", String.class);
                LOGGER.debug("inUrl= " + inputURL);
            }
            if (metaDataMap.get("filetypeSettings", String.class) != null) {
                fileTypeSettings = (String)metaDataMap.get("filetypeSettings", String.class);
                LOGGER.debug("filetypeSettings= " + fileTypeSettings);
            }
            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);
            }
            HtmlToPdfResult result = null;
            result = inputDoc == null ? this.generatePdfService.htmlToPdf2(inputURL, fileTypeSettings, securitySettings, settingsDoc, xmpDoc) : this.generatePdfService.htmlFileToPdf(inputDoc, fileTypeSettings, securitySettings, settingsDoc, xmpDoc);
            if (result != null && result.getCreatedDocument() != null) {
                DocumentUtils.saveOutputDocument(workItem, workflowSession, "outDoc", result.getCreatedDocument());
            }
        }
        catch (Exception e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    protected void bindGeneratePdfService(GeneratePDFService generatePDFService) {
        this.generatePdfService = generatePDFService;
    }

    protected void unbindGeneratePdfService(GeneratePDFService generatePDFService) {
        if (this.generatePdfService == generatePDFService) {
            this.generatePdfService = null;
        }
    }
}