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

📄 currentdeck.java

📁 一个用 java写的wap浏览器 对于浏览器感兴趣起的可以看看咯
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        case (byte) 0x0C: return "alt";
        case (byte) 0x0D: return "content";
        case (byte) 0x0F: return "domain";
        case (byte) 0x10: return "emptyok=false";
        case (byte) 0x11: return "emptyok=true";
        case (byte) 0x12: return "format";
        case (byte) 0x13: return "height";
        case (byte) 0x14: return "hspace";
        case (byte) 0x15: return "ivalue";
        case (byte) 0x16: return "iname";
        case (byte) 0x18: return "label";
        case (byte) 0x19: return "localsrc";
        case (byte) 0x1A: return "maxlength";
        case (byte) 0x1B: return "method=get";
        case (byte) 0x1C: return "method=post";
        case (byte) 0x1D: return "mode=nowrap";
        case (byte) 0x1E: return "mode=wrap";
        case (byte) 0x1F: return "multiple=false";
        case (byte) 0x20: return "multiple=true";
        case (byte) 0x21: return "name";
        case (byte) 0x22: return "newcontext=false";
        case (byte) 0x23: return "newcontext=true";
        case (byte) 0x24: return "onpick";
        case (byte) 0x25: return "onenterbackward";
        case (byte) 0x26: return "onenterforward";
        case (byte) 0x27: return "ontimer";
        case (byte) 0x28: return "optimal=false";
        case (byte) 0x29: return "optimal=true";
        case (byte) 0x2A: return "path";
        case (byte) 0x2E: return "scheme";
        case (byte) 0x2F: return "sendreferer=false";
        case (byte) 0x30: return "sendreferer=true";
        case (byte) 0x31: return "size";
        case (byte) 0x32: return "src";
        case (byte) 0x33: return "ordered=true";
        case (byte) 0x34: return "ordered=false";
        case (byte) 0x35: return "tabindex";
        case (byte) 0x36: return "title";
        case (byte) 0x37: return "type";
        case (byte) 0x38: return "type=accept";
        case (byte) 0x39: return "type=delete";
        case (byte) 0x3A: return "type=help";
        case (byte) 0x3B: return "type=password";
        case (byte) 0x3C: return "type=onpick";
        case (byte) 0x3D: return "type=onenterbackward";
        case (byte) 0x3E: return "type=onenterforward";
        case (byte) 0x3F: return "type=ontimer";
        case (byte) 0x45: return "type=options";
        case (byte) 0x46: return "type=prev";
        case (byte) 0x47: return "type=reset";
        case (byte) 0x48: return "type=text";
        case (byte) 0x49: return "type=vnd.";
        case (byte) 0x4A: return "href";
        case (byte) 0x4B: return "href=http://";
        case (byte) 0x4C: return "href=https://";
        case (byte) 0x4D: return "value";
        case (byte) 0x4E: return "vspace";
        case (byte) 0x4F: return "width";
        case (byte) 0x50: return "xml:lang";
        case (byte) 0x52: return "align";
        case (byte) 0x53: return "columns";
        case (byte) 0x54: return "class";
        case (byte) 0x55: return "id";
        case (byte) 0x56: return "forua=false";
        case (byte) 0x57: return "forua=true";
        case (byte) 0x58: return "src=http://";
        case (byte) 0x59: return "src=https://";
        case (byte) 0x5A: return "http-equiv";
        case (byte) 0x5B: return "http-equiv=Content-Type";
        case (byte) 0x5C: return "content=application/vnd.wap.wmlc;charset=";
        case (byte) 0x5D: return "http-equiv=Expires";
        default:  // Illegal attribrute start token. Raise an exception.
          J2WapException clsExcep = new J2WapException (
            "Error: Illegal attribrute start token (" + in_bytId + ").");
          throw (clsExcep);
      } // switch
    } // resolveAttrStartToken

    /**
     * Determine the string representation of an byte attribute value token.
     * @param   in_bytId  The attribute value token as a byte.
     * @return  The attribute value token as a string.
     */
    public String resolveAttrValueToken (byte in_bytId) throws J2WapException
    {
      switch (in_bytId)
      {
        case (byte) 0x85: return ".com/";
        case (byte) 0x86: return ".edu/";
        case (byte) 0x87: return ".net/";
        case (byte) 0x88: return ".org/";
        case (byte) 0x89: return "accept";
        case (byte) 0x8A: return "bottom";
        case (byte) 0x8B: return "clear";
        case (byte) 0x8C: return "delete";
        case (byte) 0x8D: return "help";
        case (byte) 0x8E: return "http://";
        case (byte) 0x8F: return "http://www.";
        case (byte) 0x90: return "https://";
        case (byte) 0x91: return "https://www.";
        case (byte) 0x93: return "middle";
        case (byte) 0x94: return "nowrap";
        case (byte) 0x95: return "onpick";
        case (byte) 0x96: return "onenterbackward";
        case (byte) 0x97: return "onenterforward";
        case (byte) 0x98: return "ontimer";
        case (byte) 0x99: return "options";
        case (byte) 0x9A: return "password";
        case (byte) 0x9B: return "reset";
        case (byte) 0x9D: return "text";
        case (byte) 0x9E: return "top";
        case (byte) 0x9F: return "unknown";
        case (byte) 0xA0: return "wrap";
        case (byte) 0xA1: return "www.";
        default:   // Illegal attribrute value token. Raise an exception.
          J2WapException clsExcep = new J2WapException (
            "Error: Illegal attribrute value token (" + in_bytId + ").");
          throw (clsExcep);
      } // switch
    } // resolveAttrValueToken

  /**
   * Pre-condition: in_strDeckURL.indexOf("http://") = 0
   * @param in_strDeckURL An absolute URL.
   */
  public void setDeckURL (String in_strDeckURL)
  {
    // Just to be sure that the pre-condition is always true.
    if (in_strDeckURL.indexOf("http://") != 0)
      in_strDeckURL = "http://" + in_strDeckURL;
    extractURIParts(in_strDeckURL);
  } // setDeckURL

  /**
   * This function sets class varables for connection to the NET layer, and
   * also returns a boolean indicating if a new deck is required.
   * @param   in_strLinkURL Relative URL, absolute URL or fragment ID,
   *			    refering to content that is to be retrived.
   * @return  True the URL is not the URL of the current deck.
   */
  public boolean requireNewDeck(String in_strLinkURL)
  {
    // Check if the URL only contains a fragment ID.
    if (in_strLinkURL.charAt(0) == '#')
    {
      // The URL just contains a fragment ID, so we already have the deck.
      c_strFragmentID = in_strLinkURL.substring(1);
      return false;
    } // if

    else if (in_strLinkURL.charAt(0) == '/')
    {
      // The URL is a relative URL. Update the deck URL and fragment ID.
      StringBuffer strBuffURL = new StringBuffer(c_strDeckBaseURL);
      int i;
      for (i = 7; i<strBuffURL.length(); i++)
      {
        if (strBuffURL.charAt(i) == '/')
        {
          strBuffURL.setLength(i);
          break;
        }
      } // for

      c_strDeckBaseURL = strBuffURL.toString();
        extractURIParts(c_strDeckBaseURL + in_strLinkURL);
        } //else-if
    else if (in_strLinkURL.startsWith("http://") == false)
      {
       String strURL = new String(c_strDeckBaseURL);
       if (strURL.charAt(strURL.length()-1) == '/')
        {
          strURL = strURL+in_strLinkURL;
        }
       if (strURL.charAt(strURL.length()-1) != '/')
        {
          strURL = strURL+"/";
          strURL = strURL+in_strLinkURL;
        }

    c_strDeckBaseURL = strURL;
      extractURIParts(c_strDeckBaseURL);
  }
    else
    {
      // The URL is an absolute URL, set the deck URL.
      extractURIParts(in_strLinkURL);
    } // else

    return true;
  } // requireNewDeck

   /**
   * Searches a URL for a fragment ID and sets the c_strFragmentID varaiable
   * if it finds one. If no fragment ID is found then c_strFragmentID is set
   * to null.
   * @param   in_strURL	The URL to scan for a fragment ID in.
   */
  private void extractURIParts (String in_strURL)
  {
    c_strDeckBaseURL = "";
    c_strDeckURLTail = "";
    c_strFragmentID = "";

    in_strURL = RemoveDotDot(in_strURL);

  	// Look for Fragment ID.
    int intFragIdPos = in_strURL.indexOf('#');
    if (intFragIdPos > 0)
    {
      if (intFragIdPos+1 < in_strURL.length()) // '#' is not the last character.
        c_strFragmentID = in_strURL.substring(intFragIdPos+1);
    } // if

    // Extract the deck's base and tail URL parts.
    // Look for Last '/'.
    int intDeckURLTailPos = in_strURL.lastIndexOf('/');
    if (intDeckURLTailPos > 6)
    {
      c_strDeckBaseURL = in_strURL.substring(0, intDeckURLTailPos);

      /**
       * There are two possibilities here:
       * 	(1) The URL has a base, tail and fragment ID parts.
       * 	(2) The URL has a base and tail parts.
       */
      if (intFragIdPos > 0) // (1)
      {
        c_strDeckURLTail =
          in_strURL.substring(intDeckURLTailPos, intFragIdPos);
      }
      else // (2)
        c_strDeckURLTail = in_strURL.substring(intDeckURLTailPos);
    } // if
    else if (intFragIdPos > 0)
      c_strDeckBaseURL = in_strURL.substring(0, intFragIdPos);
    else
      c_strDeckBaseURL = in_strURL.substring(0);
  } // extractURIParts

  /**
   * Returns the absolute URL of the deck.
   * @return  The absolute URL of the deck.
   */
  public String getAbsoluteURL()
  {
    return c_strDeckBaseURL + c_strDeckURLTail;
  } // getAbsoluteURL

  /**
   * Returns the fragment ID of the card being parsed.
   * @return  The fragment ID of the card being parsed. If a fragment ID has
   *          not been specified in the URI then null is returned. This will
   *          will cause the first card in the deck to be parsed.
   */
  public String getFragmentID()
  {
    if (c_strFragmentID != null && c_strFragmentID.equals(""))
      return null;
    else
      return c_strFragmentID;
  } // getFragmentID

  /**
   * Indicates if the TEMPLATE element has been found in the deck.
   * @return  Returns true if the TEMPLATE element has been found in the deck.
   */
  public boolean hasTemplate()
  {
    return c_bolHasTemplate;
  } // hasTemplate

  /**
   * For each dotdot found in the url, it removes one level of the url
   * So www.domain.com/sub1/sub2/../index.html becomes
   * www.domain.com/sub1/index.html
   * @param url  The url that should be processed
   * @return The string representation of the url without the "dotdot" notation
   */
 public String RemoveDotDot(String url){
    String strBaseUrl = new String("");
    String strRest = new String("");
    StringBuffer temp;

    int intFirstSlash = 0;
    int intNextSlash = 0;
    int intDotDotPos = 0;

    // Check if '..' is actually in the URL.
    int intPos = url.indexOf("..");
    if (intPos < 0)
      return url;

    if (url.startsWith("http://"))
      url = url.substring(7);
    intFirstSlash = url.indexOf("/");
    if (intFirstSlash > 0)
    {
      strBaseUrl = url.substring(0,intFirstSlash);
      strRest = url.substring(intFirstSlash);
    }
    else
      strBaseUrl = url;

    while (strRest.indexOf("..")>-1){
      temp = new StringBuffer(strRest);
      temp.reverse();
      strRest = temp.toString();
      //this has to be done since j2me doesnt have lastindexof(string)
      int maxPos=0,currentPos=0;
      while (strRest.indexOf("..",currentPos)>-1)
      {
        currentPos = strRest.indexOf("..",currentPos)-1;
        if (currentPos >= maxPos)
          maxPos = currentPos;
        currentPos+=2;
      }
      intDotDotPos = maxPos;
      intNextSlash = strRest.indexOf("/",intDotDotPos+4);
      if (intNextSlash > 0)
        temp.delete(intDotDotPos,intNextSlash);
      else
        temp.delete(intDotDotPos,strRest.length()-1);
      temp.reverse();
      strRest = temp.toString();
    }
    return strBaseUrl + strRest;
  } // RemoveDotDot

} // class CurrentDeck

⌨️ 快捷键说明

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