zoukankan      html  css  js  c++  java
  • Result实现类

    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;
    }

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

  • 相关阅读:
    谈谈关于MVP模式中V-P交互问题
    Delphi MVC模 2
    Delphi MVC模式 1
    Java长整除问题
    Java中Scanner类的简单用法
    Java中throw和throws的区别
    Java必须掌握的运算符
    Java编程多重循环
    Java实现三种简单的排序
    使用Java向properties存数据
  • 原文地址:https://www.cnblogs.com/shaohz2014/p/3698034.html
Copyright © 2011-2022 走看看