Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Maintainer.java

Go to the documentation of this file.
00001 package cedar.jetweb.servlet;
00002 
00003 import javax.servlet.ServletConfig;
00004 import javax.servlet.ServletException;
00005 import javax.servlet.http.HttpServletRequest;
00006 import javax.servlet.http.HttpServletResponse;
00007 import javax.servlet.http.HttpServlet;
00008 import java.io.PrintWriter;
00009 import java.util.Enumeration;
00010 import java.util.List;
00011 import java.util.Vector;
00012 
00013 import cedar.jetweb.model.paper.PaperBank;
00014 import cedar.jetweb.model.plots.PlotSelection;
00015 import cedar.jetweb.model.*;
00016 import cedar.jetweb.JetWebConfig;
00017 import cedar.jetweb.JetWebException;
00018 import cedar.jetweb.job.JobUtils;
00019 import cedar.jetweb.html.*;
00020 
00021 import com.oreilly.servlet.multipart.*;
00022 
00023 //import cedar.jetweb.db.DBConfig;
00024 
00032 public class Maintainer extends HttpServlet {
00033 
00040     public void init(ServletConfig config) throws ServletException {
00041         super.init(config);
00042 
00043     // Set up configuration with servlet mode on. 
00044     JetWebConfig.init();
00045 
00046     // Read in all papers from the database.
00047     try {
00048         PaperBank.getConfig();
00049     } catch (JetWebException e){
00050         System.out.println(e.getMessage());
00051         e.printStackTrace(System.out);
00052     }
00053     }
00054 
00058     public void destroy() {
00059     }
00065     protected void doGet(HttpServletRequest request, HttpServletResponse response)
00066 
00067     throws ServletException, java.io.IOException {
00068 
00069     String servletPath = JetWebConfig.mainServletPath;
00070 
00071     String title = "Control Screen";
00072     response.setContentType("text/html");
00073     PrintWriter out = response.getWriter();
00074     ResultSearchPattern pattern; 
00075     PlotSelection selection;
00076     
00077 
00078     JetWebConfig.setPrintWriter(out);
00079 
00080     // Build a search pattern from the page.
00081     try {
00082         // Methods not requiring a pattern or a selection
00083         if ((request.getParameter("MORERESULTS")!=null)){
00084 
00085         boolean verbose = Boolean.parseBoolean(request.getParameter("VERBOSE"));
00086         boolean modifiable = Boolean.parseBoolean(request.getParameter("MODIFIABLE"));
00087         HTMLUtils.displayListContinued(out,servletPath,verbose,modifiable,
00088                            request.getParameter("RESULTKEY"));
00089         return;
00090         }
00091 
00092         pattern = ServletUtils.makePattern(request);
00093 
00094         // Build a paper selection from the page.
00095         selection = ServletUtils.makePlotSelection(request);
00096         if (selection.fitIsEmpty()) { selection.setFitDefault(); }
00097         if (selection.sumIsEmpty()) { selection.setSumDefault(); }
00098         
00099         System.out.println("ACCESS FROM: "+request.getRemoteHost()+" = "+request.getRemoteAddr());
00100         String requestingHost = request.getRemoteHost();
00101         System.out.println(request.getContentType());
00102 
00103         Enumeration enmrt = request.getParameterNames();
00104         while (enmrt.hasMoreElements()){
00105         System.out.println("-----");
00106         System.out.println((String)enmrt.nextElement());
00107         System.out.println("-----");
00108         }   
00109         
00110         if (request.getParameter("CONFIG") != null) {
00111         // Submit a job (first pass) //////////////////////
00112         ServletUtils.updateConfig(request);
00113         HTMLUtils.writeControlScreen(" ",pattern,selection,out,servletPath);
00114         return;
00115 
00116         } else if ((request.getParameter("SUBMITFITEDIT") != null)) {
00117         System.out.println("Submitted edit request");
00118         ServletUtils.editFit(request,out,servletPath);
00119         return;
00120 
00121         } else if ((request.getParameter("PROCESSTYPE") != null)) {
00122         System.out.println("ProcessType management");
00123         // Write out all the MCProcessTypes, modifiable
00124         List<MCProcessType> list = new Vector<MCProcessType>();
00125         // Write out all the MCProcessTypes.
00126         list.addAll(MCProcessType.getAll(false));
00127         HTMLUtils.displayList(out,servletPath,true,true,list);
00128         return;
00129 
00130         } else if ((request.getParameter("MODIFYPROC") != null)) {
00131         System.out.println("Modifying ProcessType");
00132         MCProcessType proc = ServletUtils.buildProc(request);
00133         proc.store();
00134         // Write out all the MCProcessTypes, modifiable
00135         List<MCProcessType> list = new Vector<MCProcessType>();
00136         // Write out all the MCProcessTypes.
00137         list.addAll(MCProcessType.getAll(false));
00138         HTMLUtils.displayList(out,servletPath,true,true,list);
00139         return;
00140 
00141         } else if ((request.getParameter("DELETEPROC") != null)) {
00142         System.out.println("Deleting ProcessType");
00143         MCProcessType proc 
00144             = new MCProcessType(Integer.parseInt(request.getParameter("PROCESSID")));
00145         proc.delete();
00146         // Write out all the MCProcessTypes, modifiable
00147         List<MCProcessType> list = new Vector<MCProcessType>();
00148         // Write out all the MCProcessTypes.
00149         list.addAll(MCProcessType.getAll(false));
00150         HTMLUtils.displayList(out,servletPath,true,true,list);
00151         return;
00152         
00153         } else if ( (request.getParameter("FITID") != null) &&
00154             (!request.getParameter("FITID").trim().equals("")) 
00155             && request.getParameter("FITFIX")!=null) {
00156 
00157         String fitId = request.getParameter("FITID");
00158         HTMLFitWriter op = new HTMLFitWriter(out,servletPath);
00159 
00160         op.startControlForm("<p>Editing fit number "
00161                     +fitId
00162                     +" <em>If you are not an expert, go away!</em></p>");
00163         
00164         op.writeFitEditForm(fitId);
00165         op.endForm();
00166         op.close();
00167         return;
00168         
00169         } else  if ((request.getParameter("CHANGEPAPER") != null)) {
00170         // Modify or add a paper //////////////////////////////////////////
00171         ServletUtils.changePaper(request,out);
00172         HTMLPaperWriter.writePaperScreen(request.getParameter("PAPERID"),out,servletPath);
00173         return;
00174 
00175         } else  if ((request.getParameter("DELETEPAPER") != null)) {
00176         // Modify or add a paper //////////////////////////////////////////
00177         ServletUtils.deletePaper(request);
00178         HTMLUtils.writeControlScreen("Paper deleted",pattern,selection,out,servletPath);
00179         return;
00180         
00181         } else  if ((request.getParameter("PAPERID") != null)
00182                 && ( !request.getParameter("PAPERID").trim().equals(""))&& request.getParameter("PAPERMOD")!=null) {
00183         // Modify or add a paper //////////////////////////////////////////
00184         HTMLPaperWriter.writePaperScreen(request.getParameter("PAPERID"),out,servletPath);
00185         return;
00186         
00187         } else  if ((request.getParameter("PAPERADD") != null)) {
00188         // Modify or add a paper //////////////////////////////////////////
00189         HTMLPaperWriter.writePaperScreen(request.getParameter("PAPERID"),out,servletPath);
00190         return;
00191         
00192         } else  if ((request.getParameter("PROCESSNEW") != null)) {
00193         // Assimilate any new results //////////////////////////////////////////////
00194         JobUtils.updateJobs();
00195         HTMLUtils.writeControlScreen("Successfully run new results.",
00196                         pattern,selection,out,servletPath);
00197         return;
00198         }else if (request.getParameter("DEFAULTSMOD") != null){
00199         ServletUtils.generatorDefaults(request);
00200         HTMLUtils.writeControlScreen("Successfully updated Jetweb database",
00201                         pattern,selection,out,servletPath);
00202 
00203         System.out.println("Value of XMLDEFAULTS is "+request.getParameter("XMLDEFAULTS"));
00204 
00205         return;
00206 
00207         } else  if ((request.getParameter("FINISHED") != null)) {
00208         // Modify or add a paper //////////////////////////////////////////
00209         HTMLUtils.writeControlScreen(" ",pattern,selection,out,servletPath);
00210         return;
00211         
00212         } else if ((request.getParameter("CANCEL") != null)) {
00213         // Cancel. //////////////////////////////////////////////
00214         pattern  = new ResultSearchPattern();
00215         selection= new PlotSelection();
00216         HTMLUtils.writeControlScreen("Cancelled operation",
00217                         pattern,selection,out,servletPath);
00218         return;
00219         
00220         } else if ((request.getParameter("SEARCH") != null)) {
00221         // Search //////////////////////////////////////////////
00222         HTMLUtils.writeQueryScreen(" ",pattern,selection,out,JetWebConfig.searchServletPath);
00223         return;
00224         
00225         } else if ((request.getParameter("PENDING") != null)) {
00226         HTMLUtils.listPendingJobs(out,servletPath);
00227         return;
00228         
00229         } else {
00230         // If we get here, just write a new control page.
00231         HTMLUtils.writeControlScreen(" ",pattern,selection,out,servletPath);
00232         }
00233 
00234     } catch (JetWebException e){
00235         HTMLErrorWriter.write(out,e);
00236         return;
00237     }
00238 
00239 
00240     }
00245     protected void doPost(HttpServletRequest request, HttpServletResponse response)
00246     throws ServletException, java.io.IOException {
00247         doGet(request,response);
00248     }
00249 
00252     public String getServletInfo() {
00253         return "Test servlet. Do not use.";
00254     }
00255 
00256 }
00257 
00258 
00259 
00260 
00261 
00262 
00263 

Generated Wed Jan 17 09:14:27 GMT 2007