]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/GigiApiException.java
Merge "Suggestions to enhance the SQL call pattern."
[gigi.git] / src / org / cacert / gigi / GigiApiException.java
index b858e7d9a35d662c5ecefc10375d9a798d33349b..0d600b973f3284fa17fe8861e51398148b9aa448 100644 (file)
@@ -13,6 +13,10 @@ import org.cacert.gigi.output.template.TranslateCommand;
 
 public class GigiApiException extends Exception {
 
+    private static final Language PLAIN_LANGUAGE = Language.getInstance(Locale.ENGLISH);
+
+    private static final long serialVersionUID = -164928670180852588L;
+
     private SQLException e;
 
     private LinkedList<Outputable> messages = new LinkedList<>();
@@ -51,7 +55,7 @@ public class GigiApiException extends Exception {
         if (isInternalError()) {
             e.printStackTrace();
             out.print("<div>");
-            out.println(language.getTranslation("An internal error ouccured."));
+            out.println(language.getTranslation("An internal error occurred."));
             out.println("</div>");
         }
         HashMap<String, Object> map = new HashMap<>();
@@ -66,6 +70,24 @@ public class GigiApiException extends Exception {
 
     }
 
+    public void formatPlain(PrintWriter out) {
+        if (isInternalError()) {
+            out.println(PLAIN_LANGUAGE.getTranslation("An internal error occurred."));
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        for (Outputable message : messages) {
+            if (message instanceof TranslateCommand) {
+                String m = ((TranslateCommand) message).getRaw();
+                // Skip HTML Entities
+                out.println(PLAIN_LANGUAGE.getTranslation(m));
+            } else {
+                map.clear();
+                message.output(out, PLAIN_LANGUAGE, map);
+                out.println();
+            }
+        }
+    }
+
     public boolean isEmpty() {
         return e == null && messages.size() == 0;
     }
@@ -79,7 +101,7 @@ public class GigiApiException extends Exception {
             HashMap<String, Object> map = new HashMap<>();
             for (Outputable message : messages) {
                 map.clear();
-                message.output(pw, Language.getInstance(Locale.ENGLISH), map);
+                message.output(pw, PLAIN_LANGUAGE, map);
             }
             pw.flush();