/Users/lyon/j4p/src/net/server/servlets/FormCData.java
|
1 package net.server.servlets;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.util.Properties;
7
8 /**
9 * FormCData Class
10 */
11
12 public class FormCData {
13
14 private FormCHtml fch = new FormCHtml();
15 private FormCDataParser fc;
16
17 private String formActionURL;
18
19 private int errorCode;
20 private String fieldNames[];
21 private String fieldValues[];
22
23 private Properties fileProp;
24 static final String FORMC_PROPERTY_FILE = Globals.FORMC_PROPERTY_FILE;
25
26 private static final int ERROR_PROPERTY_FILE = 0;
27 private static final int ERROR_CSV_FILE = 1;
28 private static final int ERROR_UNKNOWN = 2;
29 private static final int ERROR_SELECTION = 3;
30
31 /**
32 * Initializes the FormC Data elements
33 *
34 * @return boolean
35 */
36
37 public boolean init() {
38
39 try {
40 fileProp = FileUtil.loadProperties(FORMC_PROPERTY_FILE);
41 String fn = fileProp.getProperty("FileName");
42
43 System.out.println("The fileName is " + fn);
44
45 File file = FileUtil.getFile(fileProp.getProperty("FileName"));
46
47 formActionURL = fileProp.getProperty("FormCURL");
48 fc = new FormCDataParser(FileUtil.openInputFile(file));
49 return true;
50 } catch (PropFileException pfnf) {
51 errorCode = ERROR_PROPERTY_FILE;
52 return false;
53 } catch (FileNotFoundException fnf) {
54 errorCode = ERROR_CSV_FILE;
55 return false;
56 } catch (IOException io) {
57 errorCode = ERROR_UNKNOWN;
58 return false;
59 }
60 }
61
62 /**
63 * Course, Section and Term are displayed for the user logged in.
64 *
65 * @return String html
66 */
67
68 public String getDefaultFormC(String user) {
69
70
71 //deh was here and added newcode get multiple courses to show up on the comboxes.. yeah
72 //
73
74 if (fc.isCourseKeyByLoginUser(user)) {
75
76 // Get the scoop on the indexarray of courses and how many before procedding
77
78 int[] keyIndexArray = fc.getCourseKeyIndexArray();
79 int cKeyIndexLength = fc.getCourseKeyIndexLength();
80
81
82 String[] selCourse = new String[cKeyIndexLength + 1];
83
84 for (int i = 0; i <= cKeyIndexLength; i++) {
85 selCourse[i] = fc.getCourseNoByKey(keyIndexArray[i]) + " " +
86 fc.getCourseNameByKey(keyIndexArray[i]);
87 }
88
89
90 return (fch.formCSelect(fc.getTerm(), selCourse,
91 fc.getSection(), formActionURL));
92
93
94 }
95
96 return (fch.formCError(ERROR_SELECTION));
97 }
98
99
100 /**
101 * If no students are available for the selection criteria, error message
102 * will be displayed.
103 *
104 * @return String html
105 */
106
107 public String getErrorFormC() {
108
109 return (fch.formCError(errorCode));
110
111 }
112
113 /**
114 * Form C will be displayed for the selected Term, Course and Section.
115 *
116 * @return String html
117 */
118
119 public String getSelectFormC(String selTerm, String selCourse,
120 String selSection) {
121
122 StringBuffer selection = new StringBuffer();
123
124 selection.append(selTerm);
125 selection.append(" ");
126 selection.append(selCourse);
127 selection.append(" ");
128 selection.append(selSection);
129
130 String selInstructor = null;
131 String selStudents[] = null;
132
133 if (fc.isCourseKey(selection.toString())) {
134 int keyIndex = fc.getCourseKeyIndex();
135 selInstructor = fc.getCourseInstructorByKey(keyIndex);
136 selStudents = fc.getCourseStudentsByKey(keyIndex);
137
138 return (fch.formC(selTerm, selCourse, selInstructor,
139 selStudents, formActionURL));
140 } else {
141
142 return (fch.formCError(ERROR_SELECTION));
143 }
144
145 }
146
147
148 /**
149 * Form C selections are redisplayed for the confirmation.
150 *
151 *
152 * @return String html
153 */
154
155 public String getDisplayFormC(String[] fNames,
156 String[] fValues) {
157
158 int keyIndex = fc.getCourseKeyIndex();
159
160 fieldNames = new String[fNames.length];
161
162 for (int i = 0; i < fNames.length; i++) {
163 fieldNames[i] = fNames[i];
164 }
165
166 fieldValues = new String[fValues.length];
167
168 for (int i = 0; i < fValues.length; i++) {
169 fieldValues[i] = fValues[i];
170 }
171
172 return (fch.formCData(fc.getCourseTermByKey(keyIndex),
173 fc.getCourseNoByKey(keyIndex) + " " +
174 fc.getCourseNameByKey(keyIndex),
175 fc.getCourseInstructorByKey(keyIndex),
176 fc.getCourseStudentsByKey(keyIndex),
177 fieldNames,
178 fieldValues));
179
180
181 }
182
183 /**
184 * Creates a outfile for the SQL insert statement and post confirmation
185 * page will be displayed.
186 *
187 * @return String html
188 */
189
190 public String getSqlFormC() {
191
192 FormCSQL fcSql = new FormCSQL(fc);
193 fcSql.generateFormCSQL(fieldNames, fieldValues);
194 return (fch.formCUpdate());
195 }
196 }
197