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

📄 baseparamreplacelookup.java

📁 这是一个mvc模式
💻 JAVA
字号:
package jsp.tags.dapact.lookup;
/**
 * Title:        Data Aware Processing And Control Tags
 * Description:  Tag library for the processing and controlling the input and output of data.
 * Copyright:    LGPL (http://www.gnu.org/copyleft/lesser.html)
 * Compile Date: @compile_date@
 * @author Allen M Servedio
 * @amp_sign@version @VERSION@
 */

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * Base class for lookups that want to do parameter replacement - it parses the value
 * looking for parameters and calls {@link #replaceParam(String, String, TagSupport, PageContext)}
 * to do the actual replacement.
 */
public abstract class BaseParamReplaceLookup extends BaseLookupValue
{
  /**
   * Default constructor...
   */
  public BaseParamReplaceLookup()
  {
  }

  /**
   * This function will be called by the tags when they want to store a general
   * non-String object. It just returns the value since this class only does parameter
   * replacement on strings.
   *
   * @param key the key of the value to be saved.
   * @param value the value to be added - this will be overridden by what is returned by
   *   this function.
   * @param tag the tag that will be used to save the value.
   * @param pc the page context associated with the tag that is also a parameter. This
   *   will be used to search parameters and contexts (page, session, request, and servlet).
   *
   * @return the lookuped value.
   */
  public Object lookupValue(String key, Object value, TagSupport tag, PageContext pc)
  {
    return value;
  }

  /**
   * This function will be called by the tags when they want to store a string object
   * (most common case: storing attributes). It will process the string replacing parameters
   * with their values from the request.
   *
   * @param key the key of the value to be saved.
   * @param value the value to be added - this will be overridden by what is returned by
   *   this function.
   * @param tag the tag that will be used to save the value.
   * @param pc the page context associated with the tag that is also a parameter. This
   *   will be used to search parameters and contexts (page, session, request, and servlet).
   *
   * @return the lookedup value.
   */
  public String lookupValue(String key, String value, TagSupport tag, PageContext pc)
  {
    if (value != null)
    {
      int valLen = value.length();
      StringBuffer buff = new StringBuffer(valLen);
      String paramSep = getParamSep();
      int len = paramSep.length();
      int pos = -1;
      int lastpos = 0;
      int firstSepPos = -1;
      boolean firstSep = false;
      // Spin through the value looking for parameters and replacing them.
      while ((pos = value.indexOf(paramSep, lastpos)) > -1)
      {
        if (!firstSep)
        {
          firstSepPos = pos;
          firstSep = true;
          buff.append(value.substring(lastpos, pos));
        }
        else
        {
          firstSep = false;
          String paramName = value.substring(firstSepPos+len, pos);
          String paramVal = replaceParam(key, paramName, tag, pc);
          if (paramVal != null)
          {
            buff.append(paramVal);
          }
        }

        lastpos = pos+len;
      }

      // Add the last part of the value to the buffer.
      if (lastpos < valLen)
      {
        if (firstSep)
        {
          lastpos -= len;
        }
        if (lastpos > 0)
        {
          buff.append(value.substring(lastpos));
        }
      }

      // If at least one parameter was found, return the buffer.
      if (lastpos > 0)
      {
        value = buff.toString();
      }
    }
    // Else, return the value unchanged.
    return value;
  }

  /**
   * Replace the parameter named with a value from the tag or page context. In this
   * function, it is replaced by looking for a similarily named parameter.
   *
   * @param key the key of the value to be saved.
   * @param name the name of the parameter to replace.
   * @param tag the tag that will be used to save the value.
   * @param pc the page context associated with the tag that is also a parameter. This
   *   will be used to search parameters and contexts (page, session, request, and servlet).
   *
   * @return a new value or null if not found.
   */
  abstract protected String replaceParam(String key, String name, TagSupport tag, PageContext pc);

  /**
   * Retrieves the parameter seperator.
   */
  protected String getParamSep()
  {
    return PARAM_SEP_CONST;
  }

  /**
   * The parameter seperator.
   */
  private static final String PARAM_SEP_CONST = "#";
}

⌨️ 快捷键说明

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