View Javadoc

1   package pl.agh.iosr.ballamigos.webapp.actions;
2   
3   import javax.servlet.http.HttpServletRequest;
4   import javax.servlet.http.HttpSession;
5   
6   import org.apache.struts.action.Action;
7   import org.apache.struts.action.ActionMessage;
8   import org.apache.struts.action.ActionMessages;
9   
10  public class BallAmigosAction extends Action {
11  
12  	/***Checks whether the user is logged in and sets a notLoggedInError if he/she isn't. This should result
13  	 * in redirecting to an error page asking the user to log into the system first.
14  	 * 
15  	 * @param request
16  	 * @return answer to the question: is the player looged in?
17  	 */
18  	public boolean playerLoggedIn(HttpServletRequest request) {
19  		HttpSession session = request.getSession();
20  		
21  		if(session.getAttribute("login") == null) {
22  			dealWithException(request,"notLoggedInError","notLoggedIn.error");
23  			return false;
24  		}
25  		return true;		
26  	}
27  	
28  	/***Adds an action message named by str2.
29  	 * 
30  	 * @param request
31  	 * @param str1
32  	 * @param str2
33  	 */
34  	public void dealWithException(HttpServletRequest request, String str1, String str2) {
35  		ActionMessages errors = new ActionMessages();
36  		errors.add(str1, new ActionMessage(str2));
37  		addErrors(request, errors);		
38  	}
39  	
40  }