- SQLException e;
- String message;
-
- public GigiApiException(SQLException e) {
- this.e = e;
- }
-
- public GigiApiException(String message) {
- this.message = message;
- }
-
- public boolean isInternalError() {
- return e != null;
- }
-
- public void format(PrintWriter out, Language language) {
- if (isInternalError()) {
- e.printStackTrace();
- out.println(language.getTranslation("An internal error ouccured."));
- } else {
- out.println(language.getTranslation(message));
- }
-
- }
+
+ private SQLException e;
+
+ private LinkedList<String> messages = new LinkedList<>();
+
+ public GigiApiException(SQLException e) {
+ super(e);
+ this.e = e;
+ }
+
+ public GigiApiException(String message) {
+ super(message);
+ messages.add(message);
+ }
+
+ public GigiApiException() {
+
+ }
+
+ public void mergeInto(GigiApiException e2) {
+ messages.addAll(e2.messages);
+ if (e == null) {
+ e = e2.e;
+ }
+ }
+
+ public boolean isInternalError() {
+ return e != null;
+ }
+
+ public void format(PrintWriter out, Language language) {
+ out.println("<div class='formError'>");
+ if (isInternalError()) {
+ e.printStackTrace();
+ out.print("<div>");
+ out.println(language.getTranslation("An internal error ouccured."));
+ out.println("</div>");
+ }
+ for (String message : messages) {
+ out.print("<div>");
+ out.print(language.getTranslation(message));
+ out.println("</div>");
+ }
+ out.println("</div>");
+
+ }
+
+ public boolean isEmpty() {
+ return e == null && messages.size() == 0;
+ }
+
+ @Override
+ public String getMessage() {
+ if (messages.size() != 0) {
+ StringBuffer res = new StringBuffer();
+ for (String string : messages) {
+ res.append(string + "\n");
+ }
+ return res.toString();
+ }
+ return "";
+ }