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 static final long serialVersionUID = -164928670180852588L;
18 private SQLException e;
20 private LinkedList<Outputable> messages = new LinkedList<>();
22 public GigiApiException(SQLException e) {
27 public GigiApiException(String message) {
29 messages.add(new TranslateCommand(message));
32 public GigiApiException() {
36 public GigiApiException(Outputable out) {
40 public void mergeInto(GigiApiException e2) {
41 messages.addAll(e2.messages);
47 public boolean isInternalError() {
51 public void format(PrintWriter out, Language language) {
52 out.println("<div class='formError'>");
53 if (isInternalError()) {
56 out.println(language.getTranslation("An internal error ouccured."));
57 out.println("</div>");
59 HashMap<String, Object> map = new HashMap<>();
60 for (Outputable message : messages) {
64 message.output(out, language, map);
65 out.println("</div>");
67 out.println("</div>");
71 public boolean isEmpty() {
72 return e == null && messages.size() == 0;
76 public String getMessage() {
77 if (messages.size() != 0) {
78 StringWriter sw = new StringWriter();
79 PrintWriter pw = new PrintWriter(sw);
81 HashMap<String, Object> map = new HashMap<>();
82 for (Outputable message : messages) {
84 message.output(pw, Language.getInstance(Locale.ENGLISH), map);