1 16 package com.blandware.atleap.webapp.action.core.contentResource.file; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.ContentResource; 20 import com.blandware.atleap.service.core.ContentResourceManager; 21 import com.blandware.atleap.webapp.action.core.BaseAction; 22 import com.blandware.atleap.webapp.form.ContentResourceForm; 23 import com.blandware.atleap.webapp.util.core.WebappConstants; 24 import org.apache.struts.action.ActionForm; 25 import org.apache.struts.action.ActionForward; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.action.ActionMessage; 28 import org.apache.struts.action.ActionMessages; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 54 public final class ViewFileAction extends BaseAction { 55 64 public ActionForward execute(ActionMapping mapping, ActionForm form, 65 HttpServletRequest request, HttpServletResponse response) throws Exception { 66 resetToken(request); 67 ContentResourceForm contentResourceForm = (ContentResourceForm) form; 68 Long contentResourceId = null; 69 if ( contentResourceForm.getId() != null ) { 70 contentResourceId = Long.valueOf(contentResourceForm.getId()); 71 } else if ( request.getAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY) != null ) { 72 contentResourceId = (Long ) request.getAttribute(WebappConstants.CONTENT_RESOURCE_ID_KEY); 73 } else { 74 if ( log.isWarnEnabled() ) { 75 log.warn("Missing content resource ID"); 76 } 77 return mapping.findForward("listContentResources"); 78 } 79 80 ContentResourceManager contentResourceManager = (ContentResourceManager) getBean(Constants.CONTENT_RESOURCE_MANAGER_BEAN); 81 ContentResource file = contentResourceManager.retrieveContentResource(contentResourceId); 82 83 if ( file == null ) { 84 ActionMessages errors = new ActionMessages(); 86 errors.add("fileNotFound", new ActionMessage("core.contentResource.file.errors.notFound")); 87 saveErrors(request, errors); 88 return mapping.findForward("listContentResources"); 89 } 90 91 request.setAttribute("file", file); 92 return mapping.findForward("viewFile"); 93 } 94 } | Popular Tags |