⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logginginterceptor.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
字号:
/* * Copyright (c) 2002-2006 by OpenSymphony * All rights reserved. */package com.opensymphony.xwork2.interceptor;import com.opensymphony.xwork2.ActionInvocation;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * <!-- START SNIPPET: description --> * This interceptor logs the the start and end of the execution an action (in English-only, not internationalized). * <!-- END SNIPPET: description --> * * <!-- START SNIPPET: parameters --> * There are no parameters for this interceptor. * <!-- END SNIPPET: parameters --> * * <!-- START SNIPPET: extending --> * There are no obvious extensions to the existing interceptor. * <!-- END SNIPPET: extending --> * * <pre> * <!-- START SNIPPET: example --> * &lt;!-- prints out a message before and after the immediate action execution --&gt; * &lt;action name="someAction" class="com.examples.SomeAction"&gt; *     &lt;interceptor-ref name="completeStack"/&gt; *     &lt;interceptor-ref name="logger"/&gt; *     &lt;result name="success"&gt;good_result.ftl&lt;/result&gt; * &lt;/action&gt; * * &lt;!-- prints out a message before any more interceptors continue and after they have finished --&gt; * &lt;action name="someAction" class="com.examples.SomeAction"&gt; *     &lt;interceptor-ref name="logger"/&gt; *     &lt;interceptor-ref name="completeStack"/&gt; *     &lt;result name="success"&gt;good_result.ftl&lt;/result&gt; * &lt;/action&gt; * <!-- END SNIPPET: example --> * </pre> * * @author Jason Carreira */public class LoggingInterceptor extends AbstractInterceptor {    private static final Log log = LogFactory.getLog(LoggingInterceptor.class);    private static final String FINISH_MESSAGE = "Finishing execution stack for action ";    private static final String START_MESSAGE = "Starting execution stack for action ";    public String intercept(ActionInvocation invocation) throws Exception {        logMessage(invocation, FINISH_MESSAGE);        String result = invocation.invoke();        logMessage(invocation, START_MESSAGE);        return result;    }    private void logMessage(ActionInvocation invocation, String baseMessage) {        if (log.isInfoEnabled()) {            StringBuffer message = new StringBuffer(baseMessage);            String namespace = invocation.getProxy().getNamespace();            if ((namespace != null) && (namespace.trim().length() > 0)) {                message.append(namespace).append("/");            }            message.append(invocation.getProxy().getActionName());            log.info(message.toString());        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -