package com.opensymphony.xwork2;

import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.RuntimeConfiguration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
import java.io.Serializable;
import java.util.Locale;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils; public class DefaultActionProxy
implements ActionProxy, Serializable
{
private static final long serialVersionUID = 3293074152487468527L;
private static final Logger LOG = LoggerFactory.getLogger(DefaultActionProxy.class);
protected Configuration configuration;
protected ActionConfig config;
protected ActionInvocation invocation;
protected UnknownHandlerManager unknownHandlerManager;
protected String actionName;
protected String namespace;
protected String method;
protected boolean executeResult;
protected boolean cleanupContext;
protected ObjectFactory objectFactory;
protected ActionEventListener actionEventListener;
private boolean methodSpecified = true; protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext)
{
this.invocation = inv;
this.cleanupContext = cleanupContext;
if (LOG.isDebugEnabled()) {
LOG.debug("Creating an DefaultActionProxy for namespace [#0] and action name [#1]", new String[] { namespace, actionName });
} this.actionName = StringEscapeUtils.escapeHtml4(actionName);
this.namespace = namespace;
this.executeResult = executeResult;
this.method = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(methodName));
} @Inject
public void setObjectFactory(ObjectFactory factory) {
this.objectFactory = factory;
} @Inject
public void setConfiguration(Configuration config) {
this.configuration = config;
} @Inject
public void setUnknownHandler(UnknownHandlerManager unknownHandlerManager) {
this.unknownHandlerManager = unknownHandlerManager;
} @Inject(required=false)
public void setActionEventListener(ActionEventListener listener) {
this.actionEventListener = listener;
} public Object getAction() {
return this.invocation.getAction();
} public String getActionName() {
return this.actionName;
} public ActionConfig getConfig() {
return this.config;
} public void setExecuteResult(boolean executeResult) {
this.executeResult = executeResult;
} public boolean getExecuteResult() {
return this.executeResult;
} public ActionInvocation getInvocation() {
return this.invocation;
} public String getNamespace() {
return this.namespace;
} public String execute() throws Exception {
ActionContext nestedContext = ActionContext.getContext();
ActionContext.setContext(this.invocation.getInvocationContext()); String retCode = null; String profileKey = "execute: ";
try {
UtilTimerStack.push(profileKey); retCode = this.invocation.invoke();
} finally {
if (this.cleanupContext) {
ActionContext.setContext(nestedContext);
}
UtilTimerStack.pop(profileKey);
} return retCode;
} public String getMethod()
{
return this.method;
} private void resolveMethod()
{
if (StringUtils.isEmpty(this.method)) {
this.method = this.config.getMethodName();
if (StringUtils.isEmpty(this.method)) {
this.method = "execute";
}
this.methodSpecified = false;
}
} protected void prepare() {
String profileKey = "create DefaultActionProxy: ";
try {
UtilTimerStack.push(profileKey);
this.config = this.configuration.getRuntimeConfiguration().getActionConfig(this.namespace, this.actionName); if ((this.config == null) && (this.unknownHandlerManager.hasUnknownHandlers())) {
this.config = this.unknownHandlerManager.handleUnknownAction(this.namespace, this.actionName);
}
if (this.config == null) {
throw new ConfigurationException(getErrorMessage());
} resolveMethod(); if (!this.config.isAllowedMethod(this.method)) {
throw new ConfigurationException("Invalid method: " + this.method + " for action " + this.actionName);
} this.invocation.init(this);
}
finally {
UtilTimerStack.pop(profileKey);
}
} protected String getErrorMessage() {
if ((this.namespace != null) && (this.namespace.trim().length() > 0)) {
return LocalizedTextUtil.findDefaultText("xwork.exception.missing-package-action", Locale.getDefault(), new String[] { this.namespace, this.actionName });
} return LocalizedTextUtil.findDefaultText("xwork.exception.missing-action", Locale.getDefault(), new String[] { this.actionName });
} public boolean isMethodSpecified()
{
return this.methodSpecified;
}
}

******************************************分割线**********************************

package org.apache.struts2.impl;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.DefaultActionProxy;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext; public class StrutsActionProxy extends DefaultActionProxy
{
private static final long serialVersionUID = -2434901249671934080L; public StrutsActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext)
{
super(inv, namespace, actionName, methodName, executeResult, cleanupContext);
} public String execute() throws Exception {
ActionContext previous = ActionContext.getContext();
ActionContext.setContext(this.invocation.getInvocationContext());
try
{
return this.invocation.invoke();
} finally {
if (this.cleanupContext)
ActionContext.setContext(previous);
}
} protected void prepare()
{
super.prepare();
} protected String getErrorMessage()
{
if ((this.namespace != null) && (this.namespace.trim().length() > 0)) {
String contextPath = ServletActionContext.getRequest().getContextPath();
return LocalizedTextUtil.findDefaultText("struts.exception.missing-package-action.with-context", Locale.getDefault(), new String[] { this.namespace, this.actionName, contextPath });
} return super.getErrorMessage();
}
}

ActionProxy相关实现类的更多相关文章

  1. Hibernate 系列 04 - Hibernate 配置相关的类

    引导目录: Hibernate 系列教程 目录 前言: 通过上一篇的增删改查小练习之后,咱们大概已经掌握了Hibernate的基本用法. 我们发现,在调用Hibernate API的过程中,虽然Hib ...

  2. SWIFT 通过字符串创建相关的类

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  3. 模拟在内存中的数据库DataSet相关的类

    这篇连着上一篇DataReader相关类. 下面两段话是在msdn官网摘下来:       .NET Framework 数据提供程序是专门为数据操作以及快速.只进.只读访问数据而设计的组件.Conn ...

  4. android中与SQLite数据库相关的类

    为什么要在应用程序中使用数据库?数据库最主要的用途就是作为数据的存储容器,另外,由于可以很方便的将应用程序中的数据结构(比如C语言中的结构体)转化成数据库的表,这样我们就可以通过操作数据库来替代写一堆 ...

  5. bootstrap 强调相关的类

    .text-muted:提示,使用浅灰色(#999) .text-primary:主要,使用蓝色(#428bca) .text-success:成功,使用浅绿色(#3c763d) .text-info ...

  6. (1)StringBuilder类和StringBuffer类 (2)日期相关的类 (3)集合框架 (4)List集合

    1.StringBuilder类和StringBuffer类(查手册会用即可)1.1 基本概念 由于String类描述的字符串内容无法更改,若程序中出现大量类似的字符串时需要申请独立的内存空间单独保存 ...

  7. Android界面相关的类

    Android界面相关的类 Window Activity的显示界面对象,并作为顶层View被加入到WindowManager中.Window提供了标准的UI显示策略:界面背景.标题区域.默认的事件处 ...

  8. Java工具类——日期相关的类

    前言 在日常的开发工作当中,我们经常需要用到日期相关的类(包括日期类已经处理日期的类),所以,我就专门整理了一篇关于日期相关的类,希望可以帮助到大家. 正文 一.日期类介绍 在 Java 里面,操作日 ...

  9. Java工具类——数学相关的类

    Java工具类--数学相关的类 在上一篇文章中,我们系统学习了 Java 里面的包装类,那么这篇文章,我们就来学习一下Java提供好的类--数学相关的类. 一.数学类介绍 在最早期学习 Java 基础 ...

随机推荐

  1. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第七天(非原创)

    文章大纲 一.课程介绍二.Redis基础实战三.Redis之高可用.集群.云平台搭建实战四.淘淘商城Jedis整合spring五.项目源码与资料下载六.参考文章   一.课程介绍 一共14天课程(1) ...

  2. var声明提前 undefined

    1.同一代码块内,所有var声明都提前: 2.var 变量的初始化不提前,按顺序执行: 3."undefined"和undefined都存在于window中: 4.if(" ...

  3. CSS3 基本要素概览

    这篇文章将对 CSS 的几个新属性 (text-shadow,box-shadow,and border-radius) 做基本介绍.这些 CSS3 属性通常用来加强页面布局.  RGBA  前面的 ...

  4. arcgis jsapi接口入门系列(5):几何(点线面)基本操作

    点 point: function () { //通过wkt生成点 //wkt,代表点的坐标 let wkt = "POINT(113.566806 22.22445)"; //w ...

  5. 学习笔记——Paint 1(MaskFilter)

    对于Paint没有很好的深入的学习过,在工作之余再巩固巩固. 1.Paint的BlurMaskFilter(模糊效果) 自定义一个View继承View 重写里面的onDraw方法.这里直接上代码了: ...

  6. linux下phpstudy的搭建以及网站的搭建

    step1: 下载SSH连接到IP地址(阿里云上购买的) step2: 安装下载phpstudywget -c http://lamp.phpstudy.net/phpstudy.bin chmod ...

  7. 新萝卜家园GHOST WIN7系统3专业装机版

    系统来自系统妈:http://www.xitongma.com/ 系统概述 萝卜家园GHOST win7 64位装机旗舰版加快“网上邻居”共享速度:取消不需要的网络服务组件,系统支持Windows安装 ...

  8. HTML5与PHP的比较

    一:需求量比较 知名招聘网站拉勾网显示,北京地区HTML5的需求量只有73个,而PHP的需求量有500+个:智联招聘网显示,北京上海广州深圳HTML5的需求量是7475个,而PHP的需求量是12514 ...

  9. 人人必知的10个 jQuery 小技巧

    原文地址:http://info.9iphp.com/10-jquery-tips-everyone-should-know/ 人人必知的10个 jQuery 小技巧   收集的10个 jQuery ...

  10. Ubuntu 18.04 上使用 OpenJDK 安装并运行 Tomcat

    在Linux上安装与卸载JDK和JRE,两种常用方法: 一.通过 apt-get 命令在线进行安装与卸载(会自动配置好环境变量) 二.通过下载并解压 .tar.gz 包进行手动安装与手动卸载(需要手动 ...