GuidePanelElement.java 3.12 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.guide.addon.dor.DoRThreadLocal
 *  com.adobe.xfa.Element
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.sling.commons.json.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.aemds.guide.addon.dor.elements;

import com.adobe.aemds.guide.addon.dor.DoRThreadLocal;
import com.adobe.aemds.guide.addon.dor.elements.DoRElement;
import com.adobe.aemds.guide.addon.dor.elements.DoRPanelElement;
import com.adobe.aemds.guide.addon.dor.elements.GuideElement;
import com.adobe.aemds.guide.addon.dor.elements.GuideElementProperties;
import com.adobe.xfa.Element;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GuidePanelElement
extends GuideElement {
    private static Logger logger = LoggerFactory.getLogger(GuidePanelElement.class);

    public GuidePanelElement(JSONObject jsonObject) {
        String dorNumCols;
        boolean dorExcludeDescription;
        String dorLayoutType;
        super(jsonObject);
        for (String key : GuideElementProperties.PANEL_PROPERTIES) {
            String value = jsonObject.optString(key);
            if (value == null || value.isEmpty()) continue;
            this.properties.setProperty(key, value);
        }
        boolean hidePanelDescription = StringUtils.equals((CharSequence)"true", (CharSequence)((CharSequence)DoRThreadLocal.getFormProperties().get("hidePanelDescriptions")));
        boolean dorExcludeTitle = this.properties.getProperty("dorExcludeTitle", "false").equals("true");
        boolean bl = dorExcludeDescription = this.properties.getProperty("dorExcludeDescription", "false").equals("true") || hidePanelDescription;
        if (dorExcludeTitle) {
            this.properties.remove("jcr:title");
        }
        if (dorExcludeDescription) {
            this.properties.remove("jcr:description");
        }
        if (dorExcludeTitle && dorExcludeDescription) {
            this.properties.put("dorRemoveEmptySpaceInPanel", "true");
        }
        if (jsonObject.has("layout") && "columnar".equals(dorLayoutType = jsonObject.optJSONObject("layout").optString("dorLayoutType")) && Integer.parseInt(dorNumCols = jsonObject.optJSONObject("layout").optString("dorNumCols", "1")) > 1) {
            this.properties.setProperty("layout", "lr-tb");
            this.properties.setProperty("dorNumCols", dorNumCols);
        }
        String minOccur = "minOccur";
        String maxOccur = "maxOccur";
        if (jsonObject.has(minOccur) && !jsonObject.has(maxOccur)) {
            String maxOccurValue = String.valueOf(Math.max(1, Integer.parseInt(jsonObject.optString(minOccur))));
            this.properties.setProperty(maxOccur, maxOccurValue);
        } else if (jsonObject.has(maxOccur) && !jsonObject.has(minOccur)) {
            this.properties.setProperty(minOccur, "1");
        }
    }

    @Override
    public DoRElement createDoRElement(Element xfaElement) throws Exception {
        return new DoRPanelElement(xfaElement);
    }
}