Header
Home | Sitemap Set as homepage | Add to favorites
  Search the Site     » Advanced Search
Sections



Standard Libraries

by

image

Standard Libraries

WMLScript contains several standard libraries with functions that can be called by other functions in their own compilation units. Libraries are collections of functions that are logically grouped together based on what the library functions do. The functions are called by using a dot separator, as has been shown in examples in the last two chapters. This is similar to other object-oriented languages with the library name to the left of the dot, and the called function and its parameters to the right.

These libraries are stored in the WAP browser, which is resident in the WAP-compliant device. There are currently eight libraries available to use in WMLScript: Lang, Float, String, URL, WMLBrowser, Dialogs, Debug, and Console.

Example 6.2 shows a WMLScript function, which uses the length function from the String library, and the setVar and refresh functions from the WMLBrowser library. The length function returns the length of the string, and the setVar function sets the value of a variable, and refresh updates the WML document in the browser.

Example 6.2

Figure 6.2 shows the associated screens.

   

Appendix II lists all of the functions in each of the WMLScript libraries. The following sections will describe the purpose of each library, and give an example of one or more of the functions in that library. But, see Appendix II for all of the functions and what they do.

URL

The URL library contains functions that can be used to examine validation, content and parameters of absolute and relative URL addresses. The library also includes functions for searching the contents of new URL addresses.

The escapestring function from the URL library returns from the entered parameter a new string that is URL encoded. This means that all special characters have been changed to hexadecimal format. This method is used when sending form data to CGI programs and Java servlets using the POST or GET methods. Example 6.10 uses the escapestring function. The figure shows the associated screen

Click To expand
Figure 6.10: Escapestring Example

Just a note on inputting variables from a WML program to a WMLScript function: you need single quotes around the variable (e.g. ‘$(str)’ ) if it is a string, but you don’t need the single quotes around the variable if it is an integer or floating-point.

The getbase function from the URL library returns the absolute address of the WMLScript compilation unit. Example 6.11 shows the use of the get- base function. Figure 6.11 shows the associated screen

Example 6.11

WML Browser

The WMLBrowser library functions have been used in most of the examples in Chapters 3, 4, 5, and 6. The library contains functions which make it possible to examine WML document variables, to change their values and to manipulate the transfer between documents in a browser.

A variable that is defined in a WML document can be retrieved into a WMLScript function by using the getVar function from the WMLBrowser library. The variable name used in the WML document is the same variable name used in the WMLScript compilation unit. Basically this is another way to “pass” variables from WML documents and WMLScript functions, without listing them as parameters in the function call.

Example 6.12 shows the use of the getVar function. Figure 6.12 shows the associated screen.

Example 6.12
Click To expand
Figure 6.12: getVar Example

The go function in the WMLBrowser library defines the URL address where the browser moves when the control of the program execution transfers from the WMLScript interpreter back to the browser. Normally the go function is called as the last WMLscript command.

Example 6.13 shows the use of the go function as it appears in a WMLScript function.

Example 6.13

The setVar and refresh functions from the WMLBrowser library are used in most of the examples in previous chapters. They set the value of variables (setVar) and refresh the contents of the browser(refresh).

The remaining functions of the WMLBrowser library are listed in AppendixII.


538 times read

Related news

» Questions
by admin posted on Jul 19,2007
» Lang Library
by admin posted on Jul 19,2007
» Scope Rules (WML)
by admin posted on Aug 28,2007
» Functions
by admin posted on Jul 19,2007
» Float Library
by admin posted on Jul 19,2007


More Top News
Cisco Wireless Networking
Most Popular
Featured Author