DoRTableElement.java 3.3 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.guide.addon.dor.AFDoRMapper
 *  com.adobe.aemds.guide.addon.dor.DoRUtils
 *  com.adobe.xfa.Attribute
 *  com.adobe.xfa.Element
 *  com.adobe.xfa.Node
 *  com.adobe.xfa.XFA
 *  org.apache.commons.lang3.StringUtils
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.aemds.guide.addon.dor.AFDoRMapper;
import com.adobe.aemds.guide.addon.dor.DoRUtils;
import com.adobe.aemds.guide.addon.dor.elements.DoRPanelElement;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.Node;
import com.adobe.xfa.XFA;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;

public class DoRTableElement
extends DoRPanelElement {
    private String widthValue;
    private String widthUnit;

    public DoRTableElement(Element xfaElement) throws Exception {
        Node bodyRow;
        Node headerRow;
        Node evenRow;
        Node footerRow;
        Node oddRow;
        super(xfaElement);
        String width = xfaElement.getAttribute(XFA.COLUMNWIDTHSTAG).getAttrValue();
        this.widthValue = DoRUtils.getValueMatch((String)"\\+?\\d+\\.?\\d*", (String)width);
        if (StringUtils.isNotEmpty((CharSequence)this.widthValue)) {
            this.widthUnit = width.substring(this.widthValue.length());
        }
        if ((headerRow = xfaElement.resolveNode(AFDoRMapper.getDoRElement((String)"guideTableHeaderRow"))) != null) {
            xfaElement.removeChild(headerRow);
        }
        if ((evenRow = xfaElement.resolveNode(AFDoRMapper.getDoRElement((String)"guideTableEvenRow"))) != null) {
            xfaElement.removeChild(evenRow);
        }
        if ((oddRow = xfaElement.resolveNode(AFDoRMapper.getDoRElement((String)"guideTableOddRow"))) != null) {
            xfaElement.removeChild(oddRow);
        }
        if ((bodyRow = xfaElement.resolveNode("AF_TABLEBODYROW_XFO")) != null) {
            xfaElement.removeChild(bodyRow);
        }
        if ((footerRow = xfaElement.resolveNode("AF_TABLEFOOTERROW_XFO")) != null) {
            xfaElement.removeChild(footerRow);
        }
        this.xPathExprs.put("columnWidth", "@columnWidths");
    }

    @Override
    public void applyProperties(Properties properties) throws Exception {
        if (this.widthValue != null) {
            Object[] colWidths;
            int columns = Integer.parseInt(properties.get("columns").toString());
            String colWidthProp = properties.get("columnWidth").toString();
            if (colWidthProp.isEmpty()) {
                colWidths = new String[columns];
                Arrays.fill(colWidths, "1");
            } else {
                colWidths = colWidthProp.split(",");
            }
            double widthSum = 0.0;
            for (Object colWidth : colWidths) {
                widthSum += Double.parseDouble((String)colWidth);
            }
            int colIndex = 0;
            for (Object colWidth2 : colWidths) {
                colWidths[colIndex++] = "" + Double.parseDouble((String)colWidth2) / widthSum * Double.parseDouble(this.widthValue) + this.widthUnit;
            }
            properties.put("columnWidth", StringUtils.join((Object[])colWidths, (String)" "));
        }
        super.applyProperties(properties);
    }
}