锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品亚洲产品,色影视在线视频资源站,久色视频在线http://www.aygfsteel.com/frogfool/category/17595.html鍏冩ā鍨嬩嬌鑳?/description>zh-cnTue, 27 Feb 2007 20:20:58 GMTTue, 27 Feb 2007 20:20:58 GMT60ExceptionInterceptorhttp://www.aygfsteel.com/frogfool/archive/2006/11/22/82912.htmlfrogfoolfrogfoolWed, 22 Nov 2006 14:57:00 GMThttp://www.aygfsteel.com/frogfool/archive/2006/11/22/82912.htmlhttp://www.aygfsteel.com/frogfool/comments/82912.htmlhttp://www.aygfsteel.com/frogfool/archive/2006/11/22/82912.html#Feedback0http://www.aygfsteel.com/frogfool/comments/commentRss/82912.htmlhttp://www.aygfsteel.com/frogfool/services/trackbacks/82912.htmlpackage com.gxlu.common.web.webwork.intercepter;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gxlu.common.web.webwork.action.AjaxJSONAction;
import com.gxlu.common.web.webwork.action.AjaxUpdaterAction;
import com.gxlu.common.web.webwork.action.AjaxXMLAction;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;

/**
聽* Interceptor to handle Exceptions thrown by Actions.
聽* <p>
聽* <a href="ExceptionHandlerInterceptor.java.html"> <i>View Source </i> </a>
聽* </p>
聽*聽
聽*/
public class ExceptionInterceptor implements Interceptor {
聽public static final String EXCEPTION = "exception";

聽protected final Log logger = LogFactory.getLog(getClass());

聽private Map exceptionMappings;

聽/**
聽 * Set the mappings between exception class names and result names.
聽 *
聽 * @param mappings
聽 *聽聽聽聽聽聽聽 fully qualified exception class names as keys, and result names as
聽 *聽聽聽聽聽聽聽 values
聽 */
聽public void setExceptionMappings(Properties mappings) throws ClassNotFoundException {
聽聽this.exceptionMappings = new HashMap();

聽聽for (Iterator it = mappings.keySet().iterator(); it.hasNext();) {
聽聽聽String exceptionClassName = (String) it.next();
聽聽聽String viewName = mappings.getProperty(exceptionClassName);
聽聽聽Class exceptionClass = Class.forName(exceptionClassName, true, Thread.currentThread().getContextClassLoader());
聽聽聽this.exceptionMappings.put(exceptionClass, viewName);
聽聽}
聽}

聽/**
聽 * Invoke action and if an exception occurs, route it to the mapped result.
聽 */
聽public String intercept(ActionInvocation invocation) throws Exception {
聽聽String result = null;

聽聽try {
聽聽聽result = invocation.invoke();
聽聽} catch (Throwable e) {
聽聽聽logger.error(e);
聽聽聽//
聽聽聽result = EXCEPTION;
聽聽聽//
聽聽聽StringWriter writer = new StringWriter();
聽聽聽e.printStackTrace(new java.io.PrintWriter(writer));
聽聽聽ServletActionContext.getRequest().setAttribute("_exception_stack_trace_", writer.toString());
聽聽聽ServletActionContext.getRequest().setAttribute("_exception_message_", e.getMessage());
聽聽聽writer = null;
聽聽聽Action action = invocation.getAction();
聽聽聽if(action instanceof AjaxJSONAction) {聽聽聽聽
聽聽聽聽return "exception.json";
聽聽聽} else if(action instanceof AjaxXMLAction) {
聽聽聽聽return "exception.xml";
聽聽聽} else if(action instanceof AjaxUpdaterAction) {
聽聽聽聽return "exception.updater";
聽聽聽}
聽聽聽/**
聽聽聽 * // check for specific mappings if (this.exceptionMappings !=
聽聽聽 * null) { for (Iterator it =
聽聽聽 * this.exceptionMappings.keySet().iterator(); it.hasNext();) {
聽聽聽 * Class exceptionClass = (Class) it.next(); if
聽聽聽 * (exceptionClass.isInstance(ex)) { result = (String)
聽聽聽 * this.exceptionMappings.get(exceptionClass); } } } if (null ==
聽聽聽 * result || "".equals(result)) { result = EXCEPTION; }
聽聽聽 */
聽聽}
聽聽return result;

聽}

聽public void destroy() {
聽}

聽public void init() {
聽}
}



frogfool 2006-11-22 22:57 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 山东省| 永泰县| 墨脱县| 冕宁县| 罗甸县| 旌德县| 临沧市| 新疆| 元阳县| 嘉荫县| 阳信县| 天水市| 磴口县| 霞浦县| 焦作市| 婺源县| 蒙城县| 玉环县| 安吉县| 大同市| 洛宁县| 明水县| 兴海县| 仪陇县| 宿松县| 哈巴河县| 志丹县| 蓬莱市| 霸州市| 弥勒县| 玉龙| 崇仁县| 射洪县| 阿鲁科尔沁旗| 河津市| 安丘市| 通许县| 方城县| 弋阳县| 于都县| 清丰县|