AEMForm.java 4.5 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.sightly.WCMUse
 *  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.service.GuideException;
import com.adobe.cq.sightly.WCMUse;
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 AEMForm
extends WCMUse {
    public static final int NO_FORM_SELECTED = -1;
    public static final int MOBILE_FORM = 1;
    public static final int ADAPTIVE_FORM = 2;
    public static final int MOBILE_FORMSET = 3;
    public static final int INLINE_SUBMIT = 4;
    public static final int PAGE_REFRESH_SUBMIT = 5;
    private static final int THANKYOU_PAGE = 6;
    private static final int THANKYOU_MESSAGE = 7;
    protected Resource mResource;
    protected ValueMap mResourceProps;

    public void activate() throws Exception {
        this.mResource = this.getResource();
        this.mResourceProps = this.getProperties();
        SlingHttpServletRequest request = this.getRequest();
        request.setAttribute("formContainerPath", (Object)this.mResource.getPath());
    }

    protected String getClientLibCategory(String themePath) {
        if ("".equals(themePath)) {
            return "";
        }
        Resource themeResource = this.getResource().getResourceResolver().getResource(themePath + "/jcr:content/metadata");
        if (themeResource == null) {
            throw new GuideException("Invalid Theme Name " + themePath);
        }
        ValueMap themeProps = themeResource.getValueMap();
        return (String)themeProps.get("clientlibCategory", (Object)"");
    }

    public String getThemeName() {
        return this.getClientLibCategory(this.getThemeRef());
    }

    public String getFormPath() {
        return (String)this.mResourceProps.get("formRef", (Object)"");
    }

    protected String getThemeRef() {
        return (String)this.mResourceProps.get("themeRef", (Object)"");
    }

    public String getFormEditPagePath() {
        return this.getFormPath();
    }

    public int getFormType() {
        if ("".equals(this.getFormPath())) {
            return -1;
        }
        ResourceResolver resolver = this.mResource.getResourceResolver();
        Resource formResource = resolver.getResource(this.getFormPath());
        if (formResource == null) {
            throw new GuideException("Invalid Form Path set");
        }
        Resource jcrContent = formResource.getChild("jcr:content");
        if (jcrContent == null) {
            throw new GuideException("Invalid Form Path set. No jcr:content node inside Form");
        }
        ValueMap props = jcrContent.getValueMap();
        if ((Integer)props.get("guide", (Object)0) == 1 || (Integer)props.get("adaptivedocument", (Object)0) == 1) {
            return 2;
        }
        return 1;
    }

    public boolean getIsAdaptiveForm() {
        return this.getFormType() == 2;
    }

    public boolean getIsMobileForm() {
        return this.getFormType() == 1;
    }

    public boolean getIsMobileFormset() {
        return this.getFormType() == 3;
    }

    public boolean getIsFormSelected() {
        return this.getFormType() != -1;
    }

    public String getSubmitType() {
        if ("message".equals(this.getThankyouConfig())) {
            return "inline";
        }
        return (String)this.mResourceProps.get("submitType", (Object)"inline");
    }

    public String getThankyouMessage() {
        return (String)this.mResourceProps.get("thankyouMessage", (Object)"");
    }

    public String getThankyouPage() {
        return (String)this.mResourceProps.get("thankyouPage", (Object)"");
    }

    public String getThankyouConfig() {
        return (String)this.mResourceProps.get("thankyouConfig", (Object)"page");
    }

    public String getHeight() {
        String height = (String)this.mResourceProps.get("height", (Object)"auto");
        if (!"auto".equals(height)) {
            try {
                height = "" + Integer.parseInt(height) + "px";
            }
            catch (NumberFormatException ex) {
                height = "auto";
            }
        }
        return height;
    }

    public String getCssClientlib() {
        return (String)this.mResourceProps.get("cssClientlib", (Object)"");
    }
}