View Javadoc
1   /******************************************************************************
2    * MosaicAnalyseAjaxController.java - The Spring controller for the Mosaic Analyse AJAX calls
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2008 - Dick Balaska
6    * 
7    */
8   
9   package com.buckosoft.PicMan.web;
10  
11  import java.io.IOException;
12  
13  import javax.servlet.http.HttpServletRequest;
14  import javax.servlet.http.HttpServletResponse;
15  
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  import org.springframework.web.servlet.ModelAndView;
19  
20  import com.buckosoft.BSAccount.web.BSAccountPageController;
21  import com.buckosoft.PicMan.business.PicManFacade;
22  
23  /** The Spring controller for the Mosaic Analysis page AJAX calls
24   * @author Dick Balaska
25   * @since 2008/05/30
26   * @see <a href="http://cvs.buckosoft.com/Projects/java/PicMan/PicMan/src/com/buckosoft/PicMan/web/ImportPicsAjaxController.java">ImportPicsAjaxController.java</a>
27   */
28  public class MosaicAnalyseAjaxController extends BSAccountPageController {
29  	private static boolean DEBUG = false;
30  	protected final Log logger = LogFactory.getLog(getClass());
31  
32  	private PicManFacade pmf;
33  
34  	/** Set the reference to the PicMan API.
35  	 * @param pmf The PicManFacade
36  	 */
37  	public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
38  
39  	/** Enable debug logger output on this module
40  	 * @param debugFlag true == turn on debugging.
41  	 */
42  	public void setDEBUG(boolean debugFlag) {
43  		DEBUG = debugFlag;
44  	}
45  
46  	/** Spring standard http request handler.
47  	 * @param request The http request.
48  	 * @param response The http response.
49  	 * @return null to return just an http status because we pushed the DOM out the response.
50  	 */ 
51  	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
52  		String cid = request.getParameter("cid");
53  		String c = request.getParameter("c");
54  		String command = request.getParameter("command");
55  		if (DEBUG) {
56  			if (!command.equals("PicManStatus"))
57  				logger.info("XML Request com=" + command + " c=" + c + " cid=" + cid);
58  		}
59  		response.setContentType("text/plain");
60  		response.addHeader("Cache-Control", "max-age=0");
61  		response.addHeader("Cache-Control", "no-cache");
62  		response.addHeader("expires", "0");
63  		response.addHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT");
64  		response.addHeader("Pragma", "no-cache");
65  
66  		try {
67  			if (command == null) {
68  				response.sendError(550, "No command in request");
69  				return(null);
70  			}
71  			else if (command.equals("DeleteMosaicTiles")) {
72  				pmf.getDB().deleteMosaicTiles(Integer.parseInt(c));
73  			}
74  			else {
75  				response.sendError(551, "Unknown command '" + command + "' in request");
76  			}
77  		} catch (NumberFormatException e) {
78  			logger.info(e);
79  			pmf.addError(e);
80  		} catch (IOException e) {
81  			logger.info(e);
82  			pmf.addError(e);
83  		}
84  
85  		return null;
86  	}
87  
88  }