码迷,mamicode.com
首页 > 其他好文 > 详细

Result实现类

时间:2014-04-29 18:55:17      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:com   http   class   blog   style   div   img   code   java   javascript   ext   

mamicode.com,码迷
package org.apache.struts2.dispatcher;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.TextParseUtil.ParsedValueEvaluator;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.apache.struts2.StrutsStatics;

public abstract class StrutsResultSupport
  implements Result, StrutsStatics
{
  private static final Logger LOG = LoggerFactory.getLogger(StrutsResultSupport.class);
  public static final String DEFAULT_PARAM = "location";
  private boolean parse;
  private boolean encode;
  private String location;
  private String lastFinalLocation;

  public StrutsResultSupport()
  {
    this(null, true, false);
  }

  public StrutsResultSupport(String location) {
    this(location, true, false);
  }

  public StrutsResultSupport(String location, boolean parse, boolean encode) {
    this.location = location;
    this.parse = parse;
    this.encode = encode;
  }

  public void setLocation(String location)
  {
    this.location = location;
  }

  public String getLocation()
  {
    return this.location;
  }

  public String getLastFinalLocation()
  {
    return this.lastFinalLocation;
  }

  public void setParse(boolean parse)
  {
    this.parse = parse;
  }

  public void setEncode(boolean encode)
  {
    this.encode = encode;
  }

  public void execute(ActionInvocation invocation)
    throws Exception
  {
    this.lastFinalLocation = conditionalParse(this.location, invocation);
    doExecute(this.lastFinalLocation, invocation);
  }

  protected String conditionalParse(String param, ActionInvocation invocation)
  {
    if ((this.parse) && (param != null) && (invocation != null)) {
      return TextParseUtil.translateVariables(param, invocation.getStack(), new TextParseUtil.ParsedValueEvaluator()
      {
        public Object evaluate(String parsedValue) {
          if ((StrutsResultSupport.this.encode) && 
            (parsedValue != null))
          {
            try
            {
              return URLEncoder.encode(parsedValue, "UTF-8");
            }
            catch (UnsupportedEncodingException e) {
              if (StrutsResultSupport.LOG.isWarnEnabled()) {
                StrutsResultSupport.LOG.warn("error while trying to encode [" + parsedValue + "]", e, new String[0]);
              }
            }
          }

          return parsedValue;
        }
      });
    }
    return param;
  }

  protected abstract void doExecute(String paramString, ActionInvocation paramActionInvocation)
    throws Exception;
}
mamicode.com,码迷

**********************************************************

 

Result实现类,码迷,mamicode.com

Result实现类

标签:com   http   class   blog   style   div   img   code   java   javascript   ext   

原文地址:http://www.cnblogs.com/shaohz2014/p/3698034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!