Google search taglib ver. 1.1

    Custom JSP taglib lets you deploy Google search API right in your JSP pages. Tags are using Google Web API for search and let you provide a customized output. For example the following code performs a search for Coldtags suite via Google.
 


<%@ taglib uri="taglib.tld" prefix="g" %>

<g:GoogleSearch query="Coldtags suite" key="your_Google_key" result="A"/>

Tag GoogleSearch creates a page scope variable with results. And now you can examine your results. Tag ForEachResult iterates over returned records.
 


<g:ForEachResult result="A" id="var">
<p>url=<%=var.getURL()%> <%=var.getTitle()%>
</g:ForEachResult>

The nested page scope variable described by the attribute id lets you request the following properties:

getCachedSize() - returns the size in kilobytes of the cached version.
getHostName() - returns the host name in the case where multiple results come from a single host.
getRelatedInformationPresent() - returns true if and only if the "related:" special query term is supported for this URL.
getSnippet() - returns a snippet which shows the query in context on the URL where it appears.
getTitle() - returns the title of the search result, formatted as HTML.
getURL() - returns the absolute URL of the search result
toString() - returns a formatted string representation of a Google search result element.

Tag GetSpellingSuggestion lets you request a spelling suggestion from Google. E.g.:
 


<%@ taglib uri="taglib.tld" prefix="g" %>

Spelling: <g:GoogleSearch phrase="goverment" key="your_Google_key"/>

Tag GetCachedPage lets you request a page cached by Google. You can print the returned data or save them in the page scope variable (type is java.lang.Object that could be casted to byte[]. E.g.:
 


<%@ taglib uri="taglib.tld" prefix="g" %>

<g:GetCachedPage url="http://www.google.com" key="your_Google_key" id="B"/>

<%=new String((byte[])B)%>

This taglib is actually just a wrapper for Google Web API. In order to use this taglib you need obtain a key from Google and download Google API SDK (see http://www.google.com/apis. Downloaded SDK contains a file googleapi.jar. You must save it in WEB-INF/lib directory.

Tags are:

GoogleSearch

Body tag lets you perform a search via Google API. Parameters are:

1) key Describes your key from Google.
2) query Describes your query for the search.
3) filter Optional parameter. Possible values are true or false. This attribute enables or disables the "related-queries" filter.
4) maxResults Optional parameter. Describes how many results the search engine will return.
5) languageRestricts Optional parameter. Describes the language restrictions. List of languages separated by | vertical bar characters. Example value (German and French): lang_de|lang_fr
6) safeSearch Optional parameter. Possible values are true or false. If this value is true than some sites will be blocked by Google (depends on the content).
7) restrict Optional parameter. Describes a search restriction. E.g.: linux.
8) start Optional parameter. Describes an index of the first result to be returned.
9) result Describes a name for your page scope variable that will keep the results.
10) proxyHost Optional parameter. Describes a proxy setting for HTTP requests.
11) proxyPort Optional parameter. Describes a proxy setting for HTTP requests.
12) proxyUserName Optional parameter. Describes a proxy setting for HTTP requests.
13) proxyPassword Optional parameter. Describes a proxy setting for HTTP requests.

ForEachResult

Body tag lets you iterate over returned data. Parameters are:

1) result Describes a name for your page scope variable that keeps the results.
2) id Describes a name for your page scope variable that will keep a reference to the current record.

GetSpellingSuggestion

Tag lets you request a spelling suggestion from Google. Parameters are:

1) key Describes your key from Google.
2) phrase Describes your query.
3) id Optional parameter. Describes a name for your page scope variable that will keep the result (type is java.lang.String). Without this attribute tag simply prints data.
4) proxyHost Optional parameter. Describes a proxy setting for HTTP requests.
5) proxyPort Optional parameter. Describes a proxy setting for HTTP requests.
6) proxyUserName Optional parameter. Describes a proxy setting for HTTP requests.
7) proxyPassword Optional parameter. Describes a proxy setting for HTTP requests.

GetCachedPage

Tag lets you request a cached page from Google. Parameters are:

1) key Describes your key from Google.
2) url Describes a URL for your page.
3) id Optional parameter. Describes a name for your page scope variable that will keep the result (type isjava.lang.Object that is actually byte array). Without this attribute tag simply prints data.
4) proxyHost Optional parameter. Describes a proxy setting for HTTP requests.
5) proxyPort Optional parameter. Describes a proxy setting for HTTP requests.
6) proxyUserName Optional parameter. Describes a proxy setting for HTTP requests.
7) proxyPassword Optional parameter. Describes a proxy setting for HTTP requests.
 

for downloading:

 Library: googlesearchtag.jar     Description: taglib.tld  

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.