All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.aemds.guide.common.AdaptiveForm 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.utils.GuideConstants;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.day.cq.commons.LanguageUtil;
import com.day.cq.wcm.api.Page;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.commons.lang3.StringUtils;
/**
 * AdaptiveForm class encapsulates basic properties of an adaptive form.
 * Few are listed below:
 * 
    *
  • Name of the form *
  • Title of the form *
* * @since 6.2 **/ public class AdaptiveForm extends AEMForm { public String getFormPagePath() { String formPath = super.getFormPath(); Boolean isMCDocument = super.getIsMCDocument(); if (isMCDocument) { return GuideUtils.guideRefToDocPath(formPath); } else { return GuideUtils.guideRefToGuidePath(formPath); } } public String getFormEditPagePath() { String formPagePath = getFormPagePath(); return formPagePath.substring(0, formPagePath.indexOf("/jcr:content")); } /** * get the title to be displayed for the form * returns {@link Page#getTitle()} for the form if it exists * otherwise returns {@link Page#getName()} * @return form title */ public String getFormTitle(){ String pageTitle = getFormPageTitle(); return pageTitle!=null ? pageTitle : getFormPageName(); } private String getFormPageTitle(){ return getFormPage().getTitle(); } private String getFormPageName(){ return getFormPage().getName(); } private Page getFormPage(){ return getFormPageResource().adaptTo(Page.class); } private Resource getFormPageResource(){ return getGuideContainerResource().getParent().getParent(); } private Resource getGuideContainerResource(){ return getResourceResolver().getResource(getFormPagePath()); } /** * Returns the client lib to be used for styling the form. The function first checks whether any theme is set * either in dialog or the form. * If not found returns empty string. * @return name of the theme client lib used in the form */ public String getFormThemeName() { Resource resource = getResourceResolver().getResource(getFormPagePath()); //look for theme selected in the component String formClientLib = getThemeName(); if (StringUtils.isNotBlank(formClientLib) && resource != null) { //fallback to the theme defined in form ValueMap valueMap = resource.getValueMap(); String formThemeRef = valueMap.get(GuideConstants.THEME_CLIENTLIB, ""); formClientLib = getClientLibCategory(formThemeRef); } return formClientLib; } /** * @deprecated */ public String getAcceptLangParamString() { String usePageLocale = (String) mResourceProps.get("usePageLocale"); if (usePageLocale != null && StringUtils.equals(usePageLocale, "true")) { String lang = getPageLocale(); if (StringUtils.isNotBlank(lang)) { return "&afAcceptLang=" + lang; } } return ""; } /** * Returns the additional param strings for the adaptive form. * @return */ public String getAdditionalParamString() { String paramString = super.getAdditionalParamString(); paramString = StringUtils.join(paramString, getAcceptLangParamString()); return paramString; } private String getPageLocale() { String pagePath = getCurrentPage().getPath(), pageLocaleRoot = LanguageUtil.getLanguageRoot(pagePath), locale = null; if (StringUtils.isNotBlank(pageLocaleRoot)) { int localeStartIndex = StringUtils.lastIndexOf(pageLocaleRoot, '/'); locale = StringUtils.substring(pageLocaleRoot, localeStartIndex+1); } return locale; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy