1 16 package com.blandware.atleap.webapp.action.core.contentField; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.ActionPage; 20 import com.blandware.atleap.model.core.ContentPage; 21 import com.blandware.atleap.model.core.Layout; 22 import com.blandware.atleap.model.core.Localizable; 23 import com.blandware.atleap.service.core.LookupManager; 24 import com.blandware.atleap.webapp.action.core.BaseAction; 25 import com.blandware.atleap.webapp.form.ContentFieldForm; 26 import com.blandware.atleap.webapp.util.core.WebappConstants; 27 import org.apache.commons.validator.GenericValidator; 28 import org.apache.struts.action.*; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 55 public final class ListContentFieldsAction extends BaseAction { 56 65 public ActionForward execute(ActionMapping mapping, ActionForm form, 66 HttpServletRequest request, HttpServletResponse response) throws Exception { 67 68 69 Long ownerId = null; 70 ContentFieldForm contentFieldForm = (ContentFieldForm) form; 71 if ( !GenericValidator.isBlankOrNull(contentFieldForm.getOwnerId()) ) { 72 ownerId = Long.valueOf(contentFieldForm.getOwnerId()); 73 } else if ( request.getAttribute(WebappConstants.OWNER_ID_KEY) != null ) { 74 ownerId = (Long ) request.getAttribute(WebappConstants.OWNER_ID_KEY); 75 } else if ( request.getSession().getAttribute(WebappConstants.OWNER_ID_KEY) != null ) { 76 ownerId = (Long ) request.getSession().getAttribute(WebappConstants.OWNER_ID_KEY); 77 } else { 78 if ( log.isWarnEnabled() ) { 79 log.warn("Missing owner ID. Returning to index..."); 80 } 81 return mapping.findForward("admin"); 82 } 83 84 LookupManager lookupManager = (LookupManager) getBean(Constants.LOOKUP_MANAGER_BEAN); 85 Localizable owner = lookupManager.retrieveLocalizable(ownerId); 86 87 if ( owner == null ) { 88 ActionMessages errors = new ActionMessages(); 90 errors.add("ownerNotFound", new ActionMessage("core.contentField.errors.ownerNotFound")); 91 saveErrors(request, errors); 92 return mapping.findForward("admin"); 93 } 94 95 String key = new String (); 96 ActionForward forward = null; 97 98 if ( owner instanceof Layout ) { 99 forward = mapping.findForward("viewLayout"); 100 key = WebappConstants.LAYOUT_ID_KEY; 101 } else if ( owner instanceof ContentPage ) { 102 forward = mapping.findForward("viewContentPage"); 103 key = WebappConstants.CONTENT_PAGE_ID_KEY; 104 } else if ( owner instanceof ActionPage ) { 105 forward = mapping.findForward("viewActionPage"); 106 key = WebappConstants.ACTION_PAGE_ID_KEY; 107 } else { 108 forward = mapping.findForward("admin"); 110 } 111 112 request.getSession().setAttribute(key, ownerId); 113 114 saveToken(request); 116 return forward; 117 } 118 } | Popular Tags |