X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FGigiApiException.java;h=0d600b973f3284fa17fe8861e51398148b9aa448;hb=10ea8fe7c71bfab653785f6599103fdf36f8a842;hp=b858e7d9a35d662c5ecefc10375d9a798d33349b;hpb=bf7a986282dfd7b3b77c25fe6617146fdd804f06;p=gigi.git diff --git a/src/org/cacert/gigi/GigiApiException.java b/src/org/cacert/gigi/GigiApiException.java index b858e7d9..0d600b97 100644 --- a/src/org/cacert/gigi/GigiApiException.java +++ b/src/org/cacert/gigi/GigiApiException.java @@ -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 messages = new LinkedList<>(); @@ -51,7 +55,7 @@ public class GigiApiException extends Exception { if (isInternalError()) { e.printStackTrace(); out.print("
"); - out.println(language.getTranslation("An internal error ouccured.")); + out.println(language.getTranslation("An internal error occurred.")); out.println("
"); } HashMap 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 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 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();