01: /*
02: * Enhydra Java Application Server Project The contents of this file are subject to the
03: * Enhydra Public License Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License on the Enhydra web
05: * site ( http://www.enhydra.org/ ). Software distributed under the License is distributed
06: * on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
07: * License for the specific terms governing rights and limitations under the License. The
08: * Initial Developer of the Enhydra Application Server is Lutris Technologies, Inc. The
09: * Enhydra Application Server and portions created by Lutris Technologies, Inc. are
10: * Copyright Lutris Technologies, Inc. All Rights Reserved. Contributor(s): $Id:
11: * ErrorHandler.java,v 1.1 2006/09/04 09:07:38 alex Exp $
12: */
13:
14: package org.enhydra.dm.presentation;
15:
16: import java.io.PrintWriter;
17: import java.io.StringWriter;
18:
19: import org.enhydra.dm.api.exceptions.BaseException;
20: import org.enhydra.dm.business.exceptions.ActionNotAllowedException;
21: import org.enhydra.dm.business.exceptions.ConfigurationException;
22: import org.enhydra.dm.business.exceptions.DatabaseException;
23: import org.enhydra.dm.business.exceptions.DesEncryptionException;
24: import org.enhydra.dm.business.exceptions.DocumentStoreException;
25: import org.enhydra.dm.business.exceptions.LockException;
26:
27: import com.lutris.appserver.server.httpPresentation.*;
28:
29: /**
30: * Trivial error handler.
31: */
32: public class ErrorHandler implements HttpPresentation {
33: ErrorHandlerHTML page;
34:
35: /**
36: * Entry.
37: */
38: public void run(HttpPresentationComms comms)
39: throws HttpPresentationException {
40: page = (ErrorHandlerHTML) comms.xmlcFactory
41: .create(ErrorHandlerHTML.class);
42:
43: if (null != comms.exception) {
44: if (comms.exception.getCause() instanceof BaseException) {
45: BaseException busEx = (BaseException) comms.exception
46: .getCause();
47: if (busEx instanceof LockException
48: || busEx.getCause() instanceof LockException) {
49: setErrorMessageTypeColor("red", LockException.class
50: .getName());
51: } else if (busEx instanceof DatabaseException
52: || busEx.getCause() instanceof DatabaseException) {
53: setErrorMessageTypeColor("blue",
54: DatabaseException.class.getName());
55: } else if (busEx instanceof DocumentStoreException
56: || busEx.getCause() instanceof DocumentStoreException) {
57: setErrorMessageTypeColor("green",
58: DocumentStoreException.class.getName());
59: } else if (busEx instanceof DesEncryptionException
60: || busEx.getCause() instanceof DesEncryptionException) {
61: setErrorMessageTypeColor("orange",
62: DesEncryptionException.class.getName());
63: } else if (busEx instanceof ActionNotAllowedException
64: || busEx.getCause() instanceof ActionNotAllowedException) {
65: setErrorMessageTypeColor("brown",
66: ActionNotAllowedException.class.getName());
67: } else if (busEx instanceof ConfigurationException
68: || busEx.getCause() instanceof ConfigurationException) {
69: setErrorMessageTypeColor("darkblue",
70: ConfigurationException.class.getName());
71: }
72: }
73: StringWriter stringWriter = new StringWriter();
74: comms.exception.printStackTrace();
75: comms.exception.printStackTrace(new PrintWriter(
76: stringWriter));
77:
78: page.setTextStackTrace(stringWriter.toString());
79: String m = comms.exception.getMessage();
80: if (null == m)
81: m = "NULL message";
82: page.setTextErrorMessage(m);
83: }
84: comms.response.writeDOM(page);
85: }
86:
87: private void setErrorMessageTypeColor(String color, String type) {
88: page.getElementErrorMessageFont().setColor(color);
89: page.getElementStackTraceFont().setColor(color);
90:
91: }
92: }
|