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

📄 lookuputil.java

📁 这是一个mvc模式
💻 JAVA
字号:
package jsp.tags.dapact.lookup;

import java.util.Hashtable;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.http.HttpServletRequest;
import jsp.tags.dapact.conf.UserClassFactory;
import jsp.tags.dapact.tags.data.RetrieveValueByNameInf;
/**
 * 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@
 */

/**
 * Utility class for functions useful in lookuping data in tags.
 */
public class LookupUtil
{
  /**
   * Default constructor.
   */
  private LookupUtil()
  {
  }

  /**
   * The separator for the data tag names.
   */
  public static final char DATA_TAG_NAME_SEP = ',';

  /**
   * Holds a class intance the retrieve value by name instance so that it can be looked up.
   */
  private static Class dataClass = null;
  static
  {
    try
    {
      dataClass = Class.forName("jsp.tags.dapact.tags.data.RetrieveValueByNameInf");
    }
    catch (ClassNotFoundException e)
    {
      // Catch this exception and log it and return null.
      UserClassFactory.getLogger().log("Unable to find the interface jsp.tags.dapact.tags.data.RetrieveValueByNameInf, please make sure that it is in your classpath.", e);
    }
  }

  /**
   * Search the tag hierarchy for data tags (optionally using the list of dataTagName(s)
   * supplied) trying to retrieve a value for the name.
   *
   * @param name the name to had to the data tags to see if there is a value.
   * @param dataTagName (optional) if it contains a value, it is a comma delimited
   *   list of names of data tags in the order that they will be searched. If no value
   *   is supplied, it will search all data tags until it retrieves a value or runs out
   *   of data tags.
   * @param tag the tag that will be used as the starting point for finding the data
   *   tags (which are parent tags to this one).
   *
   * @return a new value or null if not found.
   */
  public static Object findValueInDataTag(String name, String dataTagName, TagSupport tag)
  {
    Object result = null;
    if ((name != null) && (!name.trim().equals("")) && (tag != null))
    {
      Tag dataTag = tag;
      // To try to minimize what this function does, the first loop concentrates on looking
      // at all data tags, the second one looks by name.
      if ((dataTagName == null) || (dataTagName.trim().equals("")))
      {
        do
        {
          if (result == null)
          {
            dataTag = tag.findAncestorWithClass(dataTag, dataClass);
            if (dataTag != null)
            {
              RetrieveValueByNameInf data = (RetrieveValueByNameInf)dataTag;
              result = data.retrieveValueByName(tag, name);
            }
          }
        } while ((dataTag != null) && (result == null));
      }
      // Uses dataTagName to determine if it should ask the object for a value.
      else
      {
        Hashtable lookup = new Hashtable();
        int pos = -1;
        int lastpos = 0;
        do
        {
          // Find the name of the data tag to lookup.
          pos = dataTagName.indexOf(DATA_TAG_NAME_SEP, lastpos);
          String singleDataTagName = null;
          if (pos == -1)
          {
            if (lastpos > 0)
            {
              singleDataTagName = dataTagName.substring(lastpos).trim().toLowerCase();
            }
            else
            {
              singleDataTagName = dataTagName.trim().toLowerCase();
            }
          }
          else
          {
            singleDataTagName = dataTagName.substring(lastpos, pos).trim().toLowerCase();
          }
          if (result == null)
          {
            singleDataTagName = singleDataTagName.trim().toLowerCase();
            RetrieveValueByNameInf data = (RetrieveValueByNameInf)lookup.get(singleDataTagName);
            // If it did not find the data object and there are still data tags
            //  to search, look up the hierarchy for more and add them to the lookup.
            while ((data == null) && (dataTag != null))
            {
              dataTag = tag.findAncestorWithClass(dataTag, dataClass);
              if (dataTag != null)
              {
                RetrieveValueByNameInf tempData = (RetrieveValueByNameInf)dataTag;
                String lookupName = tempData.getName();
                if (lookupName != null)
                {
                  lookupName = lookupName.trim().toLowerCase();
                  lookup.put(lookupName, tempData);
                  if (lookupName.equals(singleDataTagName))
                  {
                    data = tempData;
                  }
                }
              }
            }

            // If it was able to find a data object, look for a value.
            if (data != null)
            {
              result = data.retrieveValueByName(tag, name);
            }
          }
          lastpos = pos+1;
        } while ((pos > -1) && (result == null));
      }
    }
    return result;
  }
}

⌨️ 快捷键说明

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