| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
package com.buckosoft.PicMan.web; |
| 9 | |
|
| 10 | |
import java.io.IOException; |
| 11 | |
|
| 12 | |
import javax.servlet.http.HttpServletRequest; |
| 13 | |
import javax.servlet.http.HttpServletResponse; |
| 14 | |
|
| 15 | |
import org.apache.commons.logging.Log; |
| 16 | |
import org.apache.commons.logging.LogFactory; |
| 17 | |
import org.springframework.web.servlet.ModelAndView; |
| 18 | |
import org.springframework.web.servlet.mvc.Controller; |
| 19 | |
|
| 20 | |
import com.buckosoft.BSAccount.web.BSAccountPageController; |
| 21 | |
import com.buckosoft.BSAccount.web.BSAccountUserWebSession; |
| 22 | |
import com.buckosoft.PicMan.business.PicManFacade; |
| 23 | |
import com.buckosoft.PicMan.domain.User; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 0 | public class WebEditController extends BSAccountPageController implements Controller { |
| 33 | |
private final static boolean DEBUG = false; |
| 34 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 35 | |
|
| 36 | |
private PicManFacade pmf; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public void setPicMan(PicManFacade pmf) { this.pmf = pmf; } |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { |
| 49 | 0 | String cid = request.getParameter("cid"); |
| 50 | 0 | String c = request.getParameter("c"); |
| 51 | 0 | String command = request.getParameter("command"); |
| 52 | |
if (DEBUG) { |
| 53 | |
if (!command.equals("PicManStatus")) |
| 54 | |
logger.info("XML Request com=" + command + " c=" + c + " cid=" + cid); |
| 55 | |
} |
| 56 | 0 | response.setContentType("text/plain"); |
| 57 | 0 | response.addHeader("Cache-Control", "max-age=0"); |
| 58 | 0 | response.addHeader("Cache-Control", "no-cache"); |
| 59 | 0 | response.addHeader("expires", "0"); |
| 60 | 0 | response.addHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT"); |
| 61 | 0 | response.addHeader("Pragma", "no-cache"); |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
try { |
| 70 | 0 | if (command == null) { |
| 71 | 0 | response.sendError(550, "No command in request"); |
| 72 | 0 | return(null); |
| 73 | |
} |
| 74 | 0 | else if (command.equals("DeleteMosaicTiles")) |
| 75 | 0 | pmf.getDB().deleteMosaicTiles(Integer.parseInt(c)); |
| 76 | 0 | else if (command.equals("DeleteVirgin")) |
| 77 | 0 | pmf.getDB().deleteVirgin(c); |
| 78 | 0 | else if (command.equals("UpdateOptions")) { |
| 79 | 0 | if (!updateOptions(request, response)) |
| 80 | 0 | response.sendError(251, "Failed to update Options"); |
| 81 | |
|
| 82 | |
} else { |
| 83 | 0 | response.sendError(551, "Unknown command '" + command + "' in request"); |
| 84 | |
} |
| 85 | 0 | } catch (NumberFormatException e) { |
| 86 | 0 | logger.info(e); |
| 87 | 0 | pmf.addError(e); |
| 88 | 0 | } catch (IOException e) { |
| 89 | 0 | logger.info(e); |
| 90 | 0 | pmf.addError(e); |
| 91 | 0 | } |
| 92 | |
|
| 93 | 0 | return null; |
| 94 | |
} |
| 95 | |
|
| 96 | |
private boolean updateOptions(HttpServletRequest request, HttpServletResponse response) { |
| 97 | 0 | User user = null; |
| 98 | 0 | BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request); |
| 99 | 0 | if (userWebSession != null) |
| 100 | 0 | user = (User)userWebSession.getUser(); |
| 101 | 0 | if (user == null) { |
| 102 | 0 | logger.warn("Can't update options for unknown user"); |
| 103 | 0 | return(false); |
| 104 | |
} |
| 105 | 0 | String showFileDates = request.getHeader("showFileDates"); |
| 106 | 0 | String showChangedFilters = request.getHeader("showChangedFilters"); |
| 107 | 0 | if (showFileDates == null || showChangedFilters == null) |
| 108 | 0 | return(false); |
| 109 | 0 | user.setEditorShowFileDates(showFileDates.equals("1") ? true : false); |
| 110 | 0 | user.setEditorShowChangedFilters(showChangedFilters.equals("1") ? true : false); |
| 111 | 0 | pmf.getDB().storeUser(user); |
| 112 | 0 | return(true); |
| 113 | |
} |
| 114 | |
|
| 115 | |
} |