]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/GigiApiException.java
fix: a problem when setting up new test environments
[gigi.git] / src / org / cacert / gigi / GigiApiException.java
index 8851ec4412efaf4f848a4ed142de11344bbc1291..944fe645ece5618fb2dc93afc5318d164be6c84b 100644 (file)
@@ -1,16 +1,23 @@
 package org.cacert.gigi;
 
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.Locale;
 
 import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
 
 public class GigiApiException extends Exception {
 
-    SQLException e;
+    private static final long serialVersionUID = -164928670180852588L;
 
-    LinkedList<String> messages = new LinkedList<>();
+    private SQLException e;
+
+    private LinkedList<Outputable> messages = new LinkedList<>();
 
     public GigiApiException(SQLException e) {
         super(e);
@@ -19,13 +26,17 @@ public class GigiApiException extends Exception {
 
     public GigiApiException(String message) {
         super(message);
-        messages.add(message);
+        messages.add(new TranslateCommand(message));
     }
 
     public GigiApiException() {
 
     }
 
+    public GigiApiException(Outputable out) {
+        messages.add(out);
+    }
+
     public void mergeInto(GigiApiException e2) {
         messages.addAll(e2.messages);
         if (e == null) {
@@ -45,9 +56,12 @@ public class GigiApiException extends Exception {
             out.println(language.getTranslation("An internal error ouccured."));
             out.println("</div>");
         }
-        for (String message : messages) {
+        HashMap<String, Object> map = new HashMap<>();
+        for (Outputable message : messages) {
+            map.clear();
+
             out.print("<div>");
-            out.print(language.getTranslation(message));
+            message.output(out, language, map);
             out.println("</div>");
         }
         out.println("</div>");
@@ -58,4 +72,22 @@ public class GigiApiException extends Exception {
         return e == null && messages.size() == 0;
     }
 
+    @Override
+    public String getMessage() {
+        if (messages.size() != 0) {
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+
+            HashMap<String, Object> map = new HashMap<>();
+            for (Outputable message : messages) {
+                map.clear();
+                message.output(pw, Language.getInstance(Locale.ENGLISH), map);
+            }
+            pw.flush();
+
+            return sw.toString();
+        }
+        return "";
+    }
+
 }