1 package org.cacert.gigi.pages.wot;
3 import java.io.InputStreamReader;
4 import java.io.PrintWriter;
5 import java.text.ParseException;
6 import java.text.SimpleDateFormat;
8 import java.util.HashMap;
11 import javax.servlet.http.HttpServletRequest;
13 import org.cacert.gigi.Language;
14 import org.cacert.gigi.User;
15 import org.cacert.gigi.output.Form;
16 import org.cacert.gigi.output.Template;
18 public class AssuranceForm extends Form {
20 static final Template templ;
22 templ = new Template(new InputStreamReader(
23 AssuranceForm.class.getResourceAsStream("AssuranceForm.templ")));
26 public AssuranceForm(int assuree) {
27 this.assuree = new User(assuree);
31 public void output(PrintWriter out, Language l, Map<String, Object> vars) {
32 HashMap<String, Object> res = new HashMap<String, Object>();
34 res.put("name", assuree.getName());
35 templ.output(out, l, res);
37 SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
40 public boolean submit(PrintWriter out, HttpServletRequest req) {
41 out.println("<div class='formError'>");
42 boolean failed = false;
44 if (!"1".equals(req.getParameter("certify"))
45 || !"1".equals(req.getParameter("rules"))
46 || !"1".equals(req.getParameter("CCAAgreed"))
47 || !"1".equals(req.getParameter("assertion"))) {
48 outputError(out, req, "You failed to check all boxes to validate"
49 + " your adherence to the rules and policies of CAcert");
53 if (req.getParameter("date") == null
54 || req.getParameter("date").equals("")) {
56 "You must enter the date when you met the assuree.");
60 Date d = sdf.parse(req.getParameter("date"));
61 if (d.getTime() > System.currentTimeMillis()) {
63 "You must not enter a date in the future.");
66 } catch (ParseException e) {
68 "You must enter the date in this format: YYYY-MM-DD.");
72 // check location, min 3 characters
73 if (req.getParameter("location") == null
74 || req.getParameter("location").equals("")) {
76 "You failed to enter a location of your meeting.");
78 } else if (req.getParameter("location").length() <= 2) {
80 "You must enter a location with at least 3 characters eg town and country.");
84 out.println("</div>");