]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/output/template/Form.java
add: Allow TranslationCommands to be serialized
[gigi.git] / src / org / cacert / gigi / output / template / Form.java
index 366d31c5913684a032eaf5b379996978a48673bd..f2219581be3c09b2d77cbbd2dff8ae30ac32de5a 100644 (file)
@@ -4,13 +4,11 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Map;
 
-import javax.servlet.ServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.localisation.Language;
-import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.util.RandomToken;
 
 /**
@@ -40,7 +38,7 @@ public abstract class Form implements Outputable {
      * @param hsr
      *            the request to register the form against.
      * @param action
-     *            the target path where the form should be submitted
+     *            the target path where the form should be submitted.
      */
     public Form(HttpServletRequest hsr, String action) {
         csrf = RandomToken.generateToken(32);
@@ -55,8 +53,8 @@ public abstract class Form implements Outputable {
      * @param out
      *            the stream to the user.
      * @param req
-     *            the request to take the initial data from
-     * @return true, iff the form succeeded an the user should be redirected.
+     *            the request to take the initial data from.
+     * @return true, iff the form succeeded and the user should be redirected.
      * @throws GigiApiException
      *             if internal operations went wrong.
      */
@@ -73,7 +71,6 @@ public abstract class Form implements Outputable {
         } else {
             out.println("<form method='POST' action='" + action + "'>");
         }
-        failed = false;
         outputContent(out, l, vars);
         out.print("<input type='hidden' name='" + CSRF_FIELD + "' value='");
         out.print(getCSRFToken());
@@ -84,47 +81,14 @@ public abstract class Form implements Outputable {
      * Outputs the forms contents.
      * 
      * @param out
-     *            Stream to the user
+     *            Stream to the user.
      * @param l
-     *            {@link Language} to translate text to
+     *            {@link Language} to translate text to.
      * @param vars
      *            Variables supplied from the outside.
      */
     protected abstract void outputContent(PrintWriter out, Language l, Map<String, Object> vars);
 
-    private boolean failed;
-
-    protected void outputError(PrintWriter out, ServletRequest req, String text, Object... contents) {
-        if ( !failed) {
-            failed = true;
-            out.println("<div class='formError'>");
-        }
-        out.print("<div>");
-        if (contents.length == 0) {
-            out.print(Page.translate(req, text));
-        } else {
-            out.print(String.format(Page.translate(req, text), contents));
-        }
-        out.println("</div>");
-    }
-
-    protected void outputErrorPlain(PrintWriter out, String text) {
-        if ( !failed) {
-            failed = true;
-            out.println("<div class='formError'>");
-        }
-        out.print("<div>");
-        out.print(text);
-        out.println("</div>");
-    }
-
-    public boolean isFailed(PrintWriter out) {
-        if (failed) {
-            out.println("</div>");
-        }
-        return failed;
-    }
-
     protected String getCSRFToken() {
         return csrf;
     }
@@ -135,7 +99,7 @@ public abstract class Form implements Outputable {
      * @param req
      *            the request that is directed to the form.
      * @param target
-     *            the {@link Class} of the expected form
+     *            the {@link Class} of the expected form.
      * @return the form where this request is directed to.
      * @throws CSRFException
      *             if no CSRF-token is found or the token is wrong.