1 package com.blandware.atleap.webapp.action.core.menuItem; 2 3 import com.blandware.atleap.common.Constants; 4 import com.blandware.atleap.model.core.ActionPage; 5 import com.blandware.atleap.model.core.ContentPage; 6 import com.blandware.atleap.model.core.Layout; 7 import com.blandware.atleap.model.core.Localizable; 8 import com.blandware.atleap.model.core.MenuItem; 9 import com.blandware.atleap.service.core.LookupManager; 10 import com.blandware.atleap.service.core.MenuManager; 11 import com.blandware.atleap.webapp.util.core.MenuUtil; 12 import com.blandware.atleap.webapp.util.core.WebappConstants; 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 import org.apache.commons.validator.GenericValidator; 16 import org.apache.struts.tiles.ComponentContext; 17 import org.apache.struts.tiles.ControllerSupport; 18 import org.springframework.context.ApplicationContext; 19 import org.springframework.web.context.support.WebApplicationContextUtils; 20 21 import javax.servlet.ServletContext ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 import java.util.ArrayList ; 25 import java.util.LinkedList ; 26 import java.util.List ; 27 28 29 37 public final class ListMenuItemsController extends ControllerSupport { 38 39 protected transient final Log log = LogFactory.getLog(ListMenuItemsController.class); 40 41 50 public void execute(ComponentContext tilesContext, 51 HttpServletRequest request, 52 HttpServletResponse response, 53 ServletContext servletContext) throws Exception { 54 55 Long ownerId = (Long ) request.getAttribute("ownerId"); 56 57 Long parentItemId = (Long ) request.getSession().getAttribute(WebappConstants.MENU_ITEM_PARENT_ID_KEY); 59 List menuItemsList = new ArrayList (); 60 61 ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); 62 63 if ( ownerId != null ) { 64 LookupManager lookupManager = (LookupManager) applicationContext.getBean(Constants.LOOKUP_MANAGER_BEAN); 65 Localizable owner = lookupManager.retrieveLocalizable(ownerId); 66 67 String pageUri = null; 68 String layoutDefinition = null; 69 if ( owner instanceof Layout ) { 70 Layout layout = (Layout) owner; 71 layoutDefinition = layout.getDefinition(); 72 } else if ( owner instanceof ContentPage ) { 73 ContentPage contentPage = (ContentPage) owner; 74 pageUri = contentPage.getUri(); 75 layoutDefinition = contentPage.getLayout().getDefinition(); 76 } else if ( owner instanceof ActionPage ) { 77 ActionPage actionPage = (ActionPage) owner; 78 pageUri = actionPage.getUri(); 79 layoutDefinition = (String ) request.getSession().getAttribute(WebappConstants.LAYOUT_DEFINITION_KEY); 80 } 81 82 if ( !GenericValidator.isBlankOrNull(layoutDefinition) ) { 85 if ( parentItemId != null ) { 87 MenuManager menuManager = (MenuManager) applicationContext.getBean(Constants.MENU_MANAGER_BEAN); 88 MenuItem parentItem = menuManager.retrieveMenuItem(parentItemId); 89 if ( parentItem == null ) { 90 parentItemId = null; 92 request.getSession().removeAttribute(WebappConstants.MENU_ITEM_PARENT_ID_KEY); 93 } else { 94 LinkedList parents = new LinkedList (); 96 while ( parentItem != null ) { 97 parents.addFirst(parentItem); 98 parentItem = parentItem.getParentItem(); 99 } 100 request.setAttribute(WebappConstants.MENU_ITEM_PARENTS_LIST_KEY, parents); 101 } 102 } 103 menuItemsList = new MenuUtil(request).getMenuItems(parentItemId, layoutDefinition, pageUri, false); 104 } 105 } 106 107 request.setAttribute("menuItemsList", menuItemsList); 108 } 109 } 110 | Popular Tags |