1 16 package com.blandware.atleap.webapp.action.core.actionPage; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.Layout; 20 import com.blandware.atleap.service.core.LayoutManager; 21 import com.blandware.atleap.webapp.action.core.BaseAction; 22 import com.blandware.atleap.webapp.form.core.SwitchActionPageLayoutForm; 23 import com.blandware.atleap.webapp.util.core.WebappConstants; 24 import org.apache.commons.validator.GenericValidator; 25 import org.apache.struts.action.ActionForm; 26 import org.apache.struts.action.ActionForward; 27 import org.apache.struts.action.ActionMapping; 28 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 55 public final class SwitchLayoutAction extends BaseAction { 56 65 public ActionForward execute(ActionMapping mapping, ActionForm form, 66 HttpServletRequest request, HttpServletResponse response) throws Exception { 67 68 SwitchActionPageLayoutForm switchLayoutForm = (SwitchActionPageLayoutForm) form; 69 70 Long actionPageId = null; 71 if ( !GenericValidator.isBlankOrNull(switchLayoutForm.getActionPageId()) ) { 72 actionPageId = Long.valueOf(switchLayoutForm.getActionPageId()); 73 } else { 74 if ( log.isWarnEnabled() ) { 75 log.warn("Missing action page ID. Returning to index..."); 76 } 77 return mapping.findForward("admin"); 78 } 79 80 String layoutDefinition = switchLayoutForm.getLayoutDefinition(); 81 if ( GenericValidator.isBlankOrNull(layoutDefinition) ) { 82 LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN); 84 List layouts = null; 85 layouts = layoutManager.listLayouts(null).asList(); 86 87 if ( layouts == null ) { 88 layouts = new ArrayList (); 90 } 91 92 if ( !layouts.isEmpty() ) { 93 Layout layout = (Layout) layouts.get(0); 94 layoutDefinition = layout.getDefinition(); 95 } 96 } 97 98 request.getSession().setAttribute(WebappConstants.LAYOUT_DEFINITION_KEY, layoutDefinition); 99 request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, actionPageId); 100 return mapping.findForward("listMenuItems"); 101 } 102 } | Popular Tags |