Introduction
Snaml is an XML generator. Snaml for Java is an integration of scripting language Tcl and Snaml for XML applications. (Snaml means Snaky Markup Language. It represents an ancient snake. When Snaml's head is attacked, its tail will come to help; when its tail is attacked, its head will be back to help; when its body is attacked, both head and tail will defense.)
Snaml for Java included a WML package. Snaml for Java code could be a WML generator. It can generate a WML page as a Java servlet. Snaml for Java programs make a mobile web site more maintainable, modifiable, and reusable. In addition, Snaml for Java is much easier to connect to a database and present database content. Snaml for Java/WML is suitable for the Presentation Logic on Mobile Applications.
WML class is a component in the Snaml for Java package. WML inheritants from Java's servlet class. A developer can extends the WML class and replace the page() method to generate a WML page dynamically. WML methods are cataloged as following types:
Block Method
Block Method may specify a scope of a set of methods. Start method is the beginning of a block method. Snaml for Java specifies the satrt method name with the underscore prefix such as '_method( attribute );'. A start method may have zero or one argument called attributes. End method is the end of a block method. The method name has the underscore postfix such as 'method_();'. An end method has no argument. The methods between the start and end methods are called content.
Attribute is a list of key/value pairs separated by whitespace. A pair has the format key='value' where key must be a character string (include letters, digits, hypen, period, and underscore). The value may be any of strings or variables. The single quote ' ' groups the value. A key that is not defined as an attribute of a start method will be ignored. A non-declared key will be assigned to its default value when a start method is invocated.
Block methods may be nested. A difference between the block method and regular Java method is that the attributes of a block method may be inherited. The inner methods in the content of a block method may inherite the attributes of the outer block method. A method in the content is called a child of the outer block method. In contrast, the outer block method is a parent of the inner methods. Finally, the block methods should be properly paired. For example,
_anchor( "title='Hello'" );
_b();
quote( "an example of block command" );
b_();
anchor_();
Empty Method
Empty method is a special case of the block method where the content is empty. A special syntax with double underscore prefix such as '__method( attribute );' can represent empty method in short. It is convenient for a parser to check a program for empty method since there is no end method is expected. For example,
Following simple Snaml for Java/WML program shows a string on the mobile phone.
import packages
import java.io.*;
import java.servlet.*;
import java.servlet.http.*;
import neatware.snaml.*;
xml header and doctype definition
public class HelloWML extends WML
{
public void page() throws HttpServletException, IOException
{
__pi( "xml version='1.0'" );
__doctype( " wml PUBLIC '-//WAPFORUM//DTD WML 1.1//EN'"
+ " http://www.wapforum.org/DTD/wml_1.1.xml" );
write the string "Hello WML!" on a card.
_wml();
_card();
_p( "align='center'" );
quote( "Hello WML!" );
p_();
card_();
wml_();
}
}
|