Picture.java 3.68 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.xfa.template.formatting;

import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.ProtoableNode;
import com.adobe.xfa.ScriptTable;
import com.adobe.xfa.TextNode;
import com.adobe.xfa.XFA;
import com.adobe.xfa.template.formatting.PictureScript;
import com.adobe.xfa.ut.BooleanHolder;
import com.adobe.xfa.ut.PictureFmt;
import com.adobe.xfa.ut.StringHolder;
import com.adobe.xfa.ut.StringUtils;
import org.xml.sax.Attributes;

public final class Picture
extends ProtoableNode {
    public Picture(Element parent, Node prevSibling) {
        super(parent, prevSibling, null, "picture", "picture", null, XFA.PICTURETAG, "picture");
    }

    public boolean formatString(String sSource, String sLocale, StringBuilder sResult) {
        Element poParent;
        String sMask = "";
        TextNode oTextNode = this.getText(true, false, false);
        if (oTextNode != null) {
            sMask = oTextNode.getValue();
        }
        if (StringUtils.isEmpty(sMask)) {
            return true;
        }
        for (poParent = this.getXFAParent(); poParent != null && !poParent.isSameClass(XFA.FIELDTAG); poParent = poParent.getXFAParent()) {
        }
        Element poValueNode = null;
        if (poParent != null) {
            poValueNode = poParent.getElement(XFA.VALUETAG, true, 0, true, false);
        }
        Node poContentNode = null;
        if (poValueNode != null) {
            poContentNode = poValueNode.getOneOfChild(false, true);
        }
        if (poContentNode != null && poContentNode.isSameClass(XFA.TEXTTAG) && PictureFmt.isTextPicture(sMask)) {
            return PictureFmt.formatText(sSource, sMask, sLocale, sResult);
        }
        PictureFmt oPict = new PictureFmt(sLocale);
        return oPict.format(sSource, sMask, sResult);
    }

    public String getValue() {
        String sValue = "";
        TextNode oTextNode = this.getText(true, false, false);
        if (oTextNode != null) {
            sValue = oTextNode.getValue();
        }
        return sValue;
    }

    public void setNumericAttributes() {
    }

    public void setValue(String sText) {
        if (sText == null) {
            return;
        }
        TextNode oTextNode = this.getText(false, false, false);
        oTextNode.setValue(sText, true, false);
        this.notifyPeers(2, "", this);
    }

    public String unformatString(String sSource, String sLocale, BooleanHolder pbSuccess) {
        Element poParent;
        String sMask = "";
        TextNode oTextNode = this.getText(true, false, false);
        if (oTextNode != null) {
            sMask = oTextNode.getValue();
        }
        for (poParent = this.getXFAParent(); poParent != null && !poParent.isSameClass(XFA.FIELDTAG); poParent = poParent.getXFAParent()) {
        }
        Element poValueNode = null;
        if (poParent != null) {
            poValueNode = poParent.getElement(XFA.VALUETAG, true, 0, true, false);
        }
        Node poContentNode = null;
        if (poValueNode != null) {
            poContentNode = poValueNode.getOneOfChild(false, true);
        }
        if (poContentNode != null && poContentNode.isSameClass(XFA.TEXTTAG) && PictureFmt.isTextPicture(sMask)) {
            StringHolder sResult = new StringHolder();
            boolean bSuccess = PictureFmt.parseText(sSource, sMask, sLocale, sResult);
            if (pbSuccess != null) {
                pbSuccess.value = bSuccess;
            }
            return sResult.value;
        }
        PictureFmt oPict = new PictureFmt(sLocale);
        return oPict.parse(sSource, sMask, pbSuccess);
    }

    @Override
    public ScriptTable getScriptTable() {
        return PictureScript.getScriptTable();
    }
}