View Javadoc

1   /***
2    * 
3    */
4   package pl.agh.iosr.ballamigos.webapp.jscommunication;
5   
6   import java.io.IOException;
7   
8   import javax.servlet.ServletConfig;
9   import javax.servlet.ServletContext;
10  import javax.servlet.ServletException;
11  import javax.servlet.http.HttpServlet;
12  import javax.servlet.http.HttpServletRequest;
13  import javax.servlet.http.HttpServletResponse;
14  
15  import pl.agh.iosr.ballamigos.common.MatchProperties;
16  import pl.agh.iosr.ballamigos.common.Obstacle;
17  import pl.agh.iosr.ballamigos.webapp.core.WebApplicationCommunicator;
18  
19  /***
20   * @author wrobel
21   *
22   */
23  public class LoadArenaServlet extends HttpServlet {
24  	   	private ServletContext context;
25  	 
26  	    public void init(ServletConfig config) throws ServletException {
27  	    	this.context = config.getServletContext();
28  	    }
29  
30  	    public void doPost(HttpServletRequest request, HttpServletResponse  response)
31  	        throws IOException, ServletException {
32  	    	String saved;
33  	    	
34  	        response.setContentType("text/xml");
35  	        response.setHeader("Cache-Control", "no-cache");
36  	        
37  	        try{
38  	        	WebApplicationCommunicator wac = Helper.getClientCommunicator(request);
39  	        	MatchProperties properties = wac.getMatch().getProperties();
40  	        	
41  		        saved = "^";
42  		        saved += "" + properties.getSizeX();
43  		        saved += " " + properties.getSizeY();
44  		        saved += " " + properties.getLeftGoalPosition().getOffsetFromCorner();
45  		        saved += " " + properties.getLeftGoalPosition().getSize();
46  		        saved += " " + properties.getBluePositionY(0) + " " + properties.getBluePositionX(0);
47  		        saved += " " + properties.getBluePositionY(1) + " " + properties.getBluePositionX(1);
48  		        saved += " " + properties.getBluePositionY(2) + " " + properties.getBluePositionX(2);		        
49  		        
50  		        int nobst = properties.getObstaclesNumber();
51  		        saved += " " + nobst; 
52  		        for (int i = 0; i < nobst; ++i){
53  		        	Obstacle o = properties.getObstacle(i);
54  		        	int type =  o.getObstacleType();
55  		        	if (type == 3)
56  		        		type = 1;
57  		        	else if (type == 1)
58  		        		type = 0;
59  		        	saved += " " + o.getObstacleType();
60  		        	saved += " " + o.getPositionX();
61  		        	saved += " " + o.getPositionX() + o.getSizeX();
62  		        	saved += " " + o.getPositionY();
63  		        	saved += " " + o.getPositionY() + o.getSizeY();
64  		    		        
65  		        }
66  		        response.getWriter().write(saved);
67  	        
68  	        }catch(Exception ex){
69  	        	response.getWriter().write("Excpetion: " + ex.toString());
70  	        }
71  	        
72  	    }
73  }