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

📄 browsercore.java

📁 一个用 java写的wap浏览器 对于浏览器感兴趣起的可以看看咯
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * 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
 *
 *			Use entirely at your own risk.
 */

package wae;

import ui.*;
import net.*;
import java.io.IOException;
import java.util.Vector;

/**
 * Title:       BrowserCore
 * Description: The <code>BrowserCore</code> class is the main class of the
 *              application and has the responsibility of managing most
 *              interactions between the WAE (Wireless Application Environment),
 *              UI (User Interface) and NET (Network) packages as well as the IP
 *              address of the gateway. It provides attributes and methods to
 *              access and manage these interactions and uses the ProcessEvents
 *              inner class to process events invoked by the UI.
 *
 *              On application startup the BrowserCore creates instances of
 *              <code>DisplayEngine</code>, <code>EventManagement</code>,
 *              <code>BrowserContext</code> and <code>Netlayer</code>. It
 *              then creates the "welcome" WML deck, and displays it by passing
 *              it as a parameter to DisplayEngine.drawCard(). When the call to
 *              <code>DisplayEngine.drawCard()</code> returns, the user has
 *              requested navigation to a URL and the
 *              <code>ProcessEvents.ProcessEventsLoop()</code> method is invoked.
 *              This method contains a loop that is executed until the
 *              application is shut down by the user.
 * Company:     J2wap.com
 * @author      Scott Campbell, Julian Bright
 * @version     1.1
 */
public class BrowserCore
{
  // Private attributes.
  /** Vector representation of a parsed card. */
  private Vector          c_clsVecCard;
  /** Holds the binary encoded WML deck. */
  private CurrentDeck     c_clsCurrentDeck;
  /** DisplayEngine object. */
  private ui.DisplayEngine  c_clsDisplayEngine;
  /** NetLayer object. Sends requests to WAP gateway. */
  private NetLayer        c_clsNetLayer;
  /** Manages events. */
  private EventManagement c_clsEventManagement;
  /** Manages browser context, i.e. history and variables. */
  private BrowserContext  c_clsBrowserContext;
  /** Processes all events after the user first requested navigation to a URL.*/
  private ProcessEvents   c_clsProcessEvents;
  /** ID of the current event being processed. */
  private int             c_intEventId;
  /** Event ID of the event bound by the timer, if one exists in the card
   *  currently being processed. */
  private int             c_intOntimerId;
  /** Contains the names of all DO elements in the card being processed. */
  private Vector          c_clsVecDosInCard = new Vector (1);
  /** IP address of the WAP gateway being used. */
  private String          c_clsGateway      = new String("193.66.59.84");
  /** Reference to the Runtime object used to invoke garbage collection. */
  private Runtime         clsRTime;
  /** The card that is displayed at application startup. */
  protected Vector          c_clsStartWml;

  /**
   * Sets the WAP gateway.<p>
   * @param in_gateway  Gateway address.
   */
  public void setGateway(String in_gateway)
  {
    c_clsGateway = in_gateway;
  } // setGateway

  /**
   * Returns a boolean that indicates if the history contains at least one URL.
   * @return  True if the history contains at least one URL.
   */
  public boolean historyHasURLs()
  {
    if (c_clsBrowserContext == null)
      return false;
    else
      return c_clsBrowserContext.hasURLs();
  } // historyHasURLs

  /**
   * Sets the <ontimer> event ID for the card currently being parsed.
   * @param in_intOntimerId The identifier of the event to which the <ontimer>
   *                        is bound.
   */
  public void setOntimerId (int in_intOntimerId)
  {
    c_intOntimerId = in_intOntimerId;
  } // setOntimerId

  /**
   * Resolves all variable references in a string.
   * @param   in_str String to be scanned for variable references.
   * @return  A string with resolved variable references.
   */
  public String subVars (String in_str)
  {
    if (c_clsBrowserContext == null)
      return in_str;
    else
      return c_clsBrowserContext.subVars(in_str);
  } // subVars

  /**
   * Returns the absolute URL of the deck containing the card which is currently
   * being displayed. If the "welcome" card is deing displayed, then
   * c_clsCurrentDeck will be null and an empty string will be returned.
   * @return  Absolute URL of the deck containing the card being displayed.
   *          If the "welcome" card is being displayed, there will be no such
   *          deck, because the user has not requested a URL, and "" will be
   *          returned.
   */
  public String getAbsoluteURL ()
  {
    if (c_clsCurrentDeck == null)
      return "";
    else
      return c_clsCurrentDeck.getAbsoluteURL();
  } // getAbsoluteURL

  /**
   * The <code>run</code> is called from <code>main<.code>, and implements the
   * startup use case:
   * <ul>
   * <li>Create the "welcome" WML deck.
   * <li>Display the "welcome" WML deck.
   * <li>When the user interface returns an event id corresponding to the user's
   *     first navigate to URL request, enter event processing loop.
   * </ul>
   */
  public void run() throws IOException
  {
    // Show the kawt object
    c_clsDisplayEngine.show();

    // Create a welcome card and display it.
    c_clsStartWml = new Vector(1,1);
    c_clsStartWml.addElement("<card>");
    c_clsStartWml.addElement("<p>");
    c_clsStartWml.addElement("Please enter a URL");
    c_clsStartWml.addElement("</p>");
    c_clsStartWml.addElement("</card>");

    int intEventID = 1;
    intEventID = this.c_clsDisplayEngine.drawCard(c_clsStartWml,
                                                  c_clsEventManagement,
                                                  c_intOntimerId);

    c_clsProcessEvents = new ProcessEvents(
      intEventID, this, clsRTime);
    c_clsProcessEvents.run();
  } // run

  /**
   * Contructor.
   */
  public BrowserCore() throws IOException
  {
    clsRTime = Runtime.getRuntime();

    // Create all permanent objects.
    c_clsDisplayEngine    = new ui.DisplayEngine (this);
    c_clsEventManagement  = new EventManagement();
    c_clsBrowserContext   = new BrowserContext();
    c_clsNetLayer         = new NetLayer ();
  } // constructor BrowserCore

  /**
   * Get a variable value given a key.
   * @param in_strVariableName  Name of the variable.
   */
  public String getVariable(String in_strVariableName)
  {
    return c_clsBrowserContext.getVariable(in_strVariableName);
  } // getVariable

  /**
   * Set a variable name and value.
   * @param in_strVariableName  Name of the variable.
   */
  public void setVariable(String in_strVariableName, String in_strVariableValue)
  {
    c_clsBrowserContext.setVariable(in_strVariableName, in_strVariableValue);
  }// setVariable

  /**
   * Register the constructor of this class as a callback for use by the
   * Spotlet class. This step is needed to make the Palm Pilot prc file.<p>
   */
  public static void main (String [] args) throws IOException
  {
    // new wae.BrowserCore().register(Spotlet.NO_EVENT_OPTIONS);
    BrowserCore clsBrowserCore = new BrowserCore();
    clsBrowserCore.run();
    System.exit(0);
  } // main

  /**
   * Title:       ProcessEvents
   * Description: The BrowserCore class is the main class of the application and
   *              has the responsibility of managing all interaction between the
   *              WAE (Wireless Application Environment), UI (User Interface) and
   *              NET (Network) packages as well as the IP address of the gateway.
   *
   *              The ProcessEvents class is an inner class of BrowserCore. It
   *              runs in it's own thread and has the responsibility of
   *              processing all events after the user first request navigation
   *              to a URL.
   * Copyright:   Copyright (c)
   * @author      Scott Campbell, Julian Bright
   * @version 1.1
   */
  public class ProcessEvents extends Thread
  {
    // Private attributes.
    private int             intEventId;
    private BrowserCore     c_clsBrowserCore;
    private Runtime         c_clsRTime;

    // Methods
    /**
     *  Constructor.
     */
    public ProcessEvents(int            in_intEventId,
                         BrowserCore    in_clsBrowserCore,
                         Runtime        in_clsRTime)
    {
      c_intEventId      = in_intEventId;
      c_clsBrowserCore  = in_clsBrowserCore;
      c_clsRTime        = in_clsRTime;
    } // constructor

    /**
     * Start the application rolling
     */
    public void run ()
    {
      // Do Barbage collection.
      clsRTime.gc();

      try
      {
        processEventsLoop(c_intEventId);
      }
      catch (Exception e)
      {
        System.out.println(e);
      } // try-catch
    } // run

   /**
    * This method is called from BrowserCore.run() when the user requests
    * navigation to a URL for the first time. A while loop is enetered  in which
    * events are processed as discribed below:
    * <ul>
    * <li>Calls methods on EventManagement to get details of the event, such as
    *     the URL and method.
    * <li>Checks with the CurrentDeck object to see if the specified URL is the
    *     URL of the deck which is currently being held.
    * <li>If a new deck is required, a message is sent to the NetLayer object to
    *     request the deck. The Netlayer object takes care of redirects and the
    *     gateway returns an approriate error deck if the URL cannot be found.
    * <li>Creates an instance of CardParser and parses the desired card.
    * <li>If the card was found and no intrinsic event which causes navigation
    *     to a new card was invoked, and a template exists in the deck, the

⌨️ 快捷键说明

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