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

com.adobe.aemds.guide.common.GuideItemsContainer 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 org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

import javax.script.SimpleBindings;
import java.util.ArrayList;
import java.util.List;


public class GuideItemsContainer extends GuideNode {
    /**
     * Returns the items present inside an items container(for eg panel)
     * @return list representing the items
     * @see GuideNode
     */
    public List getItems() {
        String fragRef = getResource().adaptTo(ValueMap.class).get(GuideConstants.FRAG_REF,"");
        Resource items = null;
        if (fragRef.length() > 0) {
            // DAM asset to adaptive forms page
            fragRef = StringUtils.replace(fragRef, GuideConstants.FM_DAM_ROOT, GuideConstants.FM_AF_ROOT, 1);
            fragRef =  GuideUtils.convertFMAssetPathToContainerPath(fragRef);
            ResourceResolver resourceResolver = getResource().getResourceResolver();
            Resource fragRefContainer = resourceResolver.getResource(fragRef);
            //  FragRef is the path of the fragment container. Now getting items of the
            // root panel
            // null check for fragRefContainer is added to handle the error which arises when a fragment has been deleted but
            // the fragRef property which references that fragment is not deleted from the node.
            if (fragRefContainer != null) {
                GuidePanel fragRefRootPanel = GuideUtils.getRootPanel(fragRefContainer, slingRequest);
                if (fragRefRootPanel != null) {
                    Resource fragRefRootPanelResource = fragRefRootPanel.getResource();
                    items = fragRefRootPanelResource.getChild(GuideConstants.ITEMS_NODENAME);
                }
            }
        } else {
            items = getResource().getChild(GuideConstants.ITEMS_NODENAME);
        }
        List panelItems = new ArrayList();
        if(items!=null){
            for(Resource itemChild : items.getChildren()){
                GuideNode newNode = null;
                String normalizedNodeType = GuideUtils.getNormalizedNodeType(itemChild.getResourceType(),
                        itemChild.getResourceSuperType());
                if (itemChild.isResourceType(GuideConstants.RT_PANEL) || itemChild.isResourceType(GuideConstants.RT_WEB_DOCUMENT_TARGET_AREA)) {
                    newNode = new GuidePanel();
                } else {
                    newNode = new GuideNode();
                }
                SimpleBindings bindings = new SimpleBindings();
                bindings.put("resource",itemChild);
                bindings.put("request",slingRequest);
                newNode.init(bindings);
                panelItems.add(newNode);
            }
        }
        return panelItems;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy