Upload
dheeraj
View
289
Download
4
Embed Size (px)
Citation preview
COMPSCI 734 April 7, 2008
© Manoharan 1
New
Zea
land
WML and WML Script
The
Uni
vers
ity o
f Auc
klan
dWML (Wireless Markup Language)
WML is a DTD of XMLDevelopped from an earlier language called HDML (Handheld
New
Zea
land
Devices Markup Language) from a company called Unwired PlanetThis is “HTML” for wireless devices that are usually resource limited
The
Uni
vers
ity o
f Auc
klan
d
WML Structure
WML applications use a card and deck metaphorA user interaction is represented by a card, while a
New
Zea
land
p y ,complete task is represented by a deckA deck is the smallest unit of WML a web server can send to a WAP browser, and it contains one or more cards
The browser displays one card at a time
The
Uni
vers
ity o
f Auc
klan
d
WML: A Deck of Cards
Card
New
Zea
land
CardCard
CardTh
e U
nive
rsity
of A
uckl
and
COMPSCI 734 April 7, 2008
© Manoharan 2
Hello World!
<?xml version="1.0"?><!DOCTYPE wml PUBLIC " //WAPFORUM//DTD WML 1 1//EN"
New
Zea
land
<!DOCTYPE wml PUBLIC -//WAPFORUM//DTD WML 1.1//EN"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml><card id="MainCard" title="My First WML Card">
<p><img src="hello.wbmp" alt="Hello"/> <br/>
The
Uni
vers
ity o
f Auc
klan
d
img src hello.wbmp alt Hello / br/Hello World! <br/><a href="click.wml">Click Me here…</a><br/>
</p></card>
</wml>
Hello World!
<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1 3//EN"
New
Zea
land
<!DOCTYPE wml PUBLIC //WAPFORUM//DTD WML 1.3//EN"http://www.wapforum.org/DTD/wml13.dtd">
<wml><card id="MainCard" title="My First WML Card">
<p><img src="hello.wbmp" alt="Hello"/> <br/>
The
Uni
vers
ity o
f Auc
klan
d
img src hello.wbmp alt Hello / br/Hello World! <br/><a href="click.wml">Click Me here…</a><br/>
</p></card>
</wml>
WML Example #1
Splash Deck
New
Zea
land
Splash
Index
PeopleCourses
The
Uni
vers
ity o
f Auc
klan
d
c334
c335
c734
WML Example #1: Splash
<card id="Splash" title="Uni Wap Server">
New
Zea
land
<p align="center"><img src=“ClockTower.wbmp"
alt="Welcome"/><br/> <b><big>Uni Wap Server</big></b><br/>
The
Uni
vers
ity o
f Auc
klan
d
<br/><a href="#Index">Enter the Uni</a>
</p></card>
COMPSCI 734 April 7, 2008
© Manoharan 3
WML Example #1: Index
<card id="Index" title="Main index">
New
Zea
land
<p>Choose the info type:<select><option title="Courses" onpick="#Courses">Course Information</option>
<option title="People" onpick="#People">
The
Uni
vers
ity o
f Auc
klan
d
<option title= People onpick= #People > People Information</option>
</select></p>
</card>
WML Example #1: Courses
<card id="Courses" title="Course List"><p>
New
Zea
land
<p><a href="#c334">Internet Programming</a><br/><a href="#c335">Distributed Objects & Web Services</a><br/><a href="#c734">Pervasive Computing & the Enterprise</a></p>
</card>
The
Uni
vers
ity o
f Auc
klan
d
WML Example #1: c334
<card id="c334" title="Internet Programming">
New
Zea
land
<p>Internet ProgrammingCurrently on.
</p></card>
The
Uni
vers
ity o
f Auc
klan
d
WML Example #1: c335
<card id="c335" title="Distributed Objects
New
Zea
land
& Web Services"><p>Distributed Objects & Web ServicesNext Semester.
</p></card>
The
Uni
vers
ity o
f Auc
klan
d
</card>
COMPSCI 734 April 7, 2008
© Manoharan 4
WML Example #1: c734
<card id="c734" title="Pervasive Computing
New
Zea
land
& the Enterprise"><p>Pervasive Computing & the EnterpriseCurrently on.
</p></card>
The
Uni
vers
ity o
f Auc
klan
d
</card>
WML Example #1: People
<card id="People" title="People Information">
New
Zea
land
<p>Work in progress. Please visit later.
</p></card>
The
Uni
vers
ity o
f Auc
klan
d
WML Example #2: Basic Animation
Splash Deck
New
Zea
land
Splash
Splash1
Splash2
The
Uni
vers
ity o
f Auc
klan
d
Index
Splash3
WML Example #2: Splash
<card id="Splash" title="Uni Wap Services"><onevent type="ontimer">
New
Zea
land
<onevent type= ontimer ><go href="#Splash1"/>
</onevent><timer value="10"/><p align="center"><br/>
*<br/>
The
Uni
vers
ity o
f Auc
klan
d
<b><big>Uni Wap Services</big></b></p>
</card>
COMPSCI 734 April 7, 2008
© Manoharan 5
WML Example #2: Splash1
<card id="Splash1" title="Uni Wap Services"><onevent type="ontimer">
h f "#S l h2"/
New
Zea
land
<go href="#Splash2"/></onevent><timer value="10"/><p align="center"><br/>\ | /<br/>-- --
The
Uni
vers
ity o
f Auc
klan
d <br/>/ | \<br/><b><big>Uni Wap Services</big></b>
</p></card>
WML Example #2: Splash2
<card id="Splash2" title="Uni Wap Services"><onevent type="ontimer"><go href="#Splash3"/>
New
Zea
land
<go href= #Splash3 /></onevent><timer value="10"/><p align="center"><br/>\ | /<br/><br/>-- --
The
Uni
vers
ity o
f Auc
klan
d
<br/><br/>/ | \<br/><b><big>Uni Wap Services</big></b>
</p></card>
WML Example #2: Splash3
<card id="Splash3" title="Uni Wap Server">li " t "
New
Zea
land
<p align="center"><img src=“ClockTower.wbmp" alt="Welcome"/><br/> <b><big>Uni Wap Server</big></b><a href="#Index">"Enter the Uni"</a>
</p></card>
The
Uni
vers
ity o
f Auc
klan
d
</card>
WML Example #3: Softkeys
<card id="Splash3" title="Uni Wap Server"><p align="center">
New
Zea
land
<p align= center ><img src= "ClockTower.wbmp" alt="Welcome"/><br/> <b><big>Uni Wap Server</big></b><do type="accept" label="Enter the Uni"><go href="#Index"/></do>
The
Uni
vers
ity o
f Auc
klan
d
</do></p></card>
COMPSCI 734 April 7, 2008
© Manoharan 6
WML Example #4N
ew Z
eala
nd
Result
InputNumbers
Deck
The
Uni
vers
ity o
f Auc
klan
d
InputNumbers asks for two numbers, and Result displays the sum
WML Example #4a: InputNumbers
<card id="InputNumbers" title="Add2 Tool"><p align="center">
New
Zea
land
<p align= center ><b>Enter Two Numbers to Add</b><br/>n1: <input name="n1" title="" format="*N"/><br/>n2: <input name="n2" title="" format="*N"/>
</p>
The
Uni
vers
ity o
f Auc
klan
d
/p<do type="accept" label="Add"><go href="#Result"/>
</do> </card>
Link using soft keys
WML Example #4b: InputNumbers
<card id="InputNumbers" title="Add2 Tool">
New
Zea
land
p<p align="center"><b>Enter Two Numbers to Add</b><br/>n1: <input name="n1" title="" format="*N"/><br/>n2: <input name="n2" title="" format="*N"/>
The
Uni
vers
ity o
f Auc
klan
d
<br/><a href="#Result">Get Results</a></p>
</card>
Link using anchor
WML Example #4: Result
d id "R lt" titl "Add2 R lt "
New
Zea
land
<card id="Result" title="Add2 Results"><p align="center"><b>Thanks for using the Add2 Tool</b><br/>You wanted to add $(n1) and $(n2)
</p></card>
The
Uni
vers
ity o
f Auc
klan
d
</card>
To use $ as part of the text, one must use $$
COMPSCI 734 April 7, 2008
© Manoharan 7
WML Example #4c: InputNumbers
<card id="InputNumbers" title="Add2 Tool"><p align="center"><b>Enter Two Numbers to Add</b>
New
Zea
land
<b>Enter Two Numbers to Add</b><br/>n1: <input name="n1" title="" format="*N"/><br/>n2: <input name="n2" title="" format="*N"/>
</p><do type="accept" label="Add"><go href="#Result"/>
</do> An extra button to clear input fields
The
Uni
vers
ity o
f Auc
klan
d
<do type="reset" label="Clear"><refresh>
<setvar name="n1" value=""/><setvar name="n2" value=""/>
</refresh></do>
</card>
input fields
WML Example #4d: InputNumbers
<card id="InputNumbers" title="Add2 Tool"><onevent type="onenterbackward">
New
Zea
land
<onevent type= onenterbackward > <refresh>
<setvar name="n1" value=""/><setvar name="n2" value=""/>
</refresh></onevent><p align="center">
<b>Enter Two Numbers to Add</b><br/>n1: <input name="n1" title="" format="*N"/>
EnterBackward event clears input fields
The
Uni
vers
ity o
f Auc
klan
d
<br/>n2: <input name="n2" title="" format="*N"/>
</p><do type="accept" label="Add">
<go href="#Result"/></do>
</card>
Soft keys
User-interface for soft keys differ from phone to phone. Some phones do not even support soft keys.
New
Zea
land
Avoid using soft keys. Use anchors instead.
The
Uni
vers
ity o
f Auc
klan
d
WML Script
Based on ECMA Script, a derivative of JavaScriptAllows defining functions that can be called from WML, in
New
Zea
land
g ,much the same way as calling JavaScript functions in HTML
The main difference between JavaScript and WML Script is that WML Script functions are contained in a separate file and WML contains references to the URL address of the file, whereas JavaScript functions are normally embedded in the HTML code.
The
Uni
vers
ity o
f Auc
klan
d
COMPSCI 734 April 7, 2008
© Manoharan 8
WML Script
Reduces network round-trips and enhance functionality.Example usages
New
Zea
land
p gField validation
• Check for formatting, input ranges, etc.
Conditional logic• Download some intelligence into the device
Device extensions• Access device or vendor-specific API
The
Uni
vers
ity o
f Auc
klan
dWML Script
Not object-oriented, or even object-based.New variables are decalred using the var keyword (e.g. var
New
Zea
land
g y ( gx;)Types aren’t explicitly declared, so there is no need to do type checking
The
Uni
vers
ity o
f Auc
klan
d
WML Script
WML Script units have to be compiled into binary WML Script code before they can be executed in a WAP device.
New
Zea
land
The WAP gateway normally does the compilationWML Script Virtual Machine (VM) has to be included on the browser that executes the script.
The
Uni
vers
ity o
f Auc
klan
d
Referencing Variables
Variable reference Description
New
Zea
land
$(myvar:e) Forces escaping of symbolic characters.
$(myvar:n) Forces no escaping of symbolic characters.
$(myvar:u) Forces removal of symbolic character escaping. Th
e U
nive
rsity
of A
uckl
and
COMPSCI 734 April 7, 2008
© Manoharan 9
Referencing Variables
<card id="MainCard" title="My First WML Card"><onevent type="onenterforward">
New
Zea
land
yp<refresh>
<setvar name="urlA" value="file nameA.wml"/><setvar name="urlB" value="file%20nameB.wml"/>
</refresh></onevent><p>
<a href="$(urlA)">urlA $(urlA)</a><br/><a href="$(urlB)">urlB $(urlB)</a><br/><a href="$(urlA:n)">urlA:n $(urlA:n)</a><br/>
h f "$( lB )" lB $( lB ) / b /
The
Uni
vers
ity o
f Auc
klan
d
<a href="$(urlB:n)">urlB:n $(urlB:n)</a><br/><a href="$(urlA:u)">urlA:u $(urlA:u)</a><br/><a href="$(urlB:u)">urlB:u $(urlB:u)</a><br/><a href="$(urlA:e)">urlA:e $(urlA:e)</a><br/><a href="$(urlB:e)">urlB:e $(urlB:e)</a><br/>
</p></card>
Referencing Variables
Reference outside a URL
New
Zea
land
$(urlA) file nameA.wml
$(urlB) file%20nameB.wml
$(urlA:n) file nameA.wml
$(urlB:n) file%20nameB.wml
$(urlA:u) file nameA.wml
The
Uni
vers
ity o
f Auc
klan
d $(urlB:u) file nameB.wml
$(urlA:e) file%20nameA.wml
$(urlB:e) file%2520nameB.wml
Referencing Variables
Reference within a URL
New
Zea
land
$(urlA) file%20nameA.wml
$(urlB) file%2520nameB.wml
$(urlA:n) file%20nameA.wml
$(urlB:n) file%20nameB.wml
$(urlA:u) file%20nameA.wml
The
Uni
vers
ity o
f Auc
klan
d $(urlB:u) file%20nameB.wml
$(urlA:e) file%20nameA.wml
$(urlB:e) file%2520nameB.wml
WML Example #5
D k
New
Zea
land
Result
InputNumbers
Deck
The
Uni
vers
ity o
f Auc
klan
d
InputNumbers asks for two numbers, and Result displays the sum
COMPSCI 734 April 7, 2008
© Manoharan 10
WML Example #5: InputNumbers
<card id="InputNumbers" title="Add2 Tool">
New
Zea
land
p<p align="center"><b>Enter Two Numbers to Add</b><br/>n1: <input name="n1" title="" format="*N"/><br/>n2: <input name="n2" title="" format="*N"/>
The
Uni
vers
ity o
f Auc
klan
d
</p><do type="accept" label="Add">
<go href="add2.wmls#add2()"/></do>
</card>
WML Example #5: Result
New
Zea
land
<card id="Result" title="Add2 Results"><p align="center"><b>Thanks for using the Add2 Tool</b><br/>You wanted to add $(n1) and $(n2)<br/>
The
Uni
vers
ity o
f Auc
klan
d
The result you require is $(reslt)</p>
</card>
WMLS Example #5
New
Zea
land
extern function add2() {var n1 = Lang.parseInt(WMLBrowser.getVar("n1"));var n2 = Lang.parseInt(WMLBrowser.getVar("n2"));var sum = n1 + n2;var sumStr = String.format("%d", sum);WMLBrowser.setVar("reslt", sumStr);
The
Uni
vers
ity o
f Auc
klan
d
WMLBrowser.setVar( reslt , sumStr);WMLBrowser.go( "add2.wml#Result" );
}
WMLS Example #6
New
Zea
land
extern function add2() {var n1 = Lang.parseInt(WMLBrowser.getVar("n1"));var n2 = Lang.parseInt(WMLBrowser.getVar("n2"));var sum = n1 + n2;var sumStr = String.format("%d", sum);Dialogs alert("The res lt is " + s mStr)
The
Uni
vers
ity o
f Auc
klan
d
Dialogs.alert("The result is: " + sumStr);}
COMPSCI 734 April 7, 2008
© Manoharan 11
WML Script
Literals can be of the following types: boolean, integer, string, floating point, and invalids
New
Zea
land
var mString = “hello world”;var myInteger = 34;var myFloat = 3.142;var d;
The
Uni
vers
ity o
f Auc
klan
d
d = myFloat / 0;if ( d == invalid ) {
// divide by zero error}
WML Script Libraries
LangLang library includes functions for data type manipulations, absolute
l l l ti l th f ti lit d d
New
Zea
land
value calculations, general-purpose math functionality, and random number generation
FloatOptional Float library includes functions such as pow(), round(), etc, but only supported on devices with floating point capabilities
StringThe String library contains methods such as length(), charAt(), find(), etc
The
Uni
vers
ity o
f Auc
klan
d
etc.
WML Script Libraries
URLThe URL library contains functions such as getPath(),
New
Zea
land
getReferer(), getHost(), etc.Browser
WML browser interfaceProvides interaction with the browser
DialogProvides a set of typical user-interface functions such as
The
Uni
vers
ity o
f Auc
klan
d
prompt(), confirm(), and alert()
The Dialogs Library
Dialogs.alert(text)Dialogs.alert(“The parameter is: “ + parameter);
New
Zea
land
Dialogs.confirm(text, ok, cancel)Dialogs.confirm(“The parameter is: “ + parameter, “OK”, “NOTOK”);
Dialogs.prompt(text, default)Dialogs.prompt(“Who are you?”, “James Bond”);
The
Uni
vers
ity o
f Auc
klan
d
COMPSCI 734 April 7, 2008
© Manoharan 12
Standard Library Functions
Lang.max(myVal1, myVal2);Lang.min(myVal1, myVal2);
New
Zea
land
g ( y , y );Lang.abs(myVal)Float.int(myVal)Float.floor(myVal)Float.ceil(myVal)Float.round(myVal)
The
Uni
vers
ity o
f Auc
klan
dStandard Library Functions
Lang.random(parameter)Lang.maxInt()
New
Zea
land
g ()Lang.minInt()Float.maxFloat()Float.minFloat()Float.pow(number, power);Float.sqrt()
The
Uni
vers
ity o
f Auc
klan
d
Basic String Manipulation
The String library offers all manner of functionality for handling and processing strings.
New
Zea
land
ExampleString.isEmpty(string)String.length(string)String.charAt(string, position)
The
Uni
vers
ity o
f Auc
klan
d
Basic String Manipulation
SubstringsString.substring(string, position, length);
New
Zea
land
String.find(string, substring);
White SpaceString.squeeze() String.trim()
The
Uni
vers
ity o
f Auc
klan
d
COMPSCI 734 April 7, 2008
© Manoharan 13
String Formatting
String.format(template, value);The formatting template is similar to the format specification used
New
Zea
land
in C’s printf.• d for integer• f for float• s for string
The
Uni
vers
ity o
f Auc
klan
dStrings as Arrays
Standard Library String-Access Fuctionsstring.elements()
New
Zea
land
string.elementAt()string.removeAt()string.replaceAt()string.insertAt()
The
Uni
vers
ity o
f Auc
klan
d
WTAI
Wireless Telephony Application Interface is a means to create telephony applications using a WTA user-agent with
New
Zea
land
appropriate librariesCalling a number using WML ScriptWTAPublic.makeCall("777");
Calling a number through URL referencewtai://wp/mc;777
The
Uni
vers
ity o
f Auc
klan
d
Not all phones support WTAI. Check if your phone does!
WTAI
WTAI includes:Call control
New
Zea
land
Network text messagingPhone book interfaceIndicator controlEvent processing
WTAI available in WML and WML Script
The
Uni
vers
ity o
f Auc
klan
d
COMPSCI 734 April 7, 2008
© Manoharan 14
Sample Application #1
<wml><card id="Top" title="Dialler">
New
Zea
land
<card id= Top title= Dialler ><p align="center"><b>Enter the number to call:</b><br/><input name="n" title="" format="*N"/><br/></p>
The
Uni
vers
ity o
f Auc
klan
d
/p<do type="accept" label="Dial number">
<go href="dial.wmls#dial()"/></do>
</card></wml>
Sample Application #1 (2)
t f ti di l() {
New
Zea
land
extern function dial() {var n1 = Lang.parseInt(WMLBrowser.getVar("n"));WTAPublic.makeCall(n1);
}
The
Uni
vers
ity o
f Auc
klan
d
Sample Application #2
<wml><card id="Top" title="Dialler">
New
Zea
land
<card id= Top title= Dialler ><p align="center"><b>Enter a number to call:</b><br/><input name="n" title="" format="*N"/><br/></p>
The
Uni
vers
ity o
f Auc
klan
d
/p<do type="accept" label="Dial number">
<go href="wtai://wp/mc;$(n)"/></do>
</card></wml>
WTAI
Other useful WTAI functions include WTAPublic.addPBEntry, WTAPublic.sendDTMF,
New
Zea
land
WTAPhoneBook.write, and WTAPhoneBook.search.Refer to the specification for details.
The
Uni
vers
ity o
f Auc
klan
d
COMPSCI 734 April 7, 2008
© Manoharan 15
Limits
There is a limit on the maximum compiled deck size, and this varies from device to device
New
Zea
land
Nokia 7110’s is 1397 bytes while Alcatel 525’s is 6656 bytesThe contents will not be loaded, if the maximum size is exceeded.Maximum number of cards within a deck and the maximum size of a card are bounded by the maximum size of the deck.
The
Uni
vers
ity o
f Auc
klan
dLimits
The history buffer is also limited. Explicit “back” links may be required rather than relying on the history buffer to go
New
Zea
land
back.E.g., Alcatel 525 has a history buffer of size 10.
The maximum size of a WBMP image too is limited.E.g., Alcatel 525 has a limit of 784 bytes.
The
Uni
vers
ity o
f Auc
klan
d
Further Reading
Wireless Markup Language Specification. www.WAPForum.org.
New
Zea
land
WML Script Specification. WML Script Standard Libraries Specification.WAP Wireless Telephony Application Interface.
The
Uni
vers
ity o
f Auc
klan
d
Exercises
Write a WML application for English dictionary lookup. Use a web service for the actual dictionary lookup.
New
Zea
land
Write an MCQ Testing suite using WML.Use questions from COMPSCI 334-35 as sample data.
The
Uni
vers
ity o
f Auc
klan
d
COMPSCI 734 April 7, 2008
© Manoharan 16
Exercises
Find out an approximate maximum deck size supported a mobile phone of your choice.
New
Zea
land
Describe the card-and-deck metaphor used by WML applications, and discuss why such a metaphor is chosen.
The
Uni
vers
ity o
f Auc
klan
d