| #
Google Tag Library

Overview Download Documentation HowTo Javadoc TLD About
Find on this site:
|  |  | Google Tag Library Documentation
Contents
1. Overview 1.1 Installation 1.2 Google API Library 1.3 TagLib Directive 1.4 HTTP Proxy 2. Search Tags 2.1 Search Tag 2.2 SearchResult Tag 2.3 Element Tag 2.4 Next & Previous Tags 2.5 StartIndex & EndIndex Tags 2.6 EstimatedTotal Tag 2.7 SearchComments Tag 2.8 SearchQuery Tag 2.9 SearchTime Tag 2.10 SearchTips Tag 3. CachedPage & Spelling Tags 3.1 CachedPage Tag 3.2 Spelling Tag
1. Overview
> This document explains in detail the semantics of the JSP tags provided by the Google Tag Library. In this document, you will learn: How to install the Google Tag Library. How to use the various Search, CachedPage and Spelling tags. How to customize searches and interpret the search results data. You may also find the following helpful: The Google Tag Library HowTo. The Google Tag Library Javadoc documention. If you have comments, find errors, or just have questions, please visit the project's support area.
> 1.1 Installation | Back to top
> > The Google Tag Library requires a JSP (1.1 or higher) container, such as Tomcat. To use the Google Tag Library, simply copy the library's JAR file (`google.jar`) to your application's `WEB-INF/lib` directory. The Tag Library Descriptor (`google.tld`) should be placed in your application's `WEB-INF` directory. You should also modify your web application deployment descriptor (`web.xml`) file to map the Google Tag Library TLD URI to its location:
> >     <taglib>
> >       <taglib-uri>/google-taglib</taglib-uri>
> >       <taglib-location>/WEB-INF/google.tld</taglib-location>
> >     </taglib>
> 1.2 Google API Library | Back to top
> > The Google Web APIs Java library is required in order to use the Google Tag Library. The library is included in the Google Web APIs developer's kit. The library's JAR file (`googleapi.jar`) should be placed into your application's `WEB-INF/lib` directory. You must also register with Google (free) in order to obtain a license key. The license key is required to access Google's Web Services. The license key can be specified as a context parameter in your web application deployment descriptor (`web.xml`) as follows:
> >     <context-param>
> >       <param-name>google_key</param-name>
> >       <param-value>000000000000000000000000</param-value>
> >     </context-param>
> The license key can also be specified using the `key` search form parameter, `key` tag attribute or the `google_key` application scope attribute.
> 1.3 TagLib Directive | Back to top
> > Using the Google Tag Library is easy; you simply need to import it into your JSP pages using the taglib directive. For instance, you would include the following line at the top of your JSP page:
> >     <%@taglib uri="/google-taglib" prefix="google"%>
> 1.4 HTTP Proxy | Back to top
> > An HTTP Proxy server can be specified using context parameters in your web application deployment descriptor (`web.xml`) as follows:
> >     <context-param>
> >       <param-name>google_proxy_host</param-name>
> >       <param-value>proxy.example.com</param-value>
> >     </context-param>
> >     <context-param>
> >       <param-name>google_proxy_port</param-name>
> >       <param-value>3128</param-value>
> >     </context-param>
> > Similarly, the HTTP Proxy user name and password (if any) may be specified using:
> >     <context-param>
> >       <param-name>google_proxy_username</param-name>
> >       <param-value>john</param-value>
> >     </context-param>
> >     <context-param>
> >       <param-name>google_proxy_password</param-name>
> >       <param-value>opensesame</param-value>
> >     </context-param>
Please note that the Google Web APIs automatically check the standard `http.proxyHost` and `http.proxyPort` Java system properties.
2. Search Tags
> 2.1 Search Tag | Back to top
> > The `<google:search/>` tag is used to perform searches on Google's index of over 2 billion web pages. Tag Syntax The search query can be specified directly in the tag body , e.g.:
> >     <google:search>my search query</google:search>
> > or via the q request parameter:
> >     (search page)
> >     <form action="search.jsp" >
> >       <input type= text" name="q">
> >       ...
> >     </form>

> >     (result page)
> >     <google:search/>
> > Similarly the `<google:search/>` tag options can be specified as attributes, e.g.:
> >     <google:search start ="10" maxResults ="5" / >
> > or via request parameters:
> >     (search page)
> >     <form action="search.jsp" >
> >       <input type="hidden" name="start" value="10">
> >       <input type="hidden" name="maxResults" value="5">
> >       ...
> >     </form>

> >     (result page)
> >     <google:search/>
> Tag Attributes / Request Parameters
> Name | Description | Default Value
> key | Provided by Google, this is required for you to access the Google service. Google uses the key for authentication and logging. |
> q | The search query string. Note: There is no q attribute. The query is specified directly within the body of the tag. |
> start | Zero-based index of the first desired result. | 0
> maxResults | Number of results desired per query. The maximum value per query is 10. Note: If you do a query that doesn't have many matches, the actual number of results you get may be smaller than what you request. | 10
> filter | Activates or deactivates automatic results filtering, which hides very similar results and results that all come from the same web host. Filtering tends to improve the end user experience on Google, but for your application you may prefer to turn it off. | true
> restrict | Restricts the search to a subset of the Google web index, such as a country like "Ukraine" or a topic like "Linux." |
> safeSearch | A Boolean value which enables filtering of adult content in the search results. | false
> lr | Language Restrict - Restricts the search to documents within one or more languages. | latin1
> The parameters listed below are not part of the Google Web APIs.
> cache | By default the search results are cached between search requests. To ensure that a new query has been specified set this parameter to false. | true
> site | Restricts the search to documents within the specified site. |
> type | Specifies the file type to be searched. (e.g.: pdf) |
> For detailed information on the above Google search options, please refer to the Google Web APIs documentation.
> 2.2 SearchResult Tag | Back to top
> > The `<google:searchResult/>` tag is used to loop through the results returned by of a Google search. Tag Syntax The search results can be displayed using an HTML ordered list:
> >     <ol>
> >     <google:searchResult>
> >       <li><google:element name="title-url"/></li>
> >     </google:searchResult>
> >     </ol>
> The `<google:element/>` tag is used to display the details of the current result set item.
> 2.3 Element Tag | Back to top
> > The `<google:element/>` tag is used to display the properties of the current result set item. It can only be used inside the `<google:searchResult/>` tag. Tag Syntax The URL property of the search results can be displayed as follows:
> >     <google:searchResult>
> >       <google:element name="url"/><br>
> >     </google:searchResult>
> The name attribute is used to specify the desired property of the current result set item. Name Attributes Values
> Name | Description
> summary | The search result has a listing in the ODP directory, the ODP summary appears here as a text string.
> URL | The URL of the search result, returned as text, with an absolute URL path.
> snippet | A snippet which shows the query in context on the URL where it appears.
> title | The title of the search result, returned as HTML.
> cachedSize | Indicates that a cached version of the URL is available; size is indicated in kilobytes.
> relatedInformationPresent | Boolean indicating that the "related:" query term is supported for this URL.
> hostName | When filtering occurs, a maximum of two results from any given host is returned. When this occurs, the second result element that comes from that host contains the host name in this parameter.
> directoryTitle | The title that appears in the ODP directory, if any.
> directoryCategoryName | The ODP directory name for the current ODP category.
> directoryCategoryEncoding | Specifies the encoding scheme of the directory information.
> The properties listed below are not part of the Google Web APIs.
> relatedQuery | The related query, suitable for use with q request parameter of the `<google:search/>` tag. For example: `related:www.example.com/search?q=vacation%20hawaii`
> cachedQuery | The cached query, suitable for use with the q request parameter of the `<google:cachedPage/>` tag. For example: `www.example.com/search?q=vacation%20hawaii`
> staticQuery | The static query, suitable for display. For example: `www.example.com/search?q=vacation hawaii`
> > For detailed information on the above Google search elements options, please refer to the Google Web APIs documentation. Automatic Link Creation The name of two properties can be combined to automatically generate properly formatted HTML links. For example, to automatically create a link whose location is the URL of the current element and whose text is the current element's title use the following syntax:
> >     <google:element name="title-url"/>
> > which will automatically generate a property formatted HTML link:
> >     <a href="[url]">[title]</a>
> > Additionally, the link's target and style options can be specify using the target, style and css attributes of the `<google:element/>` tag:
> >     <google:element name="title-url" target="_blank" style="text-decoration:none" css="c"/>
> > which will generate:
> >     <a href="[url]" target="_blank" class="c" style="text-decoration:none">[title]</a>
> 2.4 Next & Previous Tags | Back to top
> > The `<google:next/>` tag is used to used to display a link to more search results. The `<google:previous/>` tag is used to used to display a link to previous search results. Tag Syntax The next set of results can be displayed using:
> >     Click <google:next>here</google:next> to view more results.
> Additionally, the link's target and style options can be specify using the target, style and css attributes.
> 2.5 StartIndex & EndIndex Tags | Back to top
> The `<google:startIndex/>` tag is used to display the index (1-based) of the first search result in the current result set. The `<google:endIndex/>` tag is used to used to display the index (1-based) of the last search result in the current result set.
> 2.6 EstimatedTotal Tag | Back to top
> The `<google:estimatedTotal/>` tag is used to display the estimated total number of results that exist for the current query.
> 2.7 SearchComments Tag | Back to top
> The `<google:searchComments/>` tag is used to display the comments (if any) included with the current result set.
> 2.8 SearchQuery Tag | Back to top
> The `<google:searchQuery/>` tag is used to display the text of the current query. The specified search keywords (or phrase) are returned by default. To display the full query (including preset site and file type options), set the `type` attribute to `full.`
> 2.9 SearchTime Tag | Back to top
> The `<google:searchTime/>` tag is used to display the total server time used to return the search results, measured in seconds.
> 2.10 SearchTips Tag | Back to top
The `<google:searchTips/>` tag is used to display the tips (if any) included with the current result set.
3. CachedPage & Spelling Tags
> 3.1 CachedPage Tag | Back to top
> > The `<google:cachedPage/>` tag is used to display Google's cached web pages. Tag Syntax The URL can be specified directly in the tag body, e.g.:
> >     <google:cachedPage>http://www.google.com</google:cachedPage>
> > or via the q request parameter:
> >     (search page)
> >     <form action="cache.jsp">
> >       <input type="text" name="q">
> >       ...
> >     </form>

> >     (result page)
> >     <google:cachedPage/>
> Upon submission the cached page will be displayed.
> 3.2 Spelling | Back to top
> > The <google:spelling/> tag is used to display Google's spelling suggestions. Tag Syntax The text can be specified directly in the tag body, e.g.:
> >     <google:spelling>long knifes</google:spelling>
> > or via the q request parameter:
> >     (search page)
> >     <form action="spelling.jsp">
> >       <input type="text" name="q">
> >       ...
> >     </form>

> >     (result page)
> >     <google:spelling/>
Upon submission the spelling suggestion ("long knives") will be displayed.