
com.adobe.aemds.guide.common.AEMForm Maven / Gradle / Ivy
/*******************************************************************************
* ADOBE CONFIDENTIAL
* ___________________
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by all applicable intellectual property
* laws, including trade secret and copyright laws.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
******************************************************************************/
package com.adobe.aemds.guide.common;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.cq.sightly.SightlyWCMMode;
import com.adobe.cq.sightly.WCMUsePojo;
import org.apache.commons.lang3.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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* AEMForm class encapsulates basic properties of an AEM Form.
* @since 6.2
**/
public class AEMForm extends WCMUsePojo {
public final static int NO_FORM_SELECTED = -1;
public final static int MOBILE_FORM = 1;
public final static int ADAPTIVE_FORM = 2;
public final static int MC_DOCUMENT = 8;
public final static int MOBILE_FORMSET = 3;
public final static int INLINE_SUBMIT = 4;
public final static int PAGE_REFRESH_SUBMIT = 5;
private static final int THANKYOU_PAGE = 6;
private static final int THANKYOU_MESSAGE = 7;
public final static String PROP_THANK_YOU_CONFIG = "thankyouConfig";
public final static String PROP_THANK_YOU_PAGE = "thankyouPage";
public final static String PROP_THANK_YOU_MESSAGE = "thankyouMessage";
protected Resource mResource;
protected ValueMap mResourceProps;
private Logger logger;
public void activate() throws Exception {
mResource = getResource();
mResourceProps = getProperties();
SlingHttpServletRequest request = getRequest();
request.setAttribute("formContainerPath", mResource.getPath());
logger = LoggerFactory.getLogger(AEMForm.class);
}
protected String getClientLibCategory(String themePath) {
if ("".equals(themePath)) {
return "";
}
Resource themeResource = getResource().getResourceResolver().getResource(themePath + "/jcr:content/metadata");
if (themeResource == null) {
throw new GuideException("Invalid Theme Name " + themePath);
}
ValueMap themeProps = themeResource.getValueMap();
return themeProps.get("clientlibCategory", "");
}
/**
* Returns the client lib name for the theme
* @return client lib name of the theme configured for the form
*/
public String getThemeName() {
return getClientLibCategory(getThemeRef());
}
public String getFormPath() {
if ("adaptiveDocument".equals(mResourceProps.get("formType", ""))) {
return mResourceProps.get("docRef", "");
} else {
return mResourceProps.get("formRef", "");
}
}
/**
* Returns the theme associated with adaptive form.
* @return path of the theme associated with the form.
*/
protected String getThemeRef() {
return mResourceProps.get(GuideConstants.THEME_CLIENTLIB, "");
}
/**
* Returns the path of the theme associated with adaptive form.
* @return Path of the theme associated with adaptive form.
*/
public String getThemePath() {
return StringUtils.isNotBlank(getThemeRef()) ? getThemeRef() + "/" + GuideConstants.JCR_CONTENT_NODENAME : "";
}
public String getFormEditPagePath() {
return getFormPath();
}
public int getFormType() {
int formType = NO_FORM_SELECTED;
String formPath = getFormPath();
if(!("".equals(formPath))) {
ResourceResolver resolver = mResource.getResourceResolver();
if (GuideUtils.isValidFormResource(resolver, formPath, GuideConstants.ADAPTIVE_FORM)) {
formType = ADAPTIVE_FORM;
} else if (GuideUtils.isValidFormResource(resolver, formPath, GuideConstants.MC_DOCUMENT)) {
formType = MC_DOCUMENT;
} else if (GuideUtils.isValidFormResource(resolver, formPath, GuideConstants.XFA_FORM)) {
formType = MOBILE_FORM;
}
}
return formType;
}
public boolean getIsAdaptiveForm() {
return getFormType() == ADAPTIVE_FORM;
}
public boolean getIsMCDocument() {
return getFormType() == MC_DOCUMENT;
}
public boolean getIsMobileForm() {
return getFormType() == MOBILE_FORM;
}
public boolean getIsMobileFormset() {
return getFormType() == MOBILE_FORMSET;
}
public boolean getIsFormSelected() {
return getFormType() != NO_FORM_SELECTED;
}
public String getSubmitType() {
if ("message".equals(getThankyouConfig())) {
return "inline";
}
return mResourceProps.get("submitType", "inline");
}
public String getThankyouMessage() {
return mResourceProps.get(PROP_THANK_YOU_MESSAGE, "");
}
public String getThankyouPage() {
String redirectUrl = mResourceProps.get(PROP_THANK_YOU_PAGE, "");
return GuideUtils.getRedirectUrl(redirectUrl, null);
}
public String getThankyouConfig() {
return mResourceProps.get(PROP_THANK_YOU_CONFIG, "page");
}
/**
* The functions checks the height set in the dialog. It appends the height with px unless it is auto.
* For invalid values (non integers), auto is returned.
* @return height of the form configured
*/
public String getHeight() {
String height = mResourceProps.get("height", "auto");
if (!"auto".equals(height)) {
try {
height = Integer.parseInt(height) + "px";
} catch(NumberFormatException ex) {
height = "auto";
}
}
return height;
}
public String getCssClientlib() {
return mResourceProps.get("cssClientlib", "");
}
public String getAdditionalParamString() {
String paramString = "";
SightlyWCMMode wcmMode = getWcmMode();
if(!wcmMode.isEdit()) {
paramString = "&wcmmode=" + wcmMode.toString();
}
return paramString;
}
public boolean getIsPlaceholderVisible() {
boolean isEditWCMMode = false;
SightlyWCMMode wcmMode = getWcmMode();
if(!wcmMode.isDisabled()) {
isEditWCMMode = true;
}
return isEditWCMMode && !getIsFormSelected();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy