FormsServiceClient.java 13.1 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.idp.Document
 *  com.adobe.idp.dsc.DSCException
 *  com.adobe.idp.dsc.InvocationRequest
 *  com.adobe.idp.dsc.InvocationResponse
 *  com.adobe.idp.dsc.clientsdk.ServiceClient
 *  com.adobe.idp.dsc.clientsdk.ServiceClientFactory
 */
package com.adobe.livecycle.formsservice.client;

import com.adobe.idp.Document;
import com.adobe.idp.dsc.DSCException;
import com.adobe.idp.dsc.InvocationRequest;
import com.adobe.idp.dsc.InvocationResponse;
import com.adobe.idp.dsc.clientsdk.ServiceClient;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.livecycle.formsservice.client.ActivityGuideRenderSpec;
import com.adobe.livecycle.formsservice.client.FormsResult;
import com.adobe.livecycle.formsservice.client.HTMLRenderSpec;
import com.adobe.livecycle.formsservice.client.PDFFormRenderSpec;
import com.adobe.livecycle.formsservice.client.ReaderExtensionSpec;
import com.adobe.livecycle.formsservice.client.RenderOptionsSpec;
import com.adobe.livecycle.formsservice.client.TransformTo;
import com.adobe.livecycle.formsservice.client.URLSpec;
import com.adobe.livecycle.formsservice.exception.FormServerException;
import com.adobe.livecycle.formsservice.exception.ProcessFormSubmissionException;
import com.adobe.livecycle.formsservice.exception.RenderFormException;
import com.adobe.livecycle.formsservice.logging.FormsLogger;
import com.adobe.livecycle.formsservice.utils.FormsServiceClientUtils;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class FormsServiceClient {
    private ServiceClientFactory m_ServiceClientFactory = null;
    private final String FORMS_SERVICE_NAME = "FormsService";
    private ArrayList m_oDocuments = new ArrayList();
    private ArrayList m_oDocNames = new ArrayList();

    public FormsServiceClient(ServiceClientFactory serviceClientFactory) {
        this.m_ServiceClientFactory = serviceClientFactory;
    }

    @Deprecated
    public FormsResult renderHTMLForm(String formQuery, TransformTo transformTo, Document inDataDoc, HTMLRenderSpec htmlRenderSpec, String userAgent, URLSpec urlSpec, Map attachments) throws RenderFormException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("formQuery", formQuery);
        oInput.put("transformTo", (Object)transformTo);
        oInput.put("inDataDoc", (Object)inDataDoc);
        oInput.put("htmlRenderSpec", htmlRenderSpec);
        oInput.put("userAgent", userAgent);
        oInput.put("urlSpec", urlSpec);
        oInput.put("attachments", this.consolidateAttachments(attachments));
        try {
            InvocationResponse oResponse = this.invokeRequest("renderHTMLForm", oInput);
            return (FormsResult)oResponse.getOutputParameter("renderHTMLFormResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof RenderFormException) {
                RenderFormException ce = (RenderFormException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new RenderFormException(e);
        }
    }

    @Deprecated
    public FormsResult renderHTMLForm2(Document inFormDoc, TransformTo transformTo, Document inDataDoc, HTMLRenderSpec htmlRenderSpec, String userAgent, URLSpec urlSpec, Map attachments) throws RenderFormException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("inFormDoc", (Object)inFormDoc);
        oInput.put("transformTo", (Object)transformTo);
        oInput.put("inDataDoc", (Object)inDataDoc);
        oInput.put("htmlRenderSpec", htmlRenderSpec);
        oInput.put("userAgent", userAgent);
        oInput.put("urlSpec", urlSpec);
        oInput.put("attachments", this.consolidateAttachments(attachments));
        try {
            InvocationResponse oResponse = this.invokeRequest("renderHTMLForm2", oInput);
            return (FormsResult)oResponse.getOutputParameter("renderHTMLFormResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof RenderFormException) {
                RenderFormException ce = (RenderFormException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new RenderFormException(e);
        }
    }

    public FormsResult renderPDFForm(String formQuery, Document inDataDoc, PDFFormRenderSpec pdfFormRenderSpec, URLSpec urlSpec, Map attachments) throws RenderFormException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("formQuery", formQuery);
        oInput.put("inDataDoc", (Object)inDataDoc);
        oInput.put("pdfFormRenderSpec", pdfFormRenderSpec);
        oInput.put("urlSpec", urlSpec);
        oInput.put("attachments", this.consolidateAttachments(attachments));
        try {
            InvocationResponse oResponse = this.invokeRequest("renderPDFForm", oInput);
            return (FormsResult)oResponse.getOutputParameter("renderPDFFormResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof RenderFormException) {
                RenderFormException ce = (RenderFormException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new RenderFormException(e);
        }
    }

    public FormsResult renderPDFForm2(Document inFormDoc, Document inDataDoc, PDFFormRenderSpec pdfFormRenderSpec, URLSpec urlSpec, Map attachments) throws RenderFormException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("inFormDoc", (Object)inFormDoc);
        oInput.put("inDataDoc", (Object)inDataDoc);
        oInput.put("pdfFormRenderSpec", pdfFormRenderSpec);
        oInput.put("urlSpec", urlSpec);
        oInput.put("attachments", this.consolidateAttachments(attachments));
        try {
            InvocationResponse oResponse = this.invokeRequest("renderPDFForm2", oInput);
            return (FormsResult)oResponse.getOutputParameter("renderPDFFormResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof RenderFormException) {
                RenderFormException ce = (RenderFormException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new RenderFormException(e);
        }
    }

    public FormsResult renderPDFFormWithUsageRights(String formQuery, Document inDataDoc, PDFFormRenderSpec pdfFormRenderSpec, ReaderExtensionSpec readerExtensionSpec, URLSpec urlSpec) throws RenderFormException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("formQuery", formQuery);
        oInput.put("inDataDoc", (Object)this.mergeAttachmentsWithData(inDataDoc));
        oInput.put("pdfFormRenderSpec", pdfFormRenderSpec);
        oInput.put("readerExtensionSpec", readerExtensionSpec);
        oInput.put("urlSpec", urlSpec);
        try {
            InvocationResponse oResponse = this.invokeRequest("renderPDFFormWithUsageRights", oInput);
            return (FormsResult)oResponse.getOutputParameter("renderPDFFormWithUsageRightsResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof RenderFormException) {
                RenderFormException ce = (RenderFormException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new RenderFormException(e);
        }
    }

    @Deprecated
    public FormsResult renderFormGuide(String formQuery, Document inDataDoc, PDFFormRenderSpec pdfFormRenderSpec, ActivityGuideRenderSpec activityGuideRenderSpec, URLSpec urlSpec) throws RenderFormException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("formQuery", formQuery);
        oInput.put("inDataDoc", (Object)this.mergeAttachmentsWithData(inDataDoc));
        oInput.put("pdfFormRenderSpec", pdfFormRenderSpec);
        oInput.put("activityGuideRenderSpec", activityGuideRenderSpec);
        oInput.put("urlSpec", urlSpec);
        try {
            InvocationResponse oResponse = this.invokeRequest("renderFormGuide", oInput);
            return (FormsResult)oResponse.getOutputParameter("renderFormGuideResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof RenderFormException) {
                RenderFormException ce = (RenderFormException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new RenderFormException(e);
        }
    }

    public FormsResult processFormSubmission(Document inRequestDoc, String environmentBuffer, String userAgent, RenderOptionsSpec processFormSubmissionOptionsSpec) throws ProcessFormSubmissionException, DSCException {
        HashMap<String, Object> oInput = new HashMap<String, Object>();
        oInput.put("inRequestDoc", (Object)inRequestDoc);
        oInput.put("environmentBuffer", environmentBuffer);
        oInput.put("userAgent", userAgent);
        oInput.put("processFormSubmissionOptionsSpec", processFormSubmissionOptionsSpec);
        try {
            InvocationResponse oResponse = this.invokeRequest("processFormSubmission", oInput);
            return (FormsResult)oResponse.getOutputParameter("processFormSubmissionResult");
        }
        catch (DSCException e) {
            if (e.getCause() instanceof ProcessFormSubmissionException) {
                ProcessFormSubmissionException ce = (ProcessFormSubmissionException)e.getCause();
                throw ce;
            }
            throw e;
        }
        catch (Exception e) {
            throw new ProcessFormSubmissionException(e);
        }
    }

    private InvocationResponse invokeRequest(String sOperationName, HashMap oInput) throws DSCException {
        InvocationRequest oRequest = this.m_ServiceClientFactory.createInvocationRequest("FormsService", sOperationName, (Map)oInput, true);
        return this.m_ServiceClientFactory.getServiceClient().invoke(oRequest);
    }

    public void addDocument(Document oDoc, String displayName) {
        if (oDoc != null) {
            if (displayName == null || displayName.length() == 0) {
                displayName = "Attachment_" + (this.m_oDocuments.size() + 1);
            }
            if (this.m_oDocNames.contains(displayName)) {
                FormsLogger.logMessage(this.getClass(), 4, "ALC-FRM-001-049", new String[]{displayName});
            } else {
                this.m_oDocNames.add(displayName);
            }
            oDoc.setAttribute("name", (Serializable)((Object)displayName));
            this.m_oDocuments.add(oDoc);
        }
    }

    public void removeDocument(String name) {
        if (name != null && name.length() > 0) {
            for (int i = 0; i < this.m_oDocuments.size(); ++i) {
                Document oDoc = (Document)this.m_oDocuments.get(i);
                if (!oDoc.getAttribute("name").equals(name)) continue;
                this.m_oDocuments.remove(i);
            }
            this.m_oDocNames.remove(name);
        }
    }

    public void resetCache() throws FormServerException, DSCException {
        try {
            this.invokeRequest("resetCache", new HashMap());
        }
        catch (DSCException e) {
            if (e.getCause() instanceof FormServerException) {
                FormServerException fse = (FormServerException)e.getCause();
                throw fse;
            }
            throw e;
        }
        catch (Exception e) {
            throw new FormServerException(e);
        }
    }

    public ArrayList getDocuments() {
        return this.m_oDocuments;
    }

    private Map consolidateAttachments(Map attachments) {
        if (this.m_oDocuments.size() > 0) {
            if (attachments == null) {
                attachments = new LinkedHashMap<String, Document>();
            }
            Document doc = null;
            for (int i = 0; i < this.m_oDocuments.size(); ++i) {
                doc = (Document)this.m_oDocuments.get(i);
                String docName = (String)((Object)doc.getAttribute("name"));
                if (docName == null) continue;
                attachments.put(docName, doc);
            }
        }
        return attachments;
    }

    private Document mergeAttachmentsWithData(Document inDataDoc) throws RenderFormException {
        byte[] cXMLData = null;
        Document oInputData = inDataDoc;
        if (this.m_oDocuments.size() > 0) {
            try {
                cXMLData = FormsServiceClientUtils.serializeDoc(inDataDoc);
                cXMLData = FormsServiceClientUtils.combineDocsWith(cXMLData, this.m_oDocuments);
                if (cXMLData == null) {
                    cXMLData = "".getBytes();
                }
                oInputData = new Document(cXMLData);
            }
            catch (IOException ioe) {
                throw new RenderFormException(ioe);
            }
        }
        return oInputData;
    }
}