DoRTnCElement.java 3.9 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
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.aemds.guide.addon.dor.elements.DoRElement;
import com.adobe.aemds.guide.addon.dor.elements.DoRElementUtils;
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 java.util.Map;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DoRTnCElement
extends DoRElement {
    private static Logger logger = LoggerFactory.getLogger(DoRTnCElement.class);

    public DoRTnCElement(Element xfaElement) throws Exception {
        super(xfaElement);
        this.xPathExprs.put("jcr:title", "field[ui[textEdit]]/caption/value/text/text()");
        this.xPathExprs.put("tncTextContent", "field[ui[textEdit]]/value/text/text()");
        this.xPathExprs.put("tncCheckBoxContent", "field[ui[checkButton]]/caption/value/text/text()");
        this.xPathExprs.put("items.reviewDocument.name", "field[ui[textEdit]]/@name");
        this.xPathExprs.put("items.reviewStatus.name", "field[ui[checkButton]]/@name");
        this.xPathExprs.put("assistPriority", "field[ui[textEdit]]/assist/speak/@priority");
        this.xPathExprs.put("custom", "field[ui[textEdit]]/assist/speak/text()");
        this.xPathExprs.put("shortDescription", "field[ui[textEdit]]/assist/toolTip/text()");
        this.xPathExprs.put("bindRef", "field[ui[checkButton]]/bind/@ref");
        this.xPathExprs.put("bindMatch", "field[ui[checkButton]]/bind/@match");
    }

    @Override
    public String getCaptionValueSom() {
        return "#field[*].#ui.#textEdit.parent.parent.#caption.#value";
    }

    @Override
    public void applyProperties(Properties properties) throws Exception {
        this.adaptForBackwardCompatibility();
        this.adaptToTable();
        super.applyProperties(properties, true);
        this.setWidth(this.xfaElement.getAttribute(XFA.WTAG).getAttrValue());
    }

    private void adaptToTable() {
        Element parent = this.xfaElement.getXFAParent();
        try {
            if (parent.getAttribute(XFA.LAYOUTTAG).getAttrValue().equals("row")) {
                String width = DoRElementUtils.getColumnWidthFromParent(this.xfaElement);
                int childCount = this.xfaElement.getXFAChildCount();
                for (int i = 0; i < childCount; ++i) {
                    Element element = (Element)this.xfaElement.getXFAChild(i);
                    if (!element.getClassName().equals("field")) continue;
                    DoRElementUtils.adaptToTableCell(element, width);
                }
            }
        }
        catch (NullPointerException e) {
            logger.debug("TnC is not inside table", (Throwable)e);
        }
    }

    private void setWidth(String width) {
        int childCount = this.xfaElement.getXFAChildCount();
        for (int i = 0; i < childCount; ++i) {
            Element element = (Element)this.xfaElement.getXFAChild(i);
            if (element == null || !element.getClassName().equals("field")) continue;
            element.setAttribute((Attribute)new StringAttr("maxW", width), XFA.MAXWTAG);
        }
    }

    private void adaptForBackwardCompatibility() {
        Element node = (Element)this.xfaElement.resolveNode("bind");
        if (node != null) {
            this.xfaElement.removeChild((Node)node);
        }
    }

    @Override
    protected void modifyCaptionAttributes(Element node, double scalingFactor) {
        int noOfChild = node.getXFAChildCount();
        for (int i = 0; i < noOfChild; ++i) {
            Element child = (Element)node.getXFAChild(i);
            super.modifyCaptionAttributes(child, scalingFactor);
        }
    }
}