RenderPDFFormProcess.java 5.08 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemfd.docmanager.Document
 *  com.adobe.fd.forms.api.AcrobatVersion
 *  com.adobe.fd.forms.api.FormsService
 *  com.adobe.fd.forms.api.PDFFormRenderOptions
 *  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.forms.impl;

import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.forms.api.AcrobatVersion;
import com.adobe.fd.forms.api.FormsService;
import com.adobe.fd.forms.api.PDFFormRenderOptions;
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 java.util.ArrayList;
import java.util.List;
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={"RenderPDFFormProcess"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"RenderPDFFormProcess"})})
public class RenderPDFFormProcess
extends AEMFDWorkflowProcess {
    private static Logger logger = LoggerFactory.getLogger(RenderPDFFormProcess.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 SUBMIT_URL_PARAM = "submiturl";
    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
    FormsService formsService;

    @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");
            PDFFormRenderOptions options = this.createPDFRenderOptions(workItem, workflowSession, metaDataMap);
            Document document = this.formsService.renderPDFForm(template, dataDoc, options);
            FormsUtil.saveDocument(workItem, workflowSession, document, "outputpdf");
        }
        catch (Exception e) {
            throw new WorkflowException((Throwable)e);
        }
    }

    private PDFFormRenderOptions createPDFRenderOptions(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        PDFFormRenderOptions options = new PDFFormRenderOptions();
        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("submiturl", String.class) != null) {
            logger.debug("submiturl=" + (String)metaDataMap.get("submiturl", String.class));
            ArrayList<Object> list = new ArrayList<Object>();
            list.add(metaDataMap.get("submiturl", String.class));
            options.setSubmitUrls(list);
        }
        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 bindFormsService(FormsService formsService) {
        this.formsService = formsService;
    }

    protected void unbindFormsService(FormsService formsService) {
        if (this.formsService == formsService) {
            this.formsService = null;
        }
    }
}