GeneratePDFOutputProcess.java 4.99 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.fd.output.api.AcrobatVersion
 *  com.adobe.fd.output.api.OutputService
 *  com.adobe.fd.output.api.PDFOutputOptions
 *  com.adobe.granite.workflow.WorkflowException
 *  com.adobe.granite.workflow.WorkflowSession
 *  com.adobe.granite.workflow.exec.WorkItem
 *  com.adobe.granite.workflow.metadata.MetaDataMap
 *  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.output.impl;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.output.api.AcrobatVersion;
import com.adobe.fd.output.api.OutputService;
import com.adobe.fd.output.api.PDFOutputOptions;
import com.adobe.fd.workflow.forms.internal.common.FormsUtil;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
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 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={"GeneratePDFOutputProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"GeneratePDFOutputProcess"})})
public class GeneratePDFOutputProcess
extends AEMFDWorkflowProcess {
    private static Logger logger = LoggerFactory.getLogger(GeneratePDFOutputProcess.class);
    private static final String TEMPLATE_PARAM = "urlOrFileName";
    private static final String DATA_PARAM = "data";
    private static final String CONTENT_ROOT_PARAM = "contentroot";
    private static final String LINEARIZED_PARAM = "linearized";
    private static final String LOCALE_PARAM = "locale";
    private static final String ACROBAT_VERSION_PARAM = "acrobatversion";
    private static final String TAGGED_PARAM = "tagged";
    private static final String XCI_PARAM = "xci";
    private static final String OUTPUT_PARAM = "outputpdf";
    @Reference
    OutputService outputService;

    @Override
    protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        try {
            String template = FormsUtil.getAbsolutePath(workItem, workflowSession, "urlOrFileName");
            Document dataDoc = FormsUtil.getDocument(workItem, "data");
            PDFOutputOptions options = this.createPDFOutputOptions(workItem, workflowSession, metaDataMap);
            Document document = this.outputService.generatePDFOutput(template, dataDoc, options);
            FormsUtil.saveDocument(workItem, workflowSession, document, "outputpdf");
        }
        catch (Exception e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    private PDFOutputOptions createPDFOutputOptions(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        PDFOutputOptions options = new PDFOutputOptions();
        options.setContentRoot(FormsUtil.getAbsolutePath(workItem, workflowSession, "contentroot"));
        if (metaDataMap.get("tagged", Boolean.class) != null) {
            logger.debug("tagged=" + metaDataMap.get("tagged", Boolean.class));
            options.setTaggedPDF(((Boolean)metaDataMap.get("tagged", Boolean.class)).booleanValue());
        }
        if (metaDataMap.get("linearized", Boolean.class) != null) {
            logger.debug("linearized=" + metaDataMap.get("linearized", Boolean.class));
            options.setLinearizedPDF(((Boolean)metaDataMap.get("linearized", Boolean.class)).booleanValue());
        }
        if (metaDataMap.get("locale", String.class) != null) {
            logger.debug("locale=" + (String)metaDataMap.get("locale", String.class));
            options.setLocale((String)metaDataMap.get("locale", String.class));
        }
        String acrobatVersion = (String)metaDataMap.get("acrobatversion", String.class);
        logger.debug("acrobatversion=" + acrobatVersion);
        if (acrobatVersion != null) {
            options.setAcrobatVersion(AcrobatVersion.valueOf((String)acrobatVersion));
        }
        options.setXci(FormsUtil.getDocument(workItem, "xci"));
        return options;
    }

    protected void bindOutputService(OutputService outputService) {
        this.outputService = outputService;
    }

    protected void unbindOutputService(OutputService outputService) {
        if (this.outputService == outputService) {
            this.outputService = null;
        }
    }
}