1 19 20 package com.sslexplorer.setup.forms; 21 22 import java.text.SimpleDateFormat ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 26 import org.apache.struts.Globals; 27 import org.apache.struts.action.ActionErrors; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.action.ActionMessage; 30 31 import com.sslexplorer.core.CoreServlet; 32 import com.sslexplorer.core.forms.CoreForm; 33 import com.sslexplorer.tasks.shutdown.ShutdownTimerTask; 34 import com.sslexplorer.tasks.timer.StoppableTimer; 35 36 public class ShutdownForm extends CoreForm { 37 38 public static final String SHUTDOWN = "shutdown"; 39 public static final String RESTART = "restart"; 40 public static final String BOTH = "both"; 41 public static final String SHUTTING_DOWN = "shutting_down"; 42 43 private String shutdownDelay = "0"; 44 45 private String shutdownType; 46 private String shutdownOperation; 47 private boolean alreadyPerforming = false; 48 private String shutdownTime; 49 50 53 public String getShutdownType() { 54 return shutdownType; 55 } 56 57 60 public void setShutdownType(String shutdownType) { 61 this.shutdownType = shutdownType; 62 } 63 64 public String getShutdownDelay() { 65 return shutdownDelay; 66 } 67 68 public void setShutdownDelay(String shutdownTime) { 69 this.shutdownDelay = shutdownTime; 70 } 71 72 public boolean isImmediate(){ 73 if (getShutdownDelay().equals("0")) 74 return true; 75 else 76 return false; 77 } 78 79 public boolean getAlreadyPerforming(){ 80 return this.alreadyPerforming; 81 } 82 83 public void setAlreadyPerforming(boolean alreadyPerforming) { 84 this.alreadyPerforming = alreadyPerforming; 85 } 86 87 public String getShutdownTime() { 88 return shutdownTime; 89 } 90 91 public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) { 92 StoppableTimer timer = (StoppableTimer) CoreServlet.getServlet().getServletContext().getAttribute(StoppableTimer.NAME); 93 if (timer.containsTimerTask(ShutdownTimerTask.NAME)){ 94 shutdownTime = new SimpleDateFormat ("HH:mm").format(((ShutdownTimerTask)timer.getTimerTask(ShutdownTimerTask.NAME)).getShutDownTime()); 95 alreadyPerforming = true; 96 } 97 else { 98 shutdownTime = null; 99 alreadyPerforming = false; 100 } 101 102 ActionErrors errors = new ActionErrors(); 103 104 try { 105 int shutdownDelayInt = Integer.parseInt(getShutdownDelay()); 106 if(!getAlreadyPerforming() && shutdownDelayInt < 0) { 107 errors.add(Globals.ERROR_KEY, new ActionMessage("shutdown.global.error.message.negative")); 108 setShutdownDelay("0"); 109 return errors; 110 } 111 } catch (Exception e) { 112 errors.add(Globals.ERROR_KEY, new ActionMessage("shutdown.global.error.message.decimal")); 113 setShutdownDelay("0"); 114 } 115 116 return errors; 117 } 118 119 public void setShutdownOperation(String shutdownOperation) { 120 this.shutdownOperation = shutdownOperation; 121 } 122 123 public String getShutdownOperation() { 124 return shutdownOperation; 125 } 126 127 128 } | Popular Tags |