import java.io.*; import javax.servlet.http.*; import java.util.Collection; import java.util.ArrayList; import java.util.Iterator; import java.util.HashMap; /** * Sets up the input map for the Processor and invokes it. Prints out the * result to the resulting HTML page. */ public class Output extends HttpServlet { private static final String PAGE_TITLE = "Output Page"; private static final int SLEEP_TIME = 50; public void doGet(HttpServletRequest req, HttpServletResponse rsp) { PrintWriter out = null; try { rsp.setContentType("text/html"); out = rsp.getWriter(); HttpSession session = req.getSession(false); if(session == null) { HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", "Login"); return; } TranscriptRequest transReq = (TranscriptRequest) session.getAttribute("transcript_request"); if(transReq == null) { transReq = new TranscriptRequest(); session.setAttribute("transcript_request", transReq); } if(!transReq.isStarted()) { HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", "Login"); } else { HTMLUtils.printRedirectPage(out, "You must specify your preferences prior to viewing this page.", "Input"); } } catch(Exception e) { try { HTMLUtils.printException(out, e); } catch(Exception e2) {} } } public void doPost(HttpServletRequest req, HttpServletResponse rsp) { PrintWriter out = null; try { rsp.setContentType("text/html"); out = rsp.getWriter(); if(req.getCookies() == null) { HTMLUtils.printRedirectPage(out, "You must enable cookies in your browser before using the advisement system.", "Login"); return; } HttpSession session = req.getSession(false); if(session == null) { HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", "Login"); return; } TranscriptRequest transReq = (TranscriptRequest) session.getAttribute("transcript_request"); if(transReq == null) { transReq = new TranscriptRequest(); session.setAttribute("transcript_request", transReq); } if(!transReq.isStarted()) { HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", "Login"); return; } while(!transReq.isDone()) Thread.sleep(SLEEP_TIME); Exception e = transReq.getException(); if(e != null) { if(e instanceof TranscriptException) { int errorCode = ((TranscriptException) e).getErrorCode(); if(errorCode == TranscriptException.ERROR_CONTINUE) { HTMLUtils.printRedirectPage(out, e.getMessage(), "Login"); return; } } throw e; } HashMap map = new HashMap(); String major, secondMajor, minor, coreNeeded; if((major = req.getParameter("major")) == null) { throw new FrontEndException( "Missing POST Data: major"); } if((minor = req.getParameter("minor")) == null) { throw new FrontEndException( "Missing POST Data: minor"); } if((secondMajor = req.getParameter("secondmajor")) == null) { throw new FrontEndException( "Missing POST Data: secondmajor"); } if((coreNeeded = req.getParameter("coreneeded")) == null) { throw new FrontEndException( "Missing POST Data: coreneeded"); } Collection courseList = transReq.getCourses(); RetrieverUtils.translateCourseList(courseList); map.put("courses", courseList); map.put("major", major); map.put("secondmajor", secondMajor); map.put("minor", minor); map.put("coreneeded", coreNeeded); map.put("totalcredits", transReq.getTotalCreditCount()); map.put("transfercredits", transReq.getTransferCreditCount()); String errorStr; if((errorStr=InputChecker.isInputMapOk(map)) != null) { HTMLUtils.printRedirectPage(out, errorStr, "Input"); return; } HTMLUtils.printHeader(out, PAGE_TITLE); Processor processor = new Processor(map); ArrayList arrList = processor.go(); HTMLUtils.printTable(out, arrList); HTMLUtils.printFooter(out); } catch(Exception e) { try { HTMLUtils.printException(out, e); } catch(Exception e2) {} } } }