FileDocCategorySizeDatePackage
GoogleBean.javaAPI DocExample3092Mon Feb 23 20:47:36 GMT 2004com.jspservletcookbook

GoogleBean

public class GoogleBean extends Object

Fields Summary
private GoogleSearch
search
private GoogleSearchResult
googleRes
private static final String
GOOGLE_KEY
private String
lineSep
private String
query
private boolean
filter
private int
maxResults
private int
startRes
private boolean
safeSearch
private String
restrict
private String
langRestrict
Constructors Summary
public GoogleBean()

  

    
  
      query = "";
	  restrict = "";
	  langRestrict = "";
  
  
Methods Summary
public booleangetFilter()

  
      return filter;
  
public java.lang.StringgetLangRestrict()

  
      return langRestrict;
  
public java.lang.StringgetLineSep()

  
      return lineSep;
  
public intgetMaxResults()

  
      return maxResults;
  
  
public java.lang.StringgetQuery()

  
      return query;
  
public java.lang.StringgetRestrict()

  
      return restrict;
  
public booleangetSafeSearch()

  
      return safeSearch;
  
public java.lang.StringgetSearchResults()

  
      search = new GoogleSearch();
	  
	  search.setKey(GOOGLE_KEY);
	  
	  search.setFilter(filter);
	  
	  if(restrict.length() > 0)
	      search.setRestrict(restrict);
		  
	  search.setQueryString(query);
	  
	  googleRes = search.doSearch();
	  
	  return structureResult(googleRes);
	  
  
public intgetStartRes()

  
      return startRes;
  
   
public voidrelease()

   
       search = null;
	   googleRes = null;
   
public voidsetFilter(boolean filter)

  
      this.filter = filter;
  
  
public voidsetLangRestrict(java.lang.String query)

  
  this.langRestrict = langRestrict;
  
  
public voidsetLineSep(java.lang.String lineSep)

  
      this.lineSep=lineSep;
  
public voidsetMaxResults(int maxResults)

  
      this.maxResults = maxResults;
  
  
public voidsetQuery(java.lang.String query)

  
      this.query = query;
  
  
public voidsetRestrict(java.lang.String query)

  
      this.restrict = restrict;
  
  
public voidsetSafeSearch(boolean filter)

  
      this.safeSearch = safeSearch;
  
  
public voidsetStartRes(int startRes)

  
      this.startRes = startRes;
  
  
public java.lang.StringstructureResult(GoogleSearchResult res)

  
      GoogleSearchResultElement[] elements = res.getResultElements();
	  String url ="";
	  
	  String results = "Estimated total results count: " +
	      res.getEstimatedTotalResultsCount() + lineSep + lineSep;
	  
	  for (int i = 0; i < elements.length; i++){
	  
	    url = elements[i].getURL();
		
	    results += ("Title: " + elements[i].getTitle() + lineSep +
		    "URL: <a href=\"" + url + "\">" + url + "</a>"+ lineSep +
			"Summary: " + elements[i].getSummary() + lineSep +
			"Snippet: " + elements[i].getSnippet() + lineSep + lineSep);
	  }
	  
	  return results;