1 package com.teamkonzept.webman.mainint; 2 3 import java.text.MessageFormat ; 4 import java.util.*; 5 import java.sql.SQLException ; 6 import com.teamkonzept.lib.*; 7 import org.apache.log4j.Category; 8 import com.teamkonzept.db.*; 9 import com.teamkonzept.web.*; 10 import com.teamkonzept.webman.mainint.events.*; 11 import com.teamkonzept.international.*; 12 13 20 public class WebmanExceptionHandler 21 extends DefaultExceptionHandler 22 implements TKEventHandler, ErrorCodes 23 { 24 25 private static Category cat = Category.getInstance(WebmanExceptionHandler.class); 26 27 28 36 private static final String CONTEXT = "ErrorCodes"; 37 38 private static WebmanExceptionHandler instance = new WebmanExceptionHandler(); 39 40 private WebmanExceptionHandler() 41 { 42 LanguageManager.registerContext("/" + CONTEXT, this); 43 } 44 45 public static WebmanExceptionHandler getInstance() 46 { 47 return instance; 48 } 49 50 51 private static boolean developerMode = false; 52 53 56 public static boolean handleException(TKException e, TKEvent evt) 57 { 58 if (e != null) 59 { 60 int code = e.getErrorCode(); 61 try 62 { 63 int sev = e.getSeverity(); 64 Throwable t = e.getOriginalException(); 65 66 if (sev == HIGH_SEVERITY) 67 cat.fatal("caught HIGH_SEVERITY", t==null ? e:t); 68 else if (sev == NORMAL_SEVERITY) 69 cat.error("caught NORMAL", t==null ? e:t); 70 else if (sev == USER_SEVERITY) 71 cat.warn("caught USER", t==null ? e:t); 72 else if (sev == TEMPORARY_SEVERITY) 73 cat.warn("caught TEMPORARY", t==null ? e:t); 74 TKHTMLTemplate template = evt.getPrepHTMLTemplate( "error_message.tmpl" ); 75 String title; 76 if (e instanceof TKDatabaseException) 77 { 78 title = LanguageManager.getText(CONTEXT, "DatabaseError", null); 79 80 } 81 else if (e instanceof TKUserException) 82 { 83 title = LanguageManager.getText(CONTEXT, "UserError", null); 84 } 85 else if (e instanceof TKConfigurationException) 86 { 87 title = LanguageManager.getText(CONTEXT, "ConfigurationError", null); 88 } 89 else 90 { 91 title = LanguageManager.getText(CONTEXT, "InternalError", null); 92 } 93 template.set( "ERROR_TITLE", title); 94 template.set("ERROR_USER_TEXT", getErrorText(String.valueOf(code), e.getArguments())); 95 if (developerMode || e.isPublic()) 96 { 97 String text = e.getFullStackTrace(); 98 template.set( "ERROR_TEXT", text ); 99 } 100 else 101 { 102 template.set( "ERROR_TEXT", "" ); 104 } 105 evt.finishTemplate(template); 106 } catch ( Throwable th ) 107 { 108 cat.error("Fehler im EventHandler: " , th); 110 throw new Error ( th.getMessage() ); 111 } 112 return (code & DATABASE) > 0; 113 } 114 else 115 { 116 cat.error("Null Exception im ExceptionHandler !!!"); 117 return true; 118 } 119 } 120 121 122 public void handleEvent(TKEvent evt) throws TKException 123 { 124 String event = evt.getName(); 125 if (event.equalsIgnoreCase("TR_DEVELOPER")) 126 developerMode = true; 127 else if (event.equalsIgnoreCase("TR_USER")) 128 developerMode = false; 129 131 else 132 throw new TKException("Invalid Event: " + event, INVALID_EVENT, NORMAL_SEVERITY, false, null); 133 } 134 135 136 public boolean isHandler(TKEvent evt) 137 { 138 return evt.getName().startsWith("TR"); 139 } 140 141 144 public void addEventHandler(TKEventHandler handler) 145 { 146 } 147 148 151 public void removeEventHandler(TKEventHandler handler) 152 { 153 } 154 155 public static String getErrorText (String code, Object [] arguments) 156 { 157 return LanguageManager.getText(CONTEXT, code, arguments); 158 } 159 160 161 public void setHandleEvents(TKEvent[] events) 162 {} 163 164 165 166 public TKEvent[] getHandleEvents() 167 { 168 return null; 169 } 170 171 177 public TKEvent createEvent (TKHttpInterface http) 178 { 179 return null; 180 } 181 182 } 183
| Popular Tags
|