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

📄 browsercontext.java

📁 一个用 java写的wap浏览器 对于浏览器感兴趣起的可以看看咯
💻 JAVA
字号:
/*
 * j2wap is distributed under the terms of the GNU Public License
 *
 *  j2wap was written by:
 *
 *	        Scott Campbell
 *			Michael Nordling
 *			Karl Maftoum
 * 			Julian Bright
 *
 *			This was a final project for Comp.Engineering at the University of Canberra, Australia
 *
 *			Now released as Open Source software. 28 November 2000
 *
 *			Email: k_maftoum@hotmail.com for more info
 *
 */


package wae;
import java.util.*;


/**
 * Browser context is a Container for history and variable.<br>
 * @com     j2wap.com
 * @author  Julian Bright
 * @version 1.1
 */
public class BrowserContext
{
  /** Hashtable to store variables */
  private Hashtable c_htbVariable;
  /** Stack to hold history URLs */
  private Stack c_stkHistory;

  /**
   * Initialises the Browser context variable and history stacks.
   */
  public BrowserContext()
  {
    c_htbVariable = new Hashtable(10);
    c_stkHistory = new Stack();
  }

  /**
   * Pushes a card url onto the history stack.
   * @param URL The URL of the card to push onto stack
   */
   public void pushCard(String in_strURL)
  {
    c_stkHistory.push(new String(in_strURL));
  }

  /**
   * Pops the last URL off the history stack.
   * @return String URL of top card on stack.
   */
  public String popCard()
  {
    if (c_stkHistory.isEmpty())
      return "";
    else
      return (String)c_stkHistory.pop();
  }

  /**
   * Gets a variable according its name.
   * @return Variable Value for associated name.
   */
  public String getVariable(String in_strVariableName)
  {
    if (c_htbVariable.isEmpty())
      return "";
    else
      return (String)c_htbVariable.get(in_strVariableName);
  }

  /**
   * Adds a variable Name and value to the browser context.
   * @param in_strVariableName The name of the new variable.
   * @param in_strVariableValue The value associated with the name.
   */
  public void setVariable(String in_strVariableName, String in_strVariableValue)
  {
    c_htbVariable.put(in_strVariableName, new String(in_strVariableValue));
  }

  /**
   * Clear the varbles and history.
   */
  public void resetBrowserContext ()
  {
    // Clear the variables.
    if (!c_htbVariable.isEmpty())
      c_htbVariable.clear();

    // Clear the history.
    while (!c_stkHistory.empty())
      c_stkHistory.pop();
  }

  /**
   * Clear all variables in the variable hashtable.
   */
  public void clearVariables ()
  {
     if (!c_htbVariable.isEmpty())
      c_htbVariable.clear();
  }

  /**
   * Scan through a string looking for and resolving variable references. A new
   * string is returned containing the input string with all variable references
   * resolved.
   * A variable reference appears between two '$' characters.
   * @param in_string The string to be scaned for references.
   */
   public String subVars (String in_str)
   {
      boolean bolFoundVar = false;
      int intLen = in_str.length();
      int intVarStart = 0;
      int intVarEnd;
      int intStartSeg = 0;
      StringBuffer out_clsSBuf = new StringBuffer ();

      // Look for all instances of '$'...'$' and resolve variable reference.
      intVarStart = in_str.indexOf('$');
      while (intVarStart > -1 && intVarStart < intLen)
      {
        if (intVarStart > -1)
        {
          bolFoundVar = true;
          intVarEnd = in_str.indexOf('$', intVarStart+1);
          out_clsSBuf.append(in_str.substring(intStartSeg, intVarStart) +
            getVariable(in_str.substring(intVarStart+1, intVarEnd)));
          intStartSeg = intVarEnd+1;
          intVarStart = in_str.indexOf('$', intVarEnd+1);
        } // if
      } // while

      if (bolFoundVar)
      {
        if (intStartSeg < intLen) // Append the rest of the string.
          out_clsSBuf.append(in_str.substring(intStartSeg));
        return out_clsSBuf.toString();
      }
      else
        return in_str;
   } // subVars

    /**
     * Returns true if the history is not empty.
     * @return whether the history has at least one URL.
     */
    public boolean hasURLs()
    {
      return !c_stkHistory.isEmpty();
    } // hasURLs
} // class BrowserContext

⌨️ 快捷键说明

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