alertlistcontroller.java

来自「Java的框架」· Java 代码 · 共 69 行

JAVA
69
字号
package mcaps.core.alert.webapp.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mcap.core.alert.model.Alert;
import mcap.core.alert.service.AlertManager;
import mcap.core.alert.util.NameConstants;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;


/**
 * This class handles the request to retrieve a list of alert from the data
 * source.
 * 
 * @author Tan Beng Suang
 * @date 07-Sep-2005
 * @version 1.0.1.0
 */
public class AlertListController implements Controller {

	private AlertManager alertManager;
	
	/**
	 * Sets the alertManager.
	 * @param alertManager The alertManager to set.
	 */
	public void setAlertManager (AlertManager alertManager) {
		this.alertManager = alertManager;
	}


	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	public ModelAndView handleRequest (HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		if (request.getRequestURI ().indexOf ("listAlert.action") > -1) {
			
			//only user will "alertSender" or "alertAdmin" can view list.
			if (!request.isUserInRole(NameConstants.ALERT_SENDER_ROLE) 
					&& !request.isUserInRole(NameConstants.ALERT_ADMIN_ROLE)) {
				response.sendError (HttpServletResponse.SC_FORBIDDEN);
				return null;
			}
			
			Alert alert = new Alert ();
			
			if (request.isUserInRole(NameConstants.ALERT_ADMIN_ROLE) &&
					request.getParameter("showAll") != null) {
				return new ModelAndView ("core/alert/alertList", NameConstants.ALERT_LIST, this.alertManager.getAlerts(alert));
			}
			else {
				alert.setCreator (request.getRemoteUser());
				return new ModelAndView ("core/alert/alertList", NameConstants.ALERT_LIST, this.alertManager.getAlerts(alert));
			}
		}	
		else if (request.getRequestURI ().indexOf ("listMyAlert.action") > -1) {
			return new ModelAndView ("core/alert/userAlertList", NameConstants.ALERT_LIST, this.alertManager.getUserAlerts(request.getRemoteUser(), true));
		}
		
		return null;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?