DoRElementUtils.java 3.78 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.xfa.Attribute
 *  com.adobe.xfa.Element
 *  com.adobe.xfa.Node
 *  com.adobe.xfa.StringAttr
 *  com.adobe.xfa.XFA
 *  com.adobe.xfa.template.formatting.Occur
 *  org.apache.commons.lang3.StringUtils
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.StringAttr;
import com.adobe.xfa.XFA;
import com.adobe.xfa.template.formatting.Occur;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;

public class DoRElementUtils {
    public static boolean isRepeatable(Element element) {
        Occur occur = (Occur)element.resolveNode("#occur");
        if (occur == null) {
            return false;
        }
        String min = occur.getAttribute(XFA.MINTAG).getAttrValue();
        String max = occur.getAttribute(XFA.MAXTAG).getAttrValue();
        if (min == null || max == null) {
            return false;
        }
        if (min.equals("1") && max.equals("1")) {
            return false;
        }
        return true;
    }

    public static boolean isRepeatable(Properties properties) {
        if (properties.containsKey("minOccur") && properties.containsKey("maxOccur")) {
            String min = properties.getProperty("minOccur");
            String max = properties.getProperty("maxOccur");
            if (!(min == null || max == null || min.isEmpty() || max.isEmpty() || min.equals("1") && max.equals("1"))) {
                return true;
            }
        }
        return false;
    }

    public static String getColumnWidthFromParent(Element xfaElement) {
        int index = xfaElement.getIndex(true);
        String width = null;
        Element parent = xfaElement.getXFAParent();
        Element table = parent.getXFAParent();
        String[] widths = table.getAttribute(XFA.COLUMNWIDTHSTAG).getAttrValue().split(" ");
        if (index < widths.length) {
            width = widths[index];
        }
        return width;
    }

    public static void adaptToTableCell(Element element, String width) {
        StringAttr attribute = new StringAttr("hAlign", "center");
        element.setAttribute((Attribute)attribute, XFA.HALIGNTAG);
        Element caption = (Element)element.resolveNode("#caption");
        if (caption != null) {
            caption.removeAttr(null, "reserve");
        }
        element.removeAttr(null, "w");
        if (width != null) {
            element.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
        }
    }

    public static Node locateChildByName(Node parent, String childName, int nThChild) {
        if (childName == null || parent == null) {
            return null;
        }
        int nFound = 0;
        for (Node child = parent.getFirstXMLChild(); child != null; child = child.getNextXMLSibling()) {
            if (!childName.equals(child.getName())) continue;
            if (nFound == nThChild) {
                return child;
            }
            ++nFound;
        }
        return null;
    }

    public static boolean isTableHeaderRow(Element element) {
        Element assist;
        if (DoRElementUtils.isTableRow(element) && (assist = (Element)element.resolveNode("assist")) != null && assist.getAttribute(XFA.ROLETAG) != null && StringUtils.equals((CharSequence)assist.getAttribute(XFA.ROLETAG).getAttrValue(), (CharSequence)"TH")) {
            return true;
        }
        return false;
    }

    public static boolean isTableRow(Element element) {
        if (element != null && element.getAttribute(XFA.LAYOUTTAG) != null && element.getAttribute(XFA.LAYOUTTAG).getAttrValue() != null && element.getAttribute(XFA.LAYOUTTAG).getAttrValue().equals("row")) {
            return true;
        }
        return false;
    }
}