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

import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Int;
import com.adobe.xfa.Node;
import com.adobe.xfa.ProtoableNode;
import com.adobe.xfa.XFA;
import org.xml.sax.Attributes;

public final class Occur
extends ProtoableNode {
    public Occur(Element parent, Node prevSibling) {
        super(parent, prevSibling, null, "occur", "occur", null, XFA.OCCURTAG, "occur");
    }

    @Override
    public Attribute defaultAttribute(int eTag) {
        Int oMin;
        Element poParent = this.getXFAParent();
        if (null != poParent && (poParent.isSameClass(XFA.PAGEAREATAG) || poParent.isSameClass(XFA.PAGESETTAG))) {
            if (eTag == XFA.MINTAG) {
                return new Int("min", 0, false);
            }
            if (eTag == XFA.MAXTAG) {
                return new Int("max", -1, false);
            }
        }
        if (eTag == XFA.INITIALTAG) {
            return this.getAttribute(XFA.MINTAG);
        }
        if (eTag == XFA.MAXTAG && (oMin = (Int)this.getAttribute(XFA.MINTAG)).getValue() > 0) {
            return oMin;
        }
        return super.defaultAttribute(eTag);
    }

    @Override
    public Attribute getAttribute(int eTag, boolean bPeek, boolean bValidate) {
        Int minVal;
        Int oValue;
        Attribute oProperty = super.getAttribute(eTag, bPeek, bValidate);
        if (oProperty == null) {
            return oProperty;
        }
        if (eTag == XFA.INITIALTAG) {
            Int maxVal;
            oValue = (Int)oProperty;
            if (this.isPropertySpecified(XFA.MINTAG, true, 0)) {
                minVal = (Int)this.getAttribute(XFA.MINTAG);
                if (oValue.getValue() < minVal.getValue()) {
                    this.foundBadAttribute(eTag, oValue.toString());
                    return minVal;
                }
            }
            if (this.isPropertySpecified(XFA.MAXTAG, true, 0) && (maxVal = (Int)this.getAttribute(XFA.MAXTAG)).getValue() != -1 && oValue.getValue() > maxVal.getValue()) {
                this.foundBadAttribute(eTag, oValue.toString());
                return maxVal;
            }
        }
        if (eTag == XFA.MINTAG && (oValue = (Int)oProperty).getValue() < 0) {
            this.foundBadAttribute(eTag, oValue.toString());
            return this.defaultAttribute(eTag);
        }
        if (eTag == XFA.MAXTAG) {
            oValue = (Int)oProperty;
            minVal = (Int)this.getAttribute(XFA.MINTAG);
            if (oValue.getValue() < -1 || oValue.getValue() != -1 && oValue.getValue() < minVal.getValue()) {
                this.foundBadAttribute(eTag, oValue.toString());
                return minVal;
            }
        }
        return oProperty;
    }

    int getMaximum() {
        Int oMax = (Int)this.getAttribute(XFA.MAXTAG);
        return oMax.getValue();
    }

    int getMinimum() {
        Int oMin = (Int)this.getAttribute(XFA.MINTAG);
        return oMin.getValue();
    }

    int getInitial() {
        Int oInit = (Int)this.getAttribute(XFA.INITIALTAG);
        return oInit.getValue();
    }
}