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

com.adobe.aemds.guide.common.GuidePanel Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2014 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 may be covered by U.S. and Foreign Patents,
 * patents in process, and are protected by trade secret or copyright law.
 * 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.adobe.granite.xss.XSSAPI;
import com.day.cq.wcm.api.WCMMode;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.*;

import javax.script.SimpleBindings;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * GuidePanel class encapsulates basic properties of adaptive forms Panels.
 * Some of the properties that it encapsulates are listed below:
 * 
    *
  • Minimum count of the panel
  • *
  • Maximum count of the panel
  • *
  • Long Description of the panel
  • *
* * @since AEM 6.0 */ public class GuidePanel extends GuideItemsContainer implements Serializable { /** * Returns the current panel's minimum count configured in the authoring dialog * @return Integer representing the panel's minimum count */ public int getMinOccur() { return resourceProps.get("minOccur", 1); } /** * Returns the current panel's maximum count configured in the authoring dialog * @return Integer representing the panel's maximum count */ public int getMaxOccur() { return resourceProps.get("maxOccur", 1); } /** * @pad.exclude Exclude from Published API. */ public int getInitialOccur() { return resourceProps.get("initialOccur", 1); } /** * Returns the fragRef property present at the resource. * @return String representing the fragRef */ public String getFragRefPropertyFromResource(){ return resourceProps.get(GuideConstants.FRAG_REF, ""); } /** * Returns the reference to the fragment configured during authoring * @return path of the fragment reference configured for the panel component */ public String getFragRef(){ String fragRefAssetPath = getFragRefPropertyFromResource(); String fragRefContainerPath = ""; String fragRefRootPanelPath = ""; if(fragRefAssetPath.length() > 0) { fragRefContainerPath = GuideUtils.convertFMAssetPathToContainerPath(fragRefAssetPath); Resource fragRefRootPanel = GuideUtils.getRootPanel(getResource().getResourceResolver().getResource(fragRefContainerPath)); if(fragRefRootPanel != null) { fragRefRootPanelPath = fragRefRootPanel.getPath(); } } return fragRefRootPanelPath; } /** * Returns a boolean indicating whether the fragment is available or not. * @return Boolean indicating whether the fragment is available or not. */ public boolean isFragmentAvailable(){ String fragRefAssetPath = getFragRefPropertyFromResource(); ResourceResolver resourceResolver = this.getResource().getResourceResolver(); Resource fragmentContainer = resourceResolver.getResource(fragRefAssetPath); if (fragmentContainer != null) { String fragRefContainerPath = GuideUtils.convertFMAssetPathToContainerPath(fragRefAssetPath); Resource fragRefRootPanel = GuideUtils.getRootPanel(getResource().getResourceResolver().getResource(fragRefContainerPath)); if (fragRefRootPanel != null) { return true; } } return false; } /** * Returns a map containing details for fragment that has been created from a panel. * * @return Map containing title of the fragment and details of fields contained in the fragment. */ public Map getFragmentDetails() { Map fragDetails = new HashMap(); String fragRef = getFragRef(); XSSAPI xssApi = getXssapi(); StringBuilder fragFieldDetails = new StringBuilder(""); if (fragRef.length() > 0) { ResourceResolver resourceResolver = this.getResource().getResourceResolver(); if(resourceResolver != null) { Resource fragment = resourceResolver.getResource(fragRef.substring(0, fragRef.indexOf(GuideConstants.GUIDE_CONTAINER_NODE_NAME) - 1)); String title = (String) fragment.adaptTo(ValueMap.class).get(GuideConstants.JCR_TITLE); fragDetails.put(GuideConstants.TITLE_NODENAME, GuideUtils.encodeForHtml(title, xssApi)); Resource fragRefRootPanel = fragment.getChild(GuideConstants.GUIDE_CONTAINER_NODE_NAME).getChild(GuideConstants.ROOTPANEL_NODENAME); if (fragRefRootPanel != null) { int numberOfFieldsListed = 0; for (Resource itemResource : fragRefRootPanel.getChild(GuideConstants.ITEMS_NODENAME).getChildren()) { ValueMap itemValueMap = ResourceUtil.getValueMap(itemResource); String fieldLabel = itemValueMap.get(GuideConstants.JCR_TITLE, ""); if (fieldLabel == null || fieldLabel.length() == 0) { fieldLabel = itemValueMap.get(GuideConstants.NAME, ""); } if (!StringUtils.isEmpty(fieldLabel)) { GuideUtils.encodeForHtml(fieldLabel, xssApi); fragFieldDetails.append(fieldLabel).append("
"); } numberOfFieldsListed++; if ( numberOfFieldsListed == GuideConstants.NO_OF_FIELDS_TO_DISPLAY_FOR_FRAG_PLACEHOLDER) { break; } } fragDetails.put("fieldDetails", fragFieldDetails.toString()); } } } return fragDetails; } /** * @pad.exclude Exclude from Published API. * Returns the Optimized Render Layout */ public String getOptimizeRenderPerformance() { return resourceProps.get(GuideConstants.OPTIMIZE_RENDER_PERFORMANCE, ""); } /** @pad.exclude Exclude from Published API. * Returns asset ref in case of fragments * @return asset ref (String) */ public String getAssetRef(){ String fragRefAssetPath = getFragRefPropertyFromResource(); String optimizeRenderLayout = getOptimizeRenderPerformance(); if(StringUtils.isNotEmpty(fragRefAssetPath) && StringUtils.isNotEmpty(optimizeRenderLayout) ) { return fragRefAssetPath; } return null; } /** * @pad.exclude Exclude from Published API. */ public String getLayoutFromFragRootPanel() { String fragRef = getFragRef(); if(fragRef.length() > 0) { ResourceResolver resourceResolver = this.getResource().getResourceResolver(); Resource fragRefRootPanel = resourceResolver.getResource(fragRef); if(fragRefRootPanel != null) { Resource layout = fragRefRootPanel.getChild(GuideConstants.LAYOUT_NODENAME); if(layout != null) { return (String)layout.adaptTo(ValueMap.class).get(GuideConstants.SLING_RESOURCE_TYPE); } } } return null; } /** * Checks if the panel has a fragment reference and returns the CSS class of the * fragment marker * @return CSS class of the af fragment marker */ public String getAfFragmentMarker() { String afFragmentClass="" ; HttpServletRequest request = (HttpServletRequest)slingRequest; String fragRefAssetPath = getFragRefPropertyFromResource(); if((fragRefAssetPath.length()>0)&& WCMMode.EDIT.equals(WCMMode.fromRequest(request))) { afFragmentClass = "afFragmentMarker"; } return afFragmentClass; } /** * Returns whether panel is of new responsive layout type or not * @return Boolean.TRUE if panel is of new responsive layout type * @pad.exclude Exclude from Published API. */ public Boolean isNewResponsiveLayout() { Resource panelResource = getResource(); Resource layoutResource = panelResource.getChild(GuideConstants.LAYOUT_NODENAME); return layoutResource.isResourceType(GuideConstants.LAYOUT_GRIDFLUIDLAYOUT2); } /** * @pad.exclude Exclude from Published API. */ @Override public Map getAuthoringConfig(){ Map authoringConfig = super.getAuthoringConfig(); Boolean nonNavigable = getNonNavigableProperty(); String dorLayoutType = getDoRLayoutType(); updateFragmentLayoutInformation(authoringConfig); authoringConfig.put(GuideConstants.LAYOUT_NON_NAVIGABLE_PROPERTY, nonNavigable); authoringConfig.put(GuideConstants.LAYOUT_DOR_LAYOUT_TYPE, dorLayoutType); authoringConfig.put(GuideConstants.IS_NEW_RESPONSIVE_LAYOUT, isNewResponsiveLayout()); GuideUtils.setMasterAuthoringConfig(authoringConfig, resourceProps); return authoringConfig; } private void updateFragmentLayoutInformation(Map authoringConfig){ String fragRef = getFragRefPropertyFromResource(); String fragRefRootPanel = getFragRef(); Boolean isOldResponsiveFragment = false; if(StringUtils.isNotEmpty(fragRef) && StringUtils.isNotEmpty(fragRefRootPanel)){ Resource fragRootPanelResource = slingRequest.getResourceResolver().getResource(fragRefRootPanel); if(fragRootPanelResource!=null){ isOldResponsiveFragment = GuideUtils.isOldResponsiveLayout(fragRootPanelResource); isOldResponsiveFragment = (isOldResponsiveFragment == null) ? false : isOldResponsiveFragment; authoringConfig.put(GuideConstants.IS_NEW_RESPONSIVE_FRAGMENT, isOldResponsiveFragment); } } } /** * Returns the dorLayoutType property of the layout. * @return String * @pad.exclude */ public String getDoRLayoutType() { String dorLayoutType = ""; try { dorLayoutType = (String) getLayoutProperty(GuideConstants.LAYOUT_DOR_LAYOUT_TYPE); } catch (Exception e){ logger.error("Unable to fetch dorLayoutType property " + e.getMessage(), e); } return dorLayoutType; } /** * Returns the string containing the inline style specified for the panel * @return inline style of the panel */ public String getPanelInlineStyles() { return getInlineStyles(GuideConstants.GUIDE_STYLE_PANEL); } /** * Returns the string containing the inline style specified for the panel description * @return inline style of the panel description */ public String getPanelDescriptionInlineStyles() { return getInlineStyles(GuideConstants.GUIDE_STYLE_PANELDESCRIPTION); } /** * Returns whether the current panel is repeatable or not * @return boolean indicating if panel is repeatable or not */ public boolean getIsRepeatable(){ return (this.getMinOccur()!= 1 || this.getMaxOccur()!= 1); } /** * Returns if toolbar present for the panel * @return true if toolbar is present else false */ public boolean isHasToolbar(){ return getResource().getChild("toolbar") != null; } /** * Returns the long description of the panel configured in authoring dialog * @return String representing the long description */ public String getLongDescription() { return externalize(resourceProps.get("longDescription","")); } /** * Returns the toolbar configured for the panel * @return {@link GuideItemsContainer} representing the tool bar */ public GuideItemsContainer getToolbar(){ Resource toolbarResource = getResource().getChild("toolbar"); if(toolbarResource != null){ GuideItemsContainer guideItemsContainer = new GuideItemsContainer(); SimpleBindings bindings = new SimpleBindings(); bindings.put("resource",toolbarResource); bindings.put("request",slingRequest); guideItemsContainer.init(bindings); return guideItemsContainer; } return null; } /** * @param layoutNode * @throws PersistenceException * @pad.exclude Exclude from Published API. */ public void updateCompletionAndSummary(Resource layoutNode) throws PersistenceException { try { ModifiableValueMap layoutproperties = layoutNode.adaptTo(ModifiableValueMap.class); /** * ModifiableValueMap will return null if your user session does not have set_property * permission */ if (layoutproperties == null) { return; } String layoutCmpPath = (String) layoutproperties.get(GuideConstants.SLING_RESOURCE_TYPE); if (layoutCmpPath != null) { /* *summaryExpression changes * If the layout of the panel is accordion, then set property on children panels. */ Resource panel = layoutNode.getParent(); if (panel != null) { Resource getChildrenResource = panel.getChild(GuideConstants.ITEMS_NODENAME); if (getChildrenResource != null) { Iterator it = getChildrenResource.listChildren(); while (it.hasNext()) { Resource child = it.next(); ModifiableValueMap childMap = child.adaptTo(ModifiableValueMap.class); String guideNodeClass = childMap.get(GuideConstants.ELEMENT_PROPERTY_NODECLASS, ""); if (guideNodeClass.equals(GuideConstants.ROOTPANEL_NODECLASS) || guideNodeClass.equals(GuideConstants.GUIDE_PANEL)) { String oldValue = childMap.get(GuideConstants.SUMMARY_EXP_VISIBLE, ""); if (layoutCmpPath.equals(GuideConstants.ACCORDION_LAYOUT_RESOURCE_TYPE)) { if (oldValue.length() == 0 || !oldValue.equals("yes")) { childMap.put(GuideConstants.SUMMARY_EXP_VISIBLE, "yes"); // commit the summary expression changes child.getResourceResolver().commit(); } } else if (oldValue.length() > 0) { childMap.remove(GuideConstants.SUMMARY_EXP_VISIBLE); // commit the summary expression changes child.getResourceResolver().commit(); } } } } } } } catch (PersistenceException e) { logger.error("Unable to commit summary expression visible property on " + layoutNode.getPath(), e); } } /** * * @param slingRequest * @pad.exclude Exclude from Published API. */ public void setSlingRequest(SlingHttpServletRequest slingRequest) { super.setSlingRequest(slingRequest); Resource layout = getResource().getChild(GuideConstants.LAYOUT_NODENAME); if(getIsEditMode() && layout != null) { try { // todo: get rid of this API and use sling post servlet updateCompletionAndSummary(layout); } catch (PersistenceException e) { logger.error("AF: Unable to set layout Properties"+ e.getMessage(), e); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy