FieldScript.java 15.8 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xfa.template.containers;

import com.adobe.xfa.Arg;
import com.adobe.xfa.Node;
import com.adobe.xfa.Obj;
import com.adobe.xfa.ScriptFuncObj;
import com.adobe.xfa.ScriptPropObj;
import com.adobe.xfa.ScriptTable;
import com.adobe.xfa.data.DataNode;
import com.adobe.xfa.template.Items;
import com.adobe.xfa.template.containers.ContainerScript;
import com.adobe.xfa.template.containers.Field;
import com.adobe.xfa.template.containers.Subform;
import com.adobe.xfa.ut.StringUtils;

public class FieldScript
extends ContainerScript {
    protected static final ScriptTable moScriptTable = new ScriptTable(ContainerScript.moScriptTable, "field", new ScriptPropObj[]{new ScriptPropObj(FieldScript.class, "rawValue", "getRawValue", "setRawValue", 0, 21, 63, 0), new ScriptPropObj(FieldScript.class, null, "getRawValue", "setRawValue", 0, 21, 9, 0), new ScriptPropObj(FieldScript.class, "formattedValue", "getFormattedValue", "setFormattedValue", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "editValue", "getEditValue", "setEditValue", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "isNull", "getIsNull", "setIsNull", 3, 21, 63, 0), new ScriptPropObj(FieldScript.class, "mandatory", "getMandatory", "setMandatory", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "message", "getValidationMessage", "setValidationMessage", 6, 21, 0, 22), new ScriptPropObj(FieldScript.class, "validationMessage", "getValidationMessage", "setValidationMessage", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "mandatoryMessage", "getMandatoryMessage", "setMandatoryMessage", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "formatMessage", "getFormatMessage", "setFormatMessage", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "foreColor", "getForeColor", "setForeColor", 6, 21, 0, 22), new ScriptPropObj(FieldScript.class, "fontColor", "getForeColor", "setForeColor", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "backColor", "getBackColor", "setBackColor", 6, 21, 0, 22), new ScriptPropObj(FieldScript.class, "fillColor", "getBackColor", "setBackColor", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "borderColor", "getBorderColor", "setBorderColor", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "borderWidth", "getBorderWidth", "setBorderWidth", 6, 21, 63, 0), new ScriptPropObj(FieldScript.class, "parentSubform", "getParentSubform", null, 7, 21, 63, 0), new ScriptPropObj(FieldScript.class, "dataNode", "dataNode", null, 7, 21, 9, 0), new ScriptPropObj(FieldScript.class, "length", "getItemsLength", null, 4, 25, 63, 0), new ScriptPropObj(FieldScript.class, "selectedIndex", "getSelectedIndex", "setSelectedIndex", 4, 25, 63, 0), new ScriptPropObj(FieldScript.class, "errorText", "getErrorText", null, 6, 30, 63, 0)}, new ScriptFuncObj[]{new ScriptFuncObj(FieldScript.class, "addItem", "addItem", 1, new int[]{6, 6}, 1, 21, 63, "addItemPermsCheck", 0), new ScriptFuncObj(FieldScript.class, "setItems", "setItems", 3, new int[]{6, 4}, 1, 28, 63, "clearItemsPermsCheck", 0), new ScriptFuncObj(FieldScript.class, "clearItems", "clearItems", 1, new int[0], 0, 21, 63, "clearItemsPermsCheck", 0), new ScriptFuncObj(FieldScript.class, "deleteItem", "deleteItem", 3, new int[]{4}, 1, 25, 63, "deleteItemPermsCheck", 0), new ScriptFuncObj(FieldScript.class, "boundItem", "boundItem", 6, new int[]{6}, 1, 21, 63, 0), new ScriptFuncObj(FieldScript.class, "execCalculate", "execCalculate", 1, new int[0], 0, 21, 63, 0), new ScriptFuncObj(FieldScript.class, "execValidate", "execValidate", 3, new int[0], 0, 21, 63, 0), new ScriptFuncObj(FieldScript.class, "execInitialize", "execInitialize", 1, new int[0], 0, 21, 63, 0), new ScriptFuncObj(FieldScript.class, "execEvent", "execEvent", 1, new int[]{6}, 1, 21, 63, 0), new ScriptFuncObj(FieldScript.class, "getItemState", "getItemState", 3, new int[]{4}, 1, 25, 63, 0), new ScriptFuncObj(FieldScript.class, "setItemState", "setItemState", 1, new int[]{4, 3}, 2, 25, 63, "setItemStatePermsCheck", 0), new ScriptFuncObj(FieldScript.class, "getDisplayItem", "getDisplayItem", 6, new int[]{4}, 1, 25, 63, 0), new ScriptFuncObj(FieldScript.class, "getSaveItem", "getSaveItem", 6, new int[]{4}, 1, 25, 63, 0)});
    private static final String sSkipSet = "\\,";

    public static ScriptTable getScriptTable() {
        return moScriptTable;
    }

    public static void getRawValue(Obj pObj, Arg oRetVal) {
        if (!((Field)pObj).getIsNull()) {
            ((Field)pObj).getTypedRawValue(oRetVal);
        } else {
            oRetVal.setNull();
        }
    }

    public static void setRawValue(Obj pObj, Arg propertyValue) {
        String sValue = null;
        if (propertyValue.getArgType() != 2) {
            sValue = propertyValue.getAsString(false);
        }
        ((Field)pObj).setRawValue(sValue);
    }

    public static void getFormattedValue(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getFormattedValue());
    }

    public static void setFormattedValue(Obj pObj, Arg propertyValue) {
        String sValue = null;
        if (propertyValue.getArgType() != 2) {
            sValue = propertyValue.getAsString(false);
        }
        ((Field)pObj).setFormattedValue(sValue);
    }

    public static void getEditValue(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getEditValue());
    }

    public static void setEditValue(Obj pObj, Arg propertyValue) {
        String sValue = null;
        if (propertyValue.getArgType() != 2) {
            sValue = propertyValue.getAsString(false);
        }
        ((Field)pObj).setEditValue(sValue);
    }

    public static void getMandatory(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getMandatory());
    }

    public static void setMandatory(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setMandatory(propertyValue.getString());
    }

    public static void getValidationMessage(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getMessage("scriptTest"));
    }

    public static void setValidationMessage(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setMessage(propertyValue.getString(), "scriptTest");
    }

    public static void getMandatoryMessage(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getMessage("nullTest"));
    }

    public static void setMandatoryMessage(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setMessage(propertyValue.getString(), "nullTest");
    }

    public static void getFormatMessage(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getMessage("formatTest"));
    }

    public static void setFormatMessage(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setMessage(propertyValue.getString(), "formatTest");
    }

    public static void getForeColor(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getForeColor());
    }

    public static void setForeColor(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setForeColor(propertyValue.getString());
    }

    public static void getBackColor(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getBackColor());
    }

    public static void setBackColor(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setBackColor(propertyValue.getString());
    }

    public static void getBorderColor(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getBorderColor());
    }

    public static void setBorderColor(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setBorderColor(propertyValue.getString());
    }

    public static void getBorderWidth(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getBorderWidth());
    }

    public static void setBorderWidth(Obj pObj, Arg propertyValue) {
        ((Field)pObj).setBorderWidth(propertyValue.getString());
    }

    public static void getParentSubform(Obj pObj, Arg oRetVal) {
        oRetVal.setObject(((Field)pObj).getParentSubform());
    }

    public static void getIsNull(Obj pObj, Arg oRetVal) {
        oRetVal.setBool(((Field)pObj).getIsNull());
    }

    public static void setIsNull(Obj pObj, Arg oArg) {
        ((Field)pObj).setIsNull(oArg.getBool(), true);
    }

    public static void dataNode(Obj pObj, Arg oRetVal) {
        oRetVal.setObject(((Field)pObj).getDataNode());
    }

    public static void getItemsLength(Obj pObj, Arg oRetVal) {
        oRetVal.setInteger(((Field)pObj).getItemsLength());
    }

    public static void getErrorText(Obj pObj, Arg oRetVal) {
        oRetVal.setString(((Field)pObj).getErrorText());
    }

    public static void getSelectedIndex(Obj pObj, Arg oRetVal) {
        oRetVal.setInteger(((Field)pObj).getSelectedIndex());
    }

    public static void setSelectedIndex(Obj pObj, Arg oArg) {
        ((Field)pObj).setSelectedIndex(oArg.getInteger());
    }

    public static boolean addItemPermsCheck(Obj obj, Arg[] args) {
        Node node;
        if (obj instanceof Node && !(node = (Node)obj).checkAncestorPerms()) {
            return false;
        }
        return true;
    }

    public static boolean clearItemsPermsCheck(Obj obj, Arg[] args) {
        if (obj instanceof Field) {
            Field field = (Field)obj;
            if (!field.checkAncestorPerms()) {
                return false;
            }
            Field.ItemPair items = new Field.ItemPair();
            field.getItemLists(false, items, false);
            if (items.mSaveItems != null && !items.mSaveItems.checkDescendentPerms()) {
                return false;
            }
            if (items.mDisplayItems != null && !items.mDisplayItems.checkDescendentPerms()) {
                return false;
            }
        }
        return true;
    }

    public static boolean deleteItemPermsCheck(Obj obj, Arg[] args) {
        Node node;
        if (obj instanceof Node && !(node = (Node)obj).checkAncestorPerms()) {
            return false;
        }
        return true;
    }

    public static boolean setItemStatePermsCheck(Obj obj, Arg[] args) {
        Node node;
        if (obj instanceof Node && !(node = (Node)obj).checkAncestorPerms()) {
            return false;
        }
        return true;
    }

    public static void addItem(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        String sDisplayVal = null;
        String sSaveVal = null;
        Field.ItemPair items = new Field.ItemPair();
        if (pArgs.length == 1) {
            ((Field)pObj).getItemLists(false, items, false);
            sSaveVal = sDisplayVal = pArgs[0].getAsString(false);
        } else if (pArgs.length == 2) {
            ((Field)pObj).getItemLists(false, items, true);
            sDisplayVal = pArgs[0].getAsString(false);
            sSaveVal = pArgs[1].getAsString(false);
        }
        Items oSaveItems = items.mSaveItems;
        Items oDisplayItems = items.mDisplayItems;
        if (oDisplayItems != null) {
            oDisplayItems.addItem(sDisplayVal, false);
        }
        if (oSaveItems != null && oSaveItems != oDisplayItems) {
            oSaveItems.addItem(sSaveVal, false);
        }
    }

    public static void clearItems(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        ((Field)pObj).clearItems();
    }

    public static void setItems(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        String sDisplayVal = "";
        int numColumns = 1;
        ((Field)pObj).clearItems();
        String sItemValueList = pArgs[0].getAsString(false);
        StringBuilder sToken = new StringBuilder();
        if (pArgs.length == 2) {
            numColumns = pArgs[1].getInteger();
        }
        if (numColumns > 2) {
            oRetVal.setBool(false);
            return;
        }
        boolean bMultiColumn = numColumns > 1;
        int len = sItemValueList.length();
        int nPrevEndToken = 0;
        int numDisplayItems = 0;
        int numSaveValues = 0;
        Field.ItemPair itemPair = new Field.ItemPair();
        ((Field)pObj).getItemLists(false, itemPair, bMultiColumn);
        Items oDisplayItems = itemPair.mDisplayItems;
        Items oSaveItems = itemPair.mSaveItems;
        int nBeginToken = 0;
        while (nBeginToken < len) {
            String sSaveVal;
            int col = 0;
            int nTokenLen = 0;
            for (col = 0; col < numColumns - 1; ++col) {
                nTokenLen = StringUtils.skipUntil(sItemValueList, "\\,", nBeginToken);
                sToken.setLength(0);
                sToken.append(sItemValueList.substring(nBeginToken, nTokenLen));
                nPrevEndToken = nBeginToken + nTokenLen;
                nBeginToken = nPrevEndToken + 1;
                while (sItemValueList.charAt(nPrevEndToken) == '\\') {
                    sToken.append(sItemValueList.charAt(nBeginToken));
                    nTokenLen = StringUtils.skipUntil(sItemValueList, "\\,", nBeginToken);
                    sToken.append(sItemValueList.substring(nBeginToken, nTokenLen));
                    nPrevEndToken = nBeginToken + nTokenLen;
                    nBeginToken = nPrevEndToken + 1;
                }
                sDisplayVal = sToken.toString();
                ++numDisplayItems;
                if (oDisplayItems == null) continue;
                oDisplayItems.addItem(sDisplayVal, false);
            }
            if (nBeginToken <= len) {
                nTokenLen = StringUtils.skipUntil(sItemValueList, "\\,", nBeginToken);
                sToken.setLength(0);
                sToken.append(sItemValueList.substring(nBeginToken, nTokenLen));
                nPrevEndToken = nBeginToken + nTokenLen;
                nBeginToken = nPrevEndToken + 1;
                while (sItemValueList.charAt(nPrevEndToken) == '\\') {
                    sToken.append(sItemValueList.charAt(nBeginToken));
                    nTokenLen = StringUtils.skipUntil(sItemValueList, "\\,", nBeginToken);
                    sToken.append(sItemValueList.substring(nBeginToken, nTokenLen));
                    nPrevEndToken = nBeginToken + nTokenLen;
                    nBeginToken = nPrevEndToken + 1;
                }
                ++numSaveValues;
            }
            if ((sSaveVal = sToken.toString()).length() == 0) {
                sSaveVal = sDisplayVal;
            }
            if (!bMultiColumn && oDisplayItems != null) {
                oDisplayItems.addItem(sSaveVal, false);
            }
            if (oSaveItems == null || oSaveItems == oDisplayItems) continue;
            oSaveItems.addItem(sSaveVal, false);
        }
        oRetVal.setBool(true);
        if (bMultiColumn && numDisplayItems != (numColumns - 1) * numSaveValues) {
            oRetVal.setBool(true);
        }
    }

    public static void deleteItem(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        oRetVal.setBool(((Field)pObj).deleteItem(pArgs[0].getInteger()));
    }

    public static void execCalculate(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        ((Field)pObj).execEvent("calculate");
    }

    public static void execValidate(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        oRetVal.setBool(((Field)pObj).execValidate());
    }

    public static void execInitialize(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        ((Field)pObj).execEvent("initialize");
    }

    public static void execEvent(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        ((Field)pObj).execEvent(pArgs[0].getString());
    }

    public static void boundItem(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        oRetVal.setString(((Field)pObj).getBoundItem(pArgs[0].getString()));
    }

    public static void getItemState(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        oRetVal.setBool(((Field)pObj).getItemState(pArgs[0].getInteger()));
    }

    public static void setItemState(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        ((Field)pObj).setItemState(pArgs[0].getInteger(), pArgs[1].getBool());
    }

    public static void getDisplayItem(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        oRetVal.setString(((Field)pObj).getDisplayItem(pArgs[0].getInteger()));
    }

    public static void getSaveItem(Obj pObj, Arg oRetVal, Arg[] pArgs) {
        oRetVal.setString(((Field)pObj).getBoundItem(pArgs[0].getInteger()));
    }
}