GuideDropDownList.java 2.66 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.day.cq.wcm.foundation.forms.FormsHelper
 *  org.apache.commons.lang.StringUtils
 *  org.apache.sling.api.SlingHttpServletRequest
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 */
package com.adobe.aemds.guide.common;

import com.adobe.aemds.guide.common.GuideField;
import com.day.cq.wcm.foundation.forms.FormsHelper;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

public class GuideDropDownList
extends GuideField {
    private boolean isFirstOptGroup = true;

    public Map getOptions() {
        Resource resLoadPath;
        String[] options = null;
        String loadPath = (String)this.resourceProps.get("optionsLoadPath", (Object)"");
        if (loadPath.length() > 0 && (resLoadPath = this.slingRequest.getResourceResolver().getResource(loadPath)) != null) {
            options = (String[])resLoadPath.adaptTo(String[].class);
        }
        if (options == null) {
            options = (String[])this.resourceProps.get("options", String[].class);
        }
        if (options == null) {
            return null;
        }
        LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
        for (int i = 0; i < options.length; ++i) {
            String value;
            String[] option = StringUtils.split((String)options[i], (char)'=');
            if (option.length == 0) continue;
            String key = option[0];
            String string = value = option.length == 1 ? key : option[1];
            if ("afOptGroupName".equals(key)) {
                key = key + i;
            }
            result.put(key, value);
        }
        return result;
    }

    public List getValues() {
        return FormsHelper.getValuesAsList((SlingHttpServletRequest)this.slingRequest, (Resource)super.getResource());
    }

    public Boolean getIsMultiSelect() {
        return FormsHelper.hasMultiSelection((Resource)super.getResource());
    }

    public String getGuideFieldType() {
        return "guideDropDownList";
    }

    public boolean getIsFirstOptGroup() {
        if (this.isFirstOptGroup) {
            this.isFirstOptGroup = false;
            return true;
        }
        return false;
    }

    public static boolean isKeyAnOptGroup(String key) {
        return key.startsWith("afOptGroupName");
    }
}