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

📄 #wmldeckbuilder.java#

📁 An open_source WAP browser. include Java code. support WML documents and WBMP images.
💻 JAVA#
📖 第 1 页 / 共 2 页
字号:
    while(i<source.length()){      switch(source.charAt(i)){        case '<':          source = (i>0?source.substring(0,i):"")            +"&lt;"            +(i<source.length()-1?source.substring(i+1):"");          i+=3;          break;        case '&':          source = (i>0?source.substring(0,i):"")            +"&amp;"            +(i<source.length()-1?source.substring(i+1):"");          i+=4;          break;        case '>':           source = (i>0?source.substring(0,i):"")            +"&gt;"            +(i<source.length()-1?source.substring(i+1):"");          i+=3;         break;        case '\n':          if(encodeCR){            source = (i>0?source.substring(0,i):"")              +"<br>"              +(i<source.length()-1?source.substring(i+1):"");            i+=4;          }else{            i++;          }          break;        default:          i++;      }    }    return(source);  }      /**   * This inner class contains knowledge about the WML elements   * which are supported by this user agent.  This is where the WML   * content is actually interpreted and constructed into the WmlCard   * (and related) objects.   * <p> The following tags are recognised to some extent:   * <ul>   * <li>&lt;a&gt;   * <li>&lt;br&gt;   * <li>&lt;card&gt;   * <li>&lt;do&gt;   * <li>&lt;go&gt;   * <li>&lt;i&gt;   * <li>&lt;input&gt;   * <li>&lt;p&gt;   * <li>&lt;b&gt;   * <li>&lt;u&gt;   * <li>&lt;big&gt;   * <li>&lt;em&gt;   * <li>&lt;select&gt;   * <li>&lt;option&gt;   * <li>&lt;postfield&gt;   * <li>&lt;onevent&gt;   * <li>&lt;img&gt;   * <li>&lt;prev&gt;   * <li>&lt;refresh&gt;   * <li>&lt;setvar&gt;   * <li>&lt;template&gt;   * <li>&lt;table&gt;   * <li>&lt;tr&gt;   * <li>&lt;td&gt;   * <li>&lt;timer&gt;   * </ul>   *   */  public class wmlelement{    String name;    StringBuffer endTags;    boolean begun;    private Hashtable attributes;    private WmlDeckBuilder builder;    private WmlDeck deck;    /**     * Construct a wmlelement of the given name.     * If the name is not recognised, then it will be ignored     * (however, recognised elements contained by it will be     * utilised).     *     * @param elname The name of this element     */    public wmlelement(String elname, WmlDeckBuilder b){      builder = b;	    deck = builder.getDeck();	    name = elname.toLowerCase();	    attributes = new Hashtable();	    endTags = new StringBuffer();	    begun = false;    }  /**   * Begin interpreting the attributes of this element.   */    public void begin(Hashtable a){	    attributes = a;	    // only want to begin once...	    if(begun){        return;	    }	    begun = true;	    //System.err.println("//beginning element ["+name + "]");	    //System.err.println("//attributes are ["+attributes.toString()+"]");	    //System.err.println("beginning "+name);            /**       * If the name is "wml", then we are within a (hopefully) valid       * WML deck.       */	    if(name.equals("wml")){        builder.setDeck(new WmlDeck(sourceUrl));        return;	    }else if(deck == null){        /**         * Any tags outside the "wml" tags will be ignored.         */		    System.err.println("ignoring tag .. not inside wml["+name+"]");		    return;	    }	    if(name.equals("a")){        String href =           (String)attributes.get("href");         href = deck.resolveUrl(href);        deck.currentcard.cardData("<a href='javascript:setCard(\""+href+"\");'>");        endTags.append("</a>");	    }else if(name.equals("anchor")){	        String accesskey =           (String)attributes.get("accesskey");        String title =           (String)attributes.get("title");                deck.currentcard.cardData("<a href='javascript:reval(getHref("+deck.countTasks()+"));'>");        endTags.append("</a>");      	    }else if(name.equals("br")){        deck.currentcard.cardData("<br>");	    }else if(name.equals("card")){        String id =           (String)attributes.get("id");        String onenterforward =           (String)attributes.get("onenterforward");        String onenterbackward =          (String)attributes.get("onenterbackward");        String align =          (String)attributes.get("align");        String title =          (String)attributes.get("title");	            String ontimer =          (String)attributes.get("ontimer");        if(id == null || id.equals("")){          id = "aplpi"+ ++deck.unknownCards;        }        WmlCard card = new WmlCard(deck,id);        if(onenterforward != null){          card.onenterforward("setCard('"+deck.resolveUrl(onenterforward)+"');");    	        }        if(onenterbackward != null){          card.onenterbackward("setCard('"+deck.resolveUrl(onenterbackward)+"');");    	        }        deck.addCard(card);        if(ontimer != null){          ontimer = deck.resolveUrl(ontimer);          card.ontimer(new String("setCard('"+ontimer+"');"));        }        if(title != null){          deck.currentcard.cardData("<!--title--><center>"                                    +title+"</center>");        }        if(align != null){          deck.currentcard.cardData("<"+align+">");          endTags.append("</"+align+">");        }        endTags.append("\n");	    }else if(name.equals("do")){        String type =          (String)attributes.get("type");        String label =          (String)attributes.get("label");        String name_ =          (String)attributes.get("name");        String optional =          (String)attributes.get("optional");        if(type == null){        }else if(type.equals("accept")){          //Positive acknowledgement (acceptance)          if(label == null){            label="ok";          }          deck.currentcard.navData(            "<a href='javascript:reval(getHref("+deck.countTasks()+"));'>"            + "<em>"            + label+"</em></a>");        }else if(type.equals("prev")){          //Backward history navigation          if(label == null){            label = "back";          }          deck.currentcard.navData(            "<a href='javascript:prevCard();'>"            + "<em>" + label+"</em></a>");        }else if(type.equals("help")){          //Request for help. May be context-sensitive.         }else if(type.equals("reset")){          //Clearing or resetting state.         }else if(type.equals("options")){          //Context-sensitive request for options           //or additional operations.        }else if(type.equals("delete")){          //Delete item or choice        }else if(type.equals("unknown")){          //A generic do element. Equivalent to an           //empty string (e. g., type="")        }else{          //don't know about this type.        }	    }else if(name.equals("go")){        String href = // %HREF; #REQUIRED          (String)attributes.get("href");         String sendreferer = // %boolean; "false"          (String)attributes.get("sendreferer");        String method = // # (post| get) "get"          (String)attributes.get("method");        if(method == null){          method = "get";        }        WmlTask t = deck.newTask();        t.init("go",href,sendreferer, method);	    }else if(name.equals("i")){        deck.currentcard.cardData("<i>");        endTags.append("</i>");    	    }else if(name.equals("input")){        String name_ = // NMTOKEN #REQUIRED           (String) attributes.get("name");        String type_ = // (text| password) "text"          (String) attributes.get("type");        if(type_ == null){          type_ = "text";        }        String value =//%vdata; #IMPLIED           (String) attributes.get("value");        if(value == null){          value = "";        }        String format =//CDATA #IMPLIED           (String) attributes.get("format");        String emptyok = //%boolean; "false"           (String) attributes.get("emptyok");        if(emptyok == null){          emptyok = "false";        }        String size = //# %number; #IMPLIED           (String) attributes.get("size");        if(size==null){          size="10";        }        try{          int v = (Integer.valueOf(size)).intValue();          if( v>12 || v<1 ){            size="12";          }        }catch(Exception E){          size="12";        }        String maxlength = //%number; #IMPLIED           (String) attributes.get("maxlength");        String tabindex = //%number; #IMPLIED (          (String) attributes.get("tabindex");        String title = //%vdata; #IMPLIED           (String) attributes.get("title");        if(title==null){          title = "";        }        String accesskey =//%vdata; #IMPLIED          (String)attributes.get("accesskey");        deck.setVar(name_,value);        deck.currentcard.cardData(title+"<br><input size="+size                                  + " type="+ type_                                  + " value=\"$"+ name_+ "\""                                  + " onchange=\"setVar('"                                  +name_+"',this.value);\">");        	    }else if(name.equals("p")){        String align = (String)attributes.get("align");        String mode = (String)attributes.get("mode");        if(align == null){          align="left";        }        deck.currentcard.cardData("<p align=\""+align+"\">");        endTags.append("</p>");	    }else if(name.equals("b")){        deck.currentcard.cardData("<b>");        endTags.append("</b>");	    }else if(name.equals("u")){        deck.currentcard.cardData("<u>");        endTags.append("</u>");	    }else if(name.equals("big")){        deck.currentcard.cardData("<b>");        endTags.append("</b>");	    }else if(name.equals("em")){        deck.currentcard.cardData("<em>");        endTags.append("</em>");	    }else if(name.equals("select")){        //  title %vdata; #IMPLIED        String title_ = (String)attributes.get("title");                //  name NMTOKEN #IMPLIED        String name_ = (String)attributes.get("name");                //  value %vdata; #IMPLIED        String value = (String)attributes.get("value");                //  iname NMTOKEN #IMPLIED        String iname = (String)attributes.get("iname");                //  ivalue %vdata; #IMPLIED        String ivalue = (String)attributes.get("ivalue");                //  multiple %boolean; "false"        String multiple = (String)attributes.get("multiple");        boolean multiple_ = true;        if(multiple == null ||            (!multiple.equals("true"))){          multiple_ = false;        }                //  tabindex %number; #IMPLIED        String tabindex = (String)attributes.get("tabindex");        deck.currentcard.beginSelect(title_,name_,value,                                    iname,ivalue,multiple_);        //deck.currentcard.cardData("<!--select-->");        //endTags.append("<!--/select-->");	    }else if(name.equals("option")){        String onpick =          (String)attributes.get("onpick");        String title_ =           (String)attributes.get("title");        String value =          (String)attributes.get("value");        if(onpick!=null && !onpick.equals("")){          onpick = deck.resolveUrl(onpick);        }          //deck.currentcard.cardData("<br><em>&gt;</em><a href=\"javascript:setCard('"+onpick+"');\">");          //endTags.append("</a>");          deck.currentcard.addOption(value,title_,onpick);        	    }else if(name.equals("postfield")){        // these are the post fields for the current 'go'        String _name = (String)attributes.get("name");        String value = (String)attributes.get("value");        WmlTask t = deck.currentTask();        if(t != null){          t.postfield(_name,value);        }	    }else if(name.equals("img")){        String src = // %HREF; #REQUIRED           (String)attributes.get("src");        String localsrc = //%vdata; #IMPLIED           (String)attributes.get("localsrc");        String alt = //%vdata; #REQUIRED           (String)attributes.get("alt");        String vspace = //%length; "0"           (String)attributes.get("vspace");        String hspace = //%length; "0"           (String)attributes.get("hspace");        String align = //%IAlign; "bottom"           (String)attributes.get("align");         String height = //%length; #IMPLIED           (String)attributes.get("height");        String width = //%length; #IMPLIED          (String)attributes.get("width");        deck.currentcard.cardData("<img ");        if(localsrc != null && localsrc.length()>0){          src=localsrc;          if(alt == null || alt.length()>0){            alt=localsrc;          }        }        if(src != null && src.length()>0){          src = deck.resolveUrl(src);          deck.currentcard.cardData(" src=\""                                    +WmlDeckBuilder.imgconverter                                     +src+"&.gif\"");          if(alt != null){            deck.currentcard.cardData(" alt=\""+alt+"\" ");          }        }        deck.currentcard.cardData(">");        endTags.append("</img>");		    }else if(name.equals("onevent")){        String tipe = (String)attributes.get("type");        if(tipe!=null){          deck.awaitingtask=tipe;        }	    }else if(name.equals("prev")){        deck.newTask();        WmlTask t = deck.currentTask();        t.init("prev");        	    }else if(name.equals("refresh")){        deck.newTask();        WmlTask t = deck.currentTask();        t.init("refresh");    	    }else if (name.equals("setvar")){        WmlTask t = deck.currentTask();        String varname = (String)attributes.get("name");        String value = (String)attributes.get("value");        if(t !=null){          t.setvar(varname, value);        }      }else if(name.equals("template")){        WmlTemplate t = new WmlTemplate(deck);        deck.currentcard =  t;	    }else if(name.equals("table")){        deck.currentcard.cardData("<table>");        endTags.append("</table>");        	    }else if(name.equals("tr")){        deck.currentcard.cardData("<tr>");        endTags.append("</tr>");        	    }else if(name.equals("td")){        deck.currentcard.cardData("<td><font size=1>");        endTags.append("</font></td>");        	    }else if(name.equals("timer")){        String value =          (String)attributes.get("value");        String name_ =          (String)attributes.get("name");        if(value != null){          deck.setVar("aplpicardtimeout"+deck.currentcard.name(),                      value+"00");        }else{          value = "0";        }        if(name_ != null){          deck.setVar(name_, value);          deck.setVar("aplpicardtimeout"+deck.currentcard.name(),                      "$"+name_);        }        	    }else{        deck.currentcard.cardData("<!-- failed to recognize tag ["+name+"]-->");	    }	        }      /**   * Finish interpreting the attributes of this element.   * Any necessary cleanup activities will be performed.   */    public void end(){	    //System.err.println("//ending element ["+name + "]");	    if(deck == null){        return;	    }	    if(deck.currentcard != null){        deck.currentcard.cardData(endTags.toString());	    }	    if(name.equals("card")){        deck.currentcard = (WmlCard)null;	    }else if(name.equals("template")){        deck.currentcard = (WmlCard)null;      }else if(name.equals("go")){        deck.endTask();	    }else if(name.equals("onevent")){        deck.awaitingtask = null;	    }else if(name.equals("prev")){        deck.endTask();	    }else if(name.equals("refresh")){        deck.endTask();	    }    }  }}

⌨️ 快捷键说明

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