WML interpretation engine, the core component of WAP Explorer

Source: Internet
Author: User
WML interpretation engine, the core component of WAP Explorer

Source Code address + http://javaeye.5d6d.com/thread-150-1-1.html

WML interpretation engine, the core component of WAP Explorer

Today, we are also depressed. We can't go to the forum all the time, but we can say that we have time to strip out the core components of WAP explorer and give everyone a thought.

WML interpretation engine, the core component of WAP explorer.

The most important interpretation engine for WAP, whether it is WML, HTML, or data that passes through the service, finally comes
The mobile client always goes through an explanation engine. To put it bluntly, it is the data that the mobile client can recognize.
As far as I know, the following mainstream WAP mobile browser practices are:
1. Oprea Mini is transferred through the server.
2. ucweb also uses service transfer. However, a small part of ucweb explains WML, especially HTML.
3. Protocol explorer is the same as above.
4. navigators mainly explained WML in the past. However, the latest version seems to have been transferred through servers.
5. WAP explorer explains all WML engines.
6. Some other non-mainstream browsers basically explain WML, because they do not have a powerful architecture server.

Let's take a look at the WML engine I wrote. Run wmlparser directly below. I will explain it in the form of output text. As for the problem, after the explanation, the UI will be generated and then the process will be slow.
Slow down.
All you need is the kxml package.

Below is a piece of core code

/*************************************** *****************************
* Project name: <B> learn the j2e-wap explorer </B> <br/>
*
* Copyright 2005-2006 Wuhua. All Rights Reserved </BR>
*
* This program is only used for learning purposes and cannot be used for commercial purposes. Contact the author if necessary.
**************************************** ****************************/
Package org. Fox. WAP. parser;

Import java. Io. ioexception;
Import java. Io. reader;
Import java. util. hashtable;

Import javax. microedition. lcdui. choice;
Import javax. microedition. lcdui. Font;
Import javax. microedition. lcdui. textfield;

Import org. kxml2.io. kxmlparser;
Import org. xmlpull. v1.xmlpullparser;
Import org. xmlpull. v1.xmlpullparserexception;

/**
* <B> Class Name: wmlparser. Java </B> </BR> written on: 2006-12-29 <br/>
* Function Description: The interpreter of WML, which uses the kxml engine. <Br/>
* The explanation policy is to explain how much it will be drawn. <br/>
* Demo: <br/> BUG: <br/>
*
* Date of change: <br/> author: <br/> Description: <br/>
*
* @ Author Wuhua </br> <a href = "mailto: rrq12345@163.com"> rrq12345@163.com </a>
*/
Public final class wmlparser implements parser {

Private hashtable ATTR = new hashtable ();

Private string URL; // record the current URL

/**
* The current tag. The current tag is used to create the wap ui.
*/
Private string currenttag;

/**
* Create the current align.
*/
Private string align;

Kxmlparser parser;

Private wmlparser (string URL ){
Parser = new kxmlparser ();
This. url = URL;

}

Public static wmlparser getwmlparser (string URL ){
Return new wmlparser (URL );
}

/**
* WML is interpreted and a series of wap gui components are generated. For example, if you encounter <a href = "index. WML"> homepage </a>,
* Hyperlink;
*
* @ See wapguifacloud. createhyperlink (string text, string URL, string algin );
* @ Param in --
* Get inputstream through net, or interpret WML in a local file
* @ Return -- returns a vector set that contains the wap gui.
* @ Throws xmlpullparserexception --
* Throws an exception when an error occurs.
* @ Throws ioexception --
* An exception is thrown when data is read.
*/
Public final void Parser () throws exception {

// Logger. debug (system. currenttimemillis ());
;
Int eventtype;

Eventtype = parser. geteventtype ();
While (eventtype! = Xmlpullparser. end_document ){
If (eventtype = xmlpullparser. start_document ){
} Else if (eventtype = xmlpullparser. end_document ){

} Else if (eventtype = xmlpullparser. start_tag ){
Parserstarttagimpl (parser );
} Else if (eventtype = xmlpullparser. end_tag ){
Parserendtagimpl ();
} Else if (eventtype = xmlpullparser. Text ){
Parsertextimpl (parser );
}
Eventtype = parser. Next ();
}
Runtime. getruntime (). freememory ();

// Logger. debug (system. currenttimemillis ());
// Return parts;
}

Public void setinput (Reader reader) throws xmlpullparserexception {

Parser. setinput (Reader );

}

Private void parserendtagimpl (){
String name = parser. getname ();
If (name. Equals (wmltag. p_tag) | Name. Equals (wmltag. br_tag)
| Name. Equals (wmltag. card_tag )){

This. parserbrimpl ();
}

}

/**
* This method is used to handle each tag, but there is a problem, that is, there will be two tags, for example, when <A> </a>, it will process two
*
* @ Param parser
*/
Private void parsertextimpl (kxmlparser parser ){
Parseralign ();
// Logger. debug ("tag =" + currenttag + "text ="
// + This. parser. gettext ());
If (currenttag. Equals (wmltag. p_tag )){
System. Out. println ("processing p tag ");
// Paserstringpart (style. plain_small, align, true );
} Else if (currenttag. Equals (wmltag. a_tag )){
System. Out. println ("processing a tag ");
// Parserhyperlinkimpl (parser );
} Else if (currenttag. Equals (wmltag. br_tag )){
System. Out. println ("processing BR tag ");
// Paserstringpart (style. plain_small, align, true );
} Else if (currenttag. Equals (wmltag. card_tag )){
System. Out. println ("processing card tag ");
// Parsercardtag (parser );
} Else if (currenttag. Equals (wmltag. big_tag )){
System. Out. println ("Processing Big tag ");
// Parserbigtag (parser );
} Else if (currenttag. Equals (wmltag. u_tag )){
System. Out. println ("processing U tag ");
// Parserutag (parser );
} Else if (currenttag. Equals (wmltag. em_tag )){
System. Out. println ("processing em tag ");
// Parseremtag (parser );
} Else if (currenttag. Equals (wmltag. input_tag )){
System. Out. println ("processing Input tag ");
// Parserinputtag ();
} Else if (currenttag. Equals (wmltag. select_tag )){
System. Out. println ("processing select tag ");
// Parserselecttag ();
} Else if (currenttag. Equals (wmltag. option_tag )){
System. Out. println ("processing option_tag ");
// Parseroptiontag ();
} Else {
System. Out. println ("processing string content ");
// Paserstringpart (style. plain_small, align, true );
}

Currenttag = wmltag. unknow;

}

/**
* Process the image display problem. Here we need to process the Relative Path Problem of the image.
*
*/
Private void parserimgtag (){

}

Private void parseroptiontag (){

}

/**
* Process the select tag
*
*/
Private void parserselecttag (){

}

/**
* Processing inputtag
*
*/
Private void parserinputtag (){

}

Private void parseremtag (){

}

Private void parserutag (){

}

/**
* This method is used for drawing large fonts.
*
* @ Param parser
*/
Private void parserbigtag (){

}

Private void parsercardtag (){

}

/**
* Process <br/> tags such as ----- <br/> ------ create a stringpart ("---------") and design a line feed. <br/>
* The implementation of line feed is: part. setnextrow (true );
*
* @ Param parser2
*/
Private void parserbrimpl (){

}

/**
* Process the string display paintmainform (); this must be placed in the text or UI to be updated.
*
* @ Param font
* Todo
* @ Param align
* Todo
* @ Param nextrow
* Todo
* @ Param parser2
*/
Private void paserstringpart (Font font, string align, Boolean nextrow ){

ATTR. Clear ();
}

/**
* Process the hyperlink and generate the hyperlink control.
*
* @ Param parser
*/
Private void parserhyperlinkimpl (kxmlparser parser ){

ATTR. Clear ();

}

Private void parseralign (){

}

/**
* Explains the WAP tag and saves the attribute to ATTR.
*
* @ Param parser
*/
Private void parserstarttagimpl (kxmlparser parser ){

}

Public object getresult (){
Return NULL;
}

}


You can run the main class in the source code to see the result.
If you have any questions, we will discuss them here.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.