If the application provides a message manager, use that to localize any
messages reported from a FriendlyException or from the exception map. git-svn-id: https://samskivert.googlecode.com/svn/trunk@89 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: DispatcherServlet.java,v 1.7 2001/03/04 06:15:39 mdb Exp $
|
// $Id: DispatcherServlet.java,v 1.8 2001/03/04 06:22:17 mdb Exp $
|
||||||
|
|
||||||
package com.samskivert.webmacro;
|
package com.samskivert.webmacro;
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ import org.webmacro.servlet.WMServlet;
|
|||||||
import org.webmacro.servlet.WebContext;
|
import org.webmacro.servlet.WebContext;
|
||||||
|
|
||||||
import com.samskivert.Log;
|
import com.samskivert.Log;
|
||||||
|
import com.samskivert.servlet.MessageManager;
|
||||||
import com.samskivert.servlet.RedirectException;
|
import com.samskivert.servlet.RedirectException;
|
||||||
import com.samskivert.util.ConfigUtil;
|
import com.samskivert.util.ConfigUtil;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
@@ -222,12 +223,14 @@ public class DispatcherServlet extends WMServlet
|
|||||||
// assume an HTML response unless otherwise massaged by the logic
|
// assume an HTML response unless otherwise massaged by the logic
|
||||||
ctx.getResponse().setContentType("text/html");
|
ctx.getResponse().setContentType("text/html");
|
||||||
|
|
||||||
// then we populate the context with data
|
// select the proper application for the request
|
||||||
try {
|
String path = cleanupURI(ctx.getRequest().getRequestURI());
|
||||||
String path = cleanupURI(ctx.getRequest().getRequestURI());
|
Application app = selectApplication(path);
|
||||||
|
String errmsg = null;
|
||||||
|
|
||||||
// select the proper application for the request
|
try {
|
||||||
Application app = selectApplication(path);
|
// if we don't have a matching app, we'll just execute the
|
||||||
|
// template as is without first invoking a logic object
|
||||||
if (app != null) {
|
if (app != null) {
|
||||||
// insert the application into the web context in case the
|
// insert the application into the web context in case the
|
||||||
// logic or a tool wishes to make use of it
|
// logic or a tool wishes to make use of it
|
||||||
@@ -250,13 +253,27 @@ public class DispatcherServlet extends WMServlet
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (FriendlyException fe) {
|
} catch (FriendlyException fe) {
|
||||||
ctx.put(ERROR_KEY, fe.getMessage());
|
// grab the error message, we'll deal with it shortly
|
||||||
|
errmsg = fe.getMessage();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ctx.put(ERROR_KEY, ExceptionMap.getMessage(e));
|
errmsg = ExceptionMap.getMessage(e);
|
||||||
Log.logStackTrace(e);
|
Log.logStackTrace(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have an error message, insert it into the template
|
||||||
|
if (errmsg != null) {
|
||||||
|
// if we have an application, try using it to localize the
|
||||||
|
// error message before we insert it
|
||||||
|
if (app != null) {
|
||||||
|
MessageManager msgmgr = app.getMessageManager();
|
||||||
|
if (msgmgr != null) {
|
||||||
|
errmsg = msgmgr.getMessage(ctx.getRequest(), errmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.put(ERROR_KEY, errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
return tmpl;
|
return tmpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user