1 package org.cacert.gigi;
3 import java.io.PrintWriter;
4 import java.io.StringWriter;
5 import java.sql.SQLException;
6 import java.util.HashMap;
7 import java.util.LinkedList;
8 import java.util.Locale;
10 import org.cacert.gigi.localisation.Language;
11 import org.cacert.gigi.output.template.Outputable;
12 import org.cacert.gigi.output.template.TranslateCommand;
14 public class GigiApiException extends Exception {
16 private SQLException e;
18 private LinkedList<Outputable> messages = new LinkedList<>();
20 public GigiApiException(SQLException e) {
25 public GigiApiException(String message) {
27 messages.add(new TranslateCommand(message));
30 public GigiApiException() {
34 public GigiApiException(Outputable out) {
38 public void mergeInto(GigiApiException e2) {
39 messages.addAll(e2.messages);
45 public boolean isInternalError() {
49 public void format(PrintWriter out, Language language) {
50 out.println("<div class='formError'>");
51 if (isInternalError()) {
54 out.println(language.getTranslation("An internal error ouccured."));
55 out.println("</div>");
57 HashMap<String, Object> map = new HashMap<>();
58 for (Outputable message : messages) {
62 message.output(out, language, map);
63 out.println("</div>");
65 out.println("</div>");
69 public boolean isEmpty() {
70 return e == null && messages.size() == 0;
74 public String getMessage() {
75 if (messages.size() != 0) {
76 StringWriter sw = new StringWriter();
77 PrintWriter pw = new PrintWriter(sw);
79 HashMap<String, Object> map = new HashMap<>();
80 for (Outputable message : messages) {
82 message.output(pw, Language.getInstance(Locale.ENGLISH), map);