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

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

  • 相关阅读:
    国外摄影网站
    网络基础之子网划分
    Java-多线程第三篇3种创建的线程方式、线程的生命周期、线程控制、线程同步、线程通信
    Java-多线程第二篇多线程相关认识(2)
    设计模式-第八篇之桥接模式
    设计模式-第七篇之门面模式
    设计模式-第六篇之策略模式
    设计模式-第五篇之命令模式
    设计模式-第四篇之代理模式
    设计模式-第九篇之观察者模式
  • 原文地址:https://www.cnblogs.com/shaohz2014/p/3698034.html
Copyright © 2011-2022 走看看