1 package hudson.util; 2 3 import hudson.Util; 4 import hudson.model.Hudson; 5 import org.kohsuke.stapler.StaplerRequest; 6 import org.kohsuke.stapler.StaplerResponse; 7 8 import javax.servlet.ServletException ; 9 import java.io.File ; 10 import java.io.IOException ; 11 12 15 public abstract class FormFieldValidator { 16 protected final StaplerRequest request; 17 protected final StaplerResponse response; 18 private final boolean isAdminOnly; 19 20 protected FormFieldValidator(StaplerRequest request, StaplerResponse response, boolean adminOnly) { 21 this.request = request; 22 this.response = response; 23 isAdminOnly = adminOnly; 24 } 25 26 29 public final void process() throws IOException , ServletException { 30 if(isAdminOnly && !Hudson.adminCheck(request,response)) 31 return; 33 check(); 34 } 35 36 protected abstract void check() throws IOException , ServletException ; 37 38 41 protected final File getFileParameter(String paramName) { 42 return new File (Util.fixNull(request.getParameter(paramName))); 43 } 44 45 48 public void ok() throws IOException , ServletException { 49 response.setContentType("text/html"); 50 response.getWriter().print("<div/>"); 51 } 52 53 56 public void error(String message) throws IOException , ServletException { 57 response.setContentType("text/html;charset=UTF-8"); 58 response.getWriter().print("<div class=error>"+message+"</div>"); 59 } 60 } 61 | Popular Tags |