Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java =================================================================== diff -u -r3eea4539311588af3053d362058f2eb01c4f9887 -rdb44d0ba01e0426868d12ed9f59075d841251e4d --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java (.../NoticeboardConstants.java) (revision 3eea4539311588af3053d362058f2eb01c4f9887) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/NoticeboardConstants.java (.../NoticeboardConstants.java) (revision db44d0ba01e0426868d12ed9f59075d841251e4d) @@ -128,4 +128,6 @@ public static final String ERROR_NBAPPLICATION = "error.exception.NbApplication"; + public static final String ERR_MISSING_PARAM = "error.missingParam"; + } Index: lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/CustomStrutsExceptionHandler.java =================================================================== diff -u --- lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/CustomStrutsExceptionHandler.java (revision 0) +++ lams_tool_nb/src/java/org/lamsfoundation/lams/tool/noticeboard/web/CustomStrutsExceptionHandler.java (revision db44d0ba01e0426868d12ed9f59075d841251e4d) @@ -0,0 +1,94 @@ +/* + Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + + http://www.gnu.org/licenses/gpl.txt +*/ + +package org.lamsfoundation.lams.tool.noticeboard.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionMessage; +import org.apache.struts.action.ExceptionHandler; +import org.apache.struts.config.ExceptionConfig; +import org.lamsfoundation.lams.tool.noticeboard.NbApplicationException; +import org.lamsfoundation.lams.tool.noticeboard.NoticeboardConstants; + +/** + * Copied from Jacky's class in the survey tool. + */ +public class CustomStrutsExceptionHandler extends ExceptionHandler { + + //--------------------------------------------------------------------- + // Instance Data + //--------------------------------------------------------------------- + private static Logger logger = Logger.getLogger(CustomStrutsExceptionHandler.class); + + // commons logging reference + /** + * Handle the exception. Standard execute method with addition of logging + * the stacktrace. + */ + public ActionForward execute(Exception ex, + ExceptionConfig ae, + ActionMapping mapping, + ActionForm formInstance, + HttpServletRequest request, + HttpServletResponse response) + { + // write the exception information to the log file + logger.error("fatal System exception: [" + ex.getMessage() + "] ", ex); + ActionForward forward = null; + String property = null; + + /* + * Get the path for the forward either from the exception element or + * from the input attribute. + */ + + String path = null; + if (ae.getPath() != null) + { + path = ae.getPath(); + } + else + { + path = mapping.getInput(); + } + // Construct the forward object + forward = new ActionForward(path); + + // some exceptions do have null messages, so be careful! + String exceptionMessage = ex.getMessage(); + String errorMessage = exceptionMessage == null || exceptionMessage.equals("null") ? ex.getClass().getName() : ex.getMessage(); + ActionMessage error = null; + if (NbApplicationException.class.isInstance(ex) ) { + error = new ActionMessage(NoticeboardConstants.ERROR_NBAPPLICATION, errorMessage ); + } + storeException(request, property, error, forward, ae.getScope( )); + // process the exception as normal + return forward; + + + } +}