Introduction
Without doubt Google is the best search engine of this millenium. The Google
people are constantly improving and adding services. They have created a Java
API at http://www.google.com/apis/, which lets you access their search results
and the good news is that it is totally free! It is essentially a Web Service,
but you only need to know Java to use the API. You can search the Internet, get
cached pages or use the Google spellchecker. This tutorial focuses on the search
functionality.
I asked myself, whether it will be possible to use Google with a
mobile phone. There are of course a few obstacles here. First there is the
bandwidth limitation and also not all websites are suited for mobile browsers.
One of the protocols that allow mobile browsing is WAP. The webpages will have
to be written in WML. More about WML later in this tutorial. If you have a
website, you will probably want to know how your website ranks on Google for
certain keywords. Now you can use an application, that I have built and which I
will use as an example in this tutorial.
WML
WML is based on XML and optimized for requirements of mobile phones. One of the
optimization strategies is to split requested data and display it with cards. So
one long page becomes a card deck of which you see the top card on your mobile.
It is up to the developer to provide navigation showing one card at a time. Here
is a WML page in JSP style:
<%@ page language="java"
contentType="text/vnd.wap.wml" %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="searchrank">
<do type="accept">
<go href="showrankWML.jsp" method="post">
<postfield name="url" value="$(url)" />
<postfield name="keywords" value="$(keywords)" />
</go>
</do>
<p>URL:
<input type="text" name="url"
maxlength="20" format="*m" />
</p>
<p>Keywords:
<input type="text" name="keywords"
maxlength="20" format="*m" />
</p>
</card>
</wml>
Explanation
The first line tells the server that the content type of the page is WML.
<%@ page language="java"
contentType="text/vnd.wap.wml" %>
Next line declares it XML.
<?xml version="1.0"?>
Next line defines the DTD.
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
The root element is wml then you see one card tag. You can have several cards here. There are few tags that you will
be familiar with - p and input. The input tag however has an attribute 'format'.
The format indicates what kind of characters can be entered in the fields. In
this case all characters are accepted. This page displays a form, which is
posted to another jsp. There are two parameters - the URL of a website we want
to rank and keywords. The do tag defines an action for a pressed key and the go
and postfields indicate which values to send. In this case, when the user
presses OK after filling in all the parameters – the form data is posted to
showrankWML.jsp just like with a normal HTML form.