1 16 package com.blandware.atleap.webapp.action.core.layout; 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.LayoutForm; 23 import com.blandware.atleap.webapp.util.core.WebappConstants; 24 import com.blandware.atleap.webapp.util.core.WebappUtil; 25 import org.apache.struts.action.ActionForm; 26 import org.apache.struts.action.ActionForward; 27 import org.apache.struts.action.ActionMapping; 28 import org.apache.struts.action.ActionMessage; 29 import org.apache.struts.action.ActionMessages; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 53 public final class CallUpdateLayoutAction extends BaseAction { 54 63 public ActionForward execute(ActionMapping mapping, ActionForm form, 64 HttpServletRequest request, HttpServletResponse response) throws Exception { 65 66 if ( isCancelled(request) ) { 67 return mapping.findForward("listLayouts"); 68 } 69 70 if ( !request.isUserInRole("core-layout-update") ) { 71 response.sendError(HttpServletResponse.SC_FORBIDDEN); 72 return null; 73 } 74 75 LayoutForm layoutForm = (LayoutForm) form; 76 Long layoutId = null; 77 if ( layoutForm.getId() != null ) { 78 layoutId = Long.valueOf(layoutForm.getId()); 79 } else if ( request.getSession().getAttribute(WebappConstants.LAYOUT_ID_KEY) != null ) { 80 layoutId = (Long ) request.getSession().getAttribute(WebappConstants.LAYOUT_ID_KEY); 81 } else { 82 if ( log.isWarnEnabled() ) { 83 log.warn("Missing layout ID. Returning to list..."); 84 } 85 return mapping.findForward("listLayouts"); 86 } 87 88 LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN); 89 Layout layout = layoutManager.retrieveLayout(layoutId); 90 if ( layout == null ) { 91 ActionMessages errors = new ActionMessages(); 93 errors.add("layoutNotFound", new ActionMessage("core.layout.errors.notFound")); 94 saveErrors(request, errors); 95 return mapping.findForward("listLayouts"); 96 } 97 WebappUtil.copyProperties(layoutForm, layout, request); 98 99 saveToken(request); 101 return mapping.findForward("updateLayout"); 102 } 103 104 } | Popular Tags |