DoRDropDownElement.java 2.3 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.xfa.AppModel
 *  com.adobe.xfa.Attribute
 *  com.adobe.xfa.Element
 *  com.adobe.xfa.Node
 *  com.adobe.xfa.StringAttr
 *  com.adobe.xfa.XFA
 *  com.adobe.xfa.content.TextValue
 *  com.adobe.xfa.template.TemplateModel
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.aemds.guide.addon.dor.elements.DoRElement;
import com.adobe.xfa.AppModel;
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.content.TextValue;
import com.adobe.xfa.template.TemplateModel;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class DoRDropDownElement
extends DoRElement {
    public DoRDropDownElement(Element xfaElement) throws Exception {
        super(xfaElement);
        this.xPathExprs.put("multiSelect", "ui/choiceList/@open");
        this.xPathExprs.put("displayValue", "value/text/text()");
    }

    @Override
    public void applyProperties(Properties properties) throws Exception {
        Map map = (Map)properties.get("options");
        if (map != null) {
            this.applyOptionsProperty(map);
        }
        super.applyProperties(properties, true);
    }

    private void applyOptionsProperty(Map<String, String> map) {
        TemplateModel templateModel = TemplateModel.getTemplateModel((AppModel)this.xfaElement.getAppModel(), (boolean)true);
        Element itemsTexts = templateModel.createElement("items", "", this.xfaElement);
        Element itemsValues = templateModel.createElement("items", "", this.xfaElement);
        StringAttr stringAttr = new StringAttr("save", "1");
        itemsValues.setAttribute((Attribute)stringAttr, XFA.SAVETAG);
        stringAttr = new StringAttr("presence", "hidden");
        itemsValues.setAttribute((Attribute)stringAttr, XFA.PRESENCETAG);
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String valueString = entry.getKey();
            String textString = entry.getValue();
            TextValue textValue = new TextValue(itemsValues, null);
            textValue.setValue(valueString);
            textValue = new TextValue(itemsTexts, null);
            textValue.setValue(textString);
        }
    }
}