FormsResult.java 9.81 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.idp.Document
 */
package com.adobe.livecycle.formsservice.client;

import com.adobe.idp.Document;
import com.adobe.livecycle.formsservice.client.interfaces.IOutputContext;
import com.adobe.livecycle.formsservice.client.interfaces.IOutputContext2;
import com.adobe.livecycle.formsservice.utils.FormsServiceClientUtils;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.List;

public class FormsResult
implements IOutputContext,
IOutputContext2,
Serializable {
    static final long serialVersionUID = 2753066154777654131L;
    private static transient String XML_CONTENT = "text/xml";
    private static transient String XDP_XML_CONTENT = "application/vnd.adobe.xdp+xml";
    private static transient String HTML_CONTENT = "text/html";
    private static transient String NBSP = " ";
    private static transient String DEF_CHARSET = "iso-8859-1";
    private static transient String DEF_LOCALE = "en";
    private Document Null_Document = new Document(new byte[0]);
    private Document outputContent = new Document(this.Null_Document);
    private String contentType;
    private String clickedBtn;
    private Document outputXML;
    private Document validationErrorsList = new Document(this.Null_Document);
    private short action;
    private String transformationID;
    private String options;
    private Document xMLData = new Document(this.Null_Document);
    private String formQuery;
    private long pageNumber;
    private long pageCount;
    private List attachments;
    private String charSet;
    private String locale;
    private int outputType;

    public FormsResult() {
        this.setOptions("");
        this.pageNumber = 0;
        this.pageCount = 0;
        this.formQuery = null;
        this.contentType = "";
        this.outputXML = new Document(this.Null_Document);
        this.outputContent = new Document(this.Null_Document);
    }

    public FormsResult(short action, String options, String tratransformationID, String formQuery, long pageNumber, long pageCount, List attachments, Document validationErrorsList, String clickedBtn, Document xMLData) {
        this.action = action;
        this.setOptions(options);
        this.transformationID = tratransformationID;
        this.formQuery = formQuery;
        this.pageNumber = pageNumber;
        this.pageCount = pageCount;
        this.attachments = attachments;
        this.setValidationErrorsList(validationErrorsList);
        this.clickedBtn = clickedBtn;
        this.xMLData = xMLData;
    }

    private void setOptions(String opts) {
        this.options = opts;
        if (this.options != null && this.options.length() > 0) {
            this.charSet = this.getOption("charset");
            this.locale = this.getOption("Locale");
            if (this.getOption("OutputType") != null) {
                this.outputType = Integer.valueOf(this.getOption("OutputType"));
            }
        } else {
            this.charSet = DEF_CHARSET;
            this.locale = DEF_LOCALE;
            this.outputContent = new Document(this.Null_Document);
            this.outputType = 0;
        }
    }

    private void setValidationErrorsList(Document cValidationErrorsList) {
        if (cValidationErrorsList != null) {
            this.validationErrorsList = cValidationErrorsList;
            this.validationErrorsList.setContentType(XML_CONTENT);
        }
    }

    @Override
    public Document getOutputContent() throws UnsupportedEncodingException {
        Document doc = null;
        byte[] cOut = new byte[]{};
        byte[] convertedBytes = new byte[]{};
        if (this.contentType.equalsIgnoreCase(HTML_CONTENT)) {
            convertedBytes = this.convertOutputContent(FormsServiceClientUtils.getBytes(this.outputXML));
            if (this.charSet != null && this.charSet.length() > 0 && !this.charSet.equalsIgnoreCase("UTF-8") && !this.charSet.equalsIgnoreCase("UTF8")) {
                String temp = new String(convertedBytes, "UTF8");
                cOut = temp.getBytes(this.charSet);
            } else {
                cOut = convertedBytes;
            }
            doc = new Document(cOut);
        } else {
            doc = this.contentType.equalsIgnoreCase(XML_CONTENT) || this.contentType.equalsIgnoreCase(XDP_XML_CONTENT) ? this.outputXML : this.outputContent;
        }
        doc.setContentType(this.getContentType());
        return doc;
    }

    @Override
    public String getContentType() {
        String charset = this.getCharSet();
        if (this.contentType.equalsIgnoreCase(HTML_CONTENT) && charset != null && charset.length() > 0) {
            return this.contentType + "; charset=" + charset;
        }
        return this.contentType;
    }

    @Override
    public String getCharSet() {
        if (this.contentType != null) {
            if (this.contentType.equalsIgnoreCase(HTML_CONTENT)) {
                return this.charSet;
            }
            if (this.contentType.equalsIgnoreCase(XML_CONTENT) || this.contentType.equalsIgnoreCase(XDP_XML_CONTENT)) {
                return "UTF8";
            }
        }
        return this.charSet;
    }

    @Override
    public String getClickedBtn() {
        return this.clickedBtn;
    }

    @Override
    public String getOutputString() {
        try {
            byte[] cOut = FormsServiceClientUtils.getBytes(this.getOutputContent());
            if (cOut.length > 0 && this.contentType != null) {
                if (this.contentType.equalsIgnoreCase(XML_CONTENT) || this.contentType.equalsIgnoreCase(XDP_XML_CONTENT)) {
                    return new String(FormsServiceClientUtils.getBytes(this.getOutputXML()), "UTF8");
                }
                if (this.contentType.toLowerCase().indexOf("text/") >= 0) {
                    return new String(cOut, "UTF8");
                }
                return null;
            }
        }
        catch (UnsupportedEncodingException e) {
            // empty catch block
        }
        return null;
    }

    @Override
    public Document getOutputXML() {
        return this.outputXML;
    }

    @Override
    public Document getValidationErrorsList() {
        return this.validationErrorsList;
    }

    @Override
    public short getAction() {
        return this.action;
    }

    @Override
    public String getTransformationID() {
        return this.transformationID;
    }

    @Override
    public String getOptions() {
        return this.options;
    }

    @Override
    public Document getXMLData() {
        return this.xMLData;
    }

    @Override
    public String getFormQuery() {
        return this.formQuery;
    }

    @Override
    public long getPageNumber() {
        return this.pageNumber;
    }

    @Override
    public long getPageCount() {
        return this.pageCount;
    }

    @Override
    public List getAttachments() {
        return this.attachments;
    }

    public String getLocale() {
        return this.locale;
    }

    public int getOutputType() {
        return this.outputType;
    }

    @Override
    public void setOutputContent(Document contentDoc, String sContentType) throws Exception {
        if (contentDoc == null) {
            throw new Exception("contentDoc is null.");
        }
        if (sContentType == null || sContentType.length() == 0) {
            throw new Exception("sContentType is not specified.");
        }
        this.contentType = sContentType;
        if (sContentType.equalsIgnoreCase(XML_CONTENT) || sContentType.equalsIgnoreCase(XDP_XML_CONTENT) || sContentType.equalsIgnoreCase(HTML_CONTENT)) {
            this.outputXML = contentDoc;
        } else {
            this.outputContent = contentDoc;
        }
    }

    @Override
    public String getOption(String opt) {
        return FormsServiceClientUtils.getParameter(this.options, opt);
    }

    @Override
    public void setOutputXML(Document outputXML) {
        this.outputXML = outputXML;
    }

    public void setCharSet(String charSet) {
        this.charSet = charSet;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public void setTransformationID(String transformationID) {
        this.transformationID = transformationID;
    }

    private byte[] convertOutputContent(byte[] cInput) throws UnsupportedEncodingException {
        int nInputLength;
        if (cInput == null) {
            return cInput;
        }
        if (this.contentType == null || this.contentType.length() == 0) {
            return cInput;
        }
        if (!this.contentType.equalsIgnoreCase(HTML_CONTENT)) {
            return cInput;
        }
        int nOrigInputLength = nInputLength = cInput.length;
        String transID = this.getTransformationID();
        boolean bStripTags = transID.equalsIgnoreCase("HTML4");
        byte[] cNewArray = new byte[nInputLength * 2];
        int j = 0;
        int i = 0;
        if (bStripTags && (i = FormsServiceClientUtils.findArraySegment(cInput, 0, "<html".getBytes())) < 0) {
            i = 0;
        }
        while (i < nOrigInputLength) {
            if (!(bStripTags && i < nInputLength - 1 && cInput[i] == 47 && cInput[i + 1] == 62 || bStripTags && i < nInputLength - 1 && cInput[i] == 47 && cInput[i + 1] == 62)) {
                if (cInput[i] == -62 && cInput[i + 1] == -96) {
                    byte[] cBytes = NBSP.getBytes("UTF8");
                    int k = 0;
                    while (k < cBytes.length) {
                        cNewArray[j] = cBytes[k];
                        ++k;
                        ++j;
                    }
                    ++i;
                } else {
                    cNewArray[j++] = cInput[i];
                }
            }
            ++i;
        }
        byte[] cTempArray = new byte[j];
        for (i = 0; i < j; ++i) {
            cTempArray[i] = cNewArray[i];
        }
        return cTempArray;
    }
}