2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 23 - Wireless Internet and m- Business Outline 23.1 Introduction 23.2 M-Business 23.3 Identifying User Location E911 Act Location-Identification Technologies 23.4 Wireless Marketing, Advertising and Promotions 23.5 Wireless Payment Options 23.6 Privacy and the Wireless Internet 23.7 International Wireless Communications 23.8 Wireless-Communications Technologies 23.9 WAP and WML Phone Simulator and Setup Instructions Creating WML Documents WMLScript Programming String Object Methods
2001 Prentice Hall, Inc. All rights reserved. 2 Chapter 23 - Wireless Internet and m- Business Outline Wireless Protocols, Platforms and Programming Languages WAP Handheld Devices Markup Languages (HDML) Compact HTML (cHTML) and i-mode Java and Java 2 Micro Edition (J2ME) Binary Run-Time Environment for Wireless (BREW) Bluetooth Wireless Technology Internet and World Wide Web Resources
2001 Prentice Hall, Inc. All rights reserved Wireless Marketing, Advertising and Promotions
2001 Prentice Hall, Inc. All rights reserved. Outline 4 Fig23_2.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " Welcome to wireless programming! This text will be displayed in the browser window.
2001 Prentice Hall, Inc. All rights reserved. Outline 5 Program Output
2001 Prentice Hall, Inc. All rights reserved. Outline 6 Program Output
2001 Prentice Hall, Inc. All rights reserved Creating WML Documents Fig Phone Information window showing an error in the deck. List of errors in deck.
2001 Prentice Hall, Inc. All rights reserved. Outline 8 Fig23_4.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " Local Icons Link Wrench Football Boat The text Link is a link to card2.The text Wrench is a link to card3.The text Football is a link to card4 in fig23_5.wml. The boat local icon is a link to card5 in fig23_5.wml.
2001 Prentice Hall, Inc. All rights reserved. Outline 9 Fig23_4.wml You chose the link! You chose the wrench! Result of choosing the link icon. Result of choosing the wrench icon.
2001 Prentice Hall, Inc. All rights reserved. Outline 10 Fig23_5.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " You chose the football! You chose the boat! Result of choosing the football link. Result choosing the boat link.
2001 Prentice Hall, Inc. All rights reserved. Outline 11 Program Output
2001 Prentice Hall, Inc. All rights reserved. Outline 12 WelcomeDoc.wmls 1// Fig. 23.6: welcomeDoc.wmls 2// Writing a line of text 3 4extern function welcome() 5{ 6 // creating a browser variable and assigning it a value 7 WMLBrowser.setVar( "welcome", 8 "Welcome to WMLScript programming!" ); 9 10 // refresh the display window 11 WMLBrowser.refresh(); 12} Method setVar creates a browser variable welcome with the value of the string “Welcome to WMLScript programming”. Method refresh refreshes the browser and all variable values.
2001 Prentice Hall, Inc. All rights reserved. Outline 13 Fig23_7.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " $welcome Dereferencing browser variable welcome displays its value.
2001 Prentice Hall, Inc. All rights reserved. Outline 14 Program Output
2001 Prentice Hall, Inc. All rights reserved. Outline 15 DialogPrompt.wml s 1// Fig. 23.8: dialogPrompt.wmls 2// Printing multiple lines in a dialog 3 4extern function displayDialog() 5{ 6 Dialogs.alert( "Welcome to\nWMLScript\nProgramming!" ); 7} The alert method displays the string passed to it in a dialog box. Each line break character places the remaining text on the next line in the browser.
2001 Prentice Hall, Inc. All rights reserved. Outline 16 Fig23_9.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " Setting the type attribute to onenterforward causes the action of the go element to be executed when the card is entered. When the cars is entered, function displayDialog will be called.
2001 Prentice Hall, Inc. All rights reserved. Outline 17 Program Output
2001 Prentice Hall, Inc. All rights reserved. Outline 18 SquareNumbers.wm ls 1// Fig : squareNumbers.wmls 2// Programmer-defined functions 3 4extern function count() 5{ 6 // prompt the user for a number 7 var inputNumber = Dialogs.prompt( 8 "Enter a number to be squared", "" ); 9 10 // convert the number to an integer and pass 11 // the number to function square 12 var numberSquared = square( Lang.parseInt( inputNumber ) ); var outputSquare = inputNumber + " squared is " + 15 numberSquared; // set the string to a browser variable and 18 // redirect the client to the card named result 19 WMLBrowser.setVar( "result1", outputSquare ); 20 WMLBrowser.go( "#result" ); 21} 22 23function square( y ) 24{ 25 return y * y; 26} Method prompt displays a dialog box that displays a message and an input field. The first argument passed to method prompt is the message that is displayed in the dialog. The second argument passed to methos prompt is the default value for the input field Call function square and pass it the value input by the user. Variable y gets the value of inputNumber.
2001 Prentice Hall, Inc. All rights reserved. Outline 19 Fig23_11.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " Press OK to square a number $result This soft key calls function count when pressed. The prev element sends the client back to the previous card. Dereferencing variable result displays the result of the calculation.
2001 Prentice Hall, Inc. All rights reserved. Outline 20 Program Output
2001 Prentice Hall, Inc. All rights reserved. Outline 21 GetVariable.wmls 1// Fig : getVariable.wmls 2// Using the WMLBrowser object’s getVar method 3 4extern function getName() 5{ 6 var x = WMLBrowser.getVar( "username" ); 7 var y = x + ", thanks for visiting!"; 8 9 WMLBrowser.setVar( "result", y ); 10 WMLBrowser.go( "#card2" ); 11} Method getVar retrieves the value of browser variable username. The + operator concatenates the value of x and the string “, thanks for visiting”.
2001 Prentice Hall, Inc. All rights reserved. Outline 22 GetVar.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " Enter your name: This soft key calls function getName when pressed. This input field allows the user to enter a username. This soft key sends the client to the previous card.
2001 Prentice Hall, Inc. All rights reserved. Outline 23 GetVar.wml Program Output $result Dereferencing browser variable result displays the results of the script.
2001 Prentice Hall, Inc. All rights reserved. Outline 24 FunctionSet.wmls 1// Fig : functionSet.wmls 2// Demonstrating String object methods 3 4extern function stringMethods() 5{ 6 var string1 = ""; 7 var empty; 8 9 // test if string1 is empty 10 if ( String.isEmpty( string1 ) ) 11 empty = "string1 is empty"; 12 else 13 empty = "string1 is not empty"; WMLBrowser.setVar( "emptyString1", empty ); // format the string to have 12 spaces between 18 // "Wireless" and "Web" 19 string1 = String.format( "Wireless%15s", "Web" ); WMLBrowser.setVar( "formatString1", string1 ); // squeeze the string until one space is left 24 string1 = String.squeeze( string1 ); WMLBrowser.setVar( "squeezeString1", string1 ); // use method element to count the elements in string1 29 // use the toString method to convert the integer to 30 // a string 31 var count = String.toString( String.elements( string1, " ") ); WMLBrowser.setVar( "elementsString1", count ); 34 The value of variable string1 begins as an empty string. Method isEmpty determines if the string is empty and returns true if it is. After invoking the format method, the value of string1 will be “Wireless Web” with 12 spaces separating the two words. Method squeeze eliminates all consecutive whitespace leaving one space between Wireless and Web. Method elements determines the amount of elements in a string separated by a space (the second argument). Method toString converts the integer value returns by method elements to a string.
2001 Prentice Hall, Inc. All rights reserved. Outline 25 FunctionSet.wmls 35 // find string starting at index 8 and ending with a space 36 var string1Element = String.elementAt( string1, 8, " " ); WMLBrowser.setVar( "elementAtString1", string1Element ); // get the length of string1 41 var length = String.length( string1 ); // insert "Book" at the end of string1 44 string1 = String.insertAt( string1, "Book", length, " " ); WMLBrowser.setVar( "insertAtString1", string1 ); // replace "Web" with "Deitel" where "Web" has an 49 // index of 1 50 string1 = String.replaceAt( string1, "Deitel", 1, " " ); WMLBrowser.setVar( "replaceAtString1", string1 ); // remove "Wireless" from string1 55 string1 = String.removeAt( string1, 0, " " ); WMLBrowser.setVar( "removeAtString1", string1 ); 58 WMLBrowser.go( "#card2" ); 59} Method elementAt will return a substring from the value of string1 starting at index 8 and ending at a space. Method length returns the number of characters in string1 as an integer. Method replaceAt removes “Web” from string1 and replaces it with the string “Deitel” ( Wireless Deitel Book ). Method insertAt inserts the string “Book” at the end of the value of string1 ( Wireless Web Book ). Method removeAt removes the string “Wireless” from the value of string1 leaving “Deitel Book”.
2001 Prentice Hall, Inc. All rights reserved. Outline 26 StringMisc.wml 1 2<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" 3 " Click Run to execute the script
2001 Prentice Hall, Inc. All rights reserved. Outline 27 StringMisc.wml isEmpty method: $emptyString String.format method: $formatString Display results of invoking method isEmpty. Display result of invoking method format.
2001 Prentice Hall, Inc. All rights reserved. Outline 28 StringMisc.wml String.squeeze method: $squeezeString String.elements method: $elementsString Display results of invoking method squeeze. Display result of invoking method elements.
2001 Prentice Hall, Inc. All rights reserved. Outline 29 StringMisc.wml String.elementAt method: $elementAtString String.insertAt method: $insertAtString Display results of invoking method elementAt. Display result of invoking method insertAt.
2001 Prentice Hall, Inc. All rights reserved. Outline 30 StringMisc.wml String.replaceAt method: $replaceAtString String.removeAt method: $removeAtString Display results of invoking method replaceAt. Display result of invoking method removeAt.
2001 Prentice Hall, Inc. All rights reserved. Outline 31 Program Output
2001 Prentice Hall, Inc. All rights reserved. Outline 32 Program Output