// tool wishes to make use of it
ictx.put(APPLICATION_KEY, _app);
// if the application provides a message manager, we want create a
// translation tool and stuff that into the context
MessageManager msgmgr = _app.getMessageManager();
if (msgmgr != null) {
I18nTool i18n = new I18nTool(req, msgmgr);
ictx.put(I18NTOOL_KEY, i18n);
}
// create a form tool for use by the template
FormTool form = new FormTool(req);
ictx.put(FORMTOOL_KEY, form);
// create a new string tool for use by the template
StringTool string = new StringTool();
ictx.put(STRINGTOOL_KEY, string);
// create a new data tool for use by the tempate
DataTool datatool = new DataTool();
ictx.put(DATATOOL_KEY, datatool);
// create a curreny tool set up to use the correct locale
CurrencyTool ctool = new CurrencyTool(req.getLocale());
ictx.put(CURRENCYTOOL_KEY, ctool);
// allow the application to prepare the context
_app.prepareContext(ictx);
// allow the application to do global access control
_app.checkAccess(ictx);
// resolve the appropriate logic class for this URI and execute it
// if it exists
String path = req.getServletPath();
logic = resolveLogic(path);
if (logic != null) {
logic.invoke(_app, ictx);
}
} catch (Exception e) {
error = e;
}
// if an error occurred processing the template, allow the application
// to convert it to something more appropriate and then handle it
String errmsg = null;
try {
if (error != null) {
throw _app.translateException(error);
}
} catch (RedirectException re) {
rsp.sendRedirect(re.getRedirectURL());
return null;
} catch (HttpErrorException hee) {
String msg = hee.getErrorMessage();
if (msg != null) {
rsp.sendError(hee.getErrorCode(), msg);
} else {
rsp.sendError(hee.getErrorCode());
}
return null;
} catch (FriendlyException fe) {
// grab the error message, we'll deal with it shortly
errmsg = fe.getMessage();
} catch (Exception e) {
errmsg = _app.handleException(req, logic, e);
}
// if we have an error message, insert it into the template
if (errmsg != null) {
// try using the application to localize the error message
// before we insert it
MessageManager msgmgr = _app.getMessageManager();
if (msgmgr != null) {
errmsg = msgmgr.getMessage(req, errmsg);
}
ictx.put(ERROR_KEY, errmsg);
}
return tmpl;