|
Jack's Hack for the month of August, 2003: This month in Jack's Hacks, we're going to take a look at an open source tool that offers devleopers a way to manage and deal with the multitude of devices and their varying capabilities. The tool we will use is the WURFL (Wirless Universal Resource FiLe), and you can find all of the details including source code and updates at http://wurfl.sourceforge.net What is the WURFL? The WURFL is an XML configuration file that contains information about every known wireless user agent that the developer community has encountered. It is the developer's counterpart to UAProf if you will, but contains additional data about devices that do not have UAProf information, and information outside of the scope of UAProf, but relevant to developers (In case you forgot, we talked about UAProf back in February's hack). The families of features that the WURFL Covers are:
<device user_agent="SIE-SL55/02 UP.Browser/6.1.0.5.c.2 (GUI) MMP/1.0" fall_back="sie_sl55_ver1" id="sie_sl55_ver1_sub02"/> This particular entry in the WURFL has no information about any properties, so the fall_back entry of the "sie_sl55_ver1" is to be used. The entry for sie_sl55_ver1
starts as:<device user_agent="SIE-SL55" fall_back="opwv_v6_generic" id="sie_sl55_ver1">and contains informaiton about the supported sound formats in the SL55:
Thanks to the inheritance feature of the WURFL, we know that our version of the SL55 has support
for all of these sounds formats as well. Also, if we discover an error or omission in the WURFL,
it can be fixed in one place, and then inhereted by all future versions of the device. Futrhermore, since
the SIE-SL55 "falls back" to opwv_v6_generic, it will inherit all known properties
of the Openwave devices. Also, when Siemens releases an update to the SL55, SIE-SL55/08 for example,
an application using the WURFL will be able to correctly identify its capabilities without making any code changes.
How do I use the WURFL in an application Having this wealth of device information in a XML document that is readable by an end user is nice, but what we realy want to do is leverage this data when delivering content. An example of this is that one of the most common tasks a user will do when visiting any website is navigate back from any given page. The challenge for devleopers is that some devices have built in back keys, and other don't. Providing a link to navigate backwards from every page that you display may be neccessary, but may also take up real estate that could be used in other ways. WURFL can help, with the capapbilty: built_in_back_button_support. Since it would be a waste of time to manully read the WURFL and build mulitple versions of page to serve to the different devices, we want to incorporate the WURFL right into our page devliery. Fortunately, the developers and maintainers of the WURFL offer a number of tools that can be used to get started. Samples are available for Java (including a tag library), PHP, and Perl. We'll take a look specifically at how the WURLF JSP tag library can be used. Keep in mind that the technique we use can be applied with ANY programming language you favor The first step is to download the packages from the WURFL Website: http://wurfl.sourceforge.net/java/jaxb_api.php Following the instructions from the site, setting up your existing Servlet Container (such as Tomcat) is pretty straight foward. Since there are additional details on Tomcat configuration at the WURFL project home page, we'll skip the gory details and get right into the code. The tag library contains an <wurfl:ifmc> tag that we can employ to decide if we want to include a link for backward navigation in
our code, or if the device has us covered already. We use the ifmc (If Multiple Conditions) so that we can also employ
the <wurfl:else> tag to cover both cases. (In the case where we're only concerned about the presence of
a condition to base code on, the <wurfl:if> tag can be used).
Looking at the code in red, you can see where we employ the WURFL elements. The logic is very straight foward here: if the phone has a built in back key, print "no" else include a link back.We need to use the ifmc tag instead of just the if so we can use the else. The JSP bit at the bottom simply
prints the user-agent for a sanity check. If we look at this code using the Openwave Phone Simulator 6.2.2, and the Nokia 5100 SDK 1.0
here's what we see
While we used a very simple (and mildly contrived) example here, it should give the flavor of the power that the WURFL can bring to your wireless application development. |