/Users/lyon/j4p/src/net/server/servlets/FormC.java
|
1 package net.server.servlets;
2
3 import javax.servlet.ServletException;
4 import javax.servlet.http.HttpServlet;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7 import javax.servlet.http.HttpSession;
8 import java.io.IOException;
9 import java.io.PrintWriter;
10 import java.util.Properties;
11
12 /**
13 * FormC Class
14 */
15
16 public class FormC extends HttpServlet {
17
18 /**
19 * If the user came througth the Login Prompt then the FormC selection
20 * will be displayed for the respective user, otherwise process is
21 * redirected to Login Page.
22 *
23 */
24
25 static final String FORMC_PROPERTY_FILE = Globals.FORMC_PROPERTY_FILE;
26
27 public void doGet(HttpServletRequest request,
28 HttpServletResponse response)
29 throws IOException, ServletException {
30
31 response.setContentType("text/html");
32 PrintWriter out = response.getWriter();
33 System.out.println("Loading FormC");
34
35 HttpSession session = request.getSession(true);
36 String user = (String) session.getValue("userId");
37
38 if (user == null) {
39 response.sendRedirect(getRedirectURL());
40 } else {
41 FormCData fcData = (FormCData) session.getValue("fcData");
42 getFormC(request, response, session, out, fcData, user);
43 }
44
45 }
46
47 /**
48 * Calls the doGet() method
49 *
50 * @throws java.io.IOException ServletException
51 */
52
53 public void doPost(HttpServletRequest request,
54 HttpServletResponse response)
55 throws IOException, ServletException {
56
57 doGet(request, response);
58 }
59
60 /**
61 * getRedirectURL Method
62 *
63 * @return String
64 */
65
66 private String getRedirectURL() {
67 try {
68 Properties prop = FileUtil.loadProperties("FormC.Property");
69 System.out.println("The loginURL is " + prop.getProperty("LoginURL"));
70 return prop.getProperty("LoginURL");
71 } catch (PropFileException pfnf) {
72 pfnf.printStackTrace();
73 return null;
74 }
75 }
76
77 /**
78 * getFormC Method
79 *
80
81 */
82
83 private void getFormC(HttpServletRequest request,
84 HttpServletResponse response,
85 HttpSession session,
86 PrintWriter out,
87 FormCData fcData,
88 String user) {
89
90 String nextAction = (String) session.getValue("nextAction");
91
92 System.out.println("Next action is " + nextAction);
93
94 if (!nextAction.equals("FormC"))
95 nextAction = request.getParameter("txtNextAction");
96
97 if ((fcData == null) || (nextAction.equals("FormC"))) {
98 session.putValue("nextAction", "CollectData");
99 fcDataInit(session, out, fcData, user);
100 } else if (nextAction.equals("CollectData")) {
101 selectFormC(request, session, out, fcData);
102 } else if (nextAction.equals("DisplayData")) {
103 displayFormCData(request, session, out, fcData);
104 } else if (nextAction.equals("SQL")) {
105 out.println(fcData.getSqlFormC());
106 }
107 }
108
109 /**
110 * fcDataInit Method
111 *
112 */
113
114 private void fcDataInit(HttpSession session, PrintWriter out,
115 FormCData fcData, String user) {
116 if (fcData == null) {
117 fcData = new FormCData();
118 if (fcData.init()) {
119 session.putValue("fcData", fcData);
120 // System.out.println("We are trying to initialize the data " + user);
121
122 out.println(fcData.getDefaultFormC(user));
123 } else {
124 out.println(fcData.getErrorFormC());
125 }
126 } else {
127 out.println(fcData.getDefaultFormC(user));
128 }
129
130 }
131
132
133 /**
134 * selectFormC Method
135 *
136
137 */
138
139 private void selectFormC(HttpServletRequest request, HttpSession session,
140 PrintWriter out, FormCData fcData) {
141
142 String term = request.getParameter("cboTerm");
143 String course = request.getParameter("cboCourse");
144 String section = request.getParameter("cboSection");
145
146 out.println(fcData.getSelectFormC(term, course, section));
147
148 }
149
150 /**
151 * displayFormCData Method
152 *
153
154 */
155
156 private void displayFormCData(HttpServletRequest request,
157 HttpSession session,
158 PrintWriter out,
159 FormCData fcData) {
160
161 String[] iNames = RequestUtil.getParmNames(request);
162 String[] iValues = RequestUtil.getParmValues(iNames, request);
163
164 out.println(fcData.getDisplayFormC(iNames, iValues));
165
166 }
167
168 }
169
170
171
172