Groovy Documentation

org.jdesktop.swingx.ws.yahoo.search
[Java] Class YahooSearch

java.lang.Object
  org.jdesktop.beans.AbstractBean
      org.jdesktop.swingx.ws.yahoo.search.YahooSearch

public abstract class YahooSearch
extends org.jdesktop.beans.AbstractBean

Base class from which other Yahoo! search beans extend. It provides support for constructing the URL in a common manner, as well as a consistent set of "search" methods that may be called by client code.

Authors:
rbair


Field Summary
private static String URL_PREFIX

The URL prefix at the beginning of every Yahoo!

 
Constructor Summary
YahooSearch()

 
Method Summary
protected URL constructUrl(int firstSearchPosition, int resultCount)

protected int getDefaultResultCount()

Returns:
the default number of results returned from the web service.

protected String getMethod()

Returns:
the method name for the web service.

protected Map getParameters()

Returns:
a map of parameters for your web service.

protected String getServiceName()

Returns:
the service name for the web service.

protected String getVersionNumber()

Returns:
the version number of the web service.

protected ResultsList readResults(InputStream in)

@return a ResultsList containing the results read from the given InputStream.

ResultsList search()

ResultsList search(int firstResultPosition, int resultCount)

 
Methods inherited from class org.jdesktop.beans.AbstractBean
org.jdesktop.beans.AbstractBean#clone(), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(), org.jdesktop.beans.AbstractBean#wait(), org.jdesktop.beans.AbstractBean#wait(long), org.jdesktop.beans.AbstractBean#wait(long, int), org.jdesktop.beans.AbstractBean#equals(java.lang.Object), org.jdesktop.beans.AbstractBean#toString(), org.jdesktop.beans.AbstractBean#hashCode(), org.jdesktop.beans.AbstractBean#getClass(), org.jdesktop.beans.AbstractBean#notify(), org.jdesktop.beans.AbstractBean#notifyAll()
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

URL_PREFIX

private static final String URL_PREFIX
The URL prefix at the beginning of every Yahoo! search request


 
Constructor Detail

YahooSearch

YahooSearch()


 
Method Detail

constructUrl

protected final URL constructUrl(int firstSearchPosition, int resultCount)

Creates and returns a java.net.URL representing the search. It is constructed by calling the getServiceName, getVersionNumber, getMethod(), and getParameters() methods. In addition to combining these returned values into the URL, this method also performs URL escaping of the parameters as necessary. Thus, it is not necessary for the parameters in the map to be URL encoded.

If the firstSearchPosition and/or resultCount params are >= 1, then they are included in the search URL as appropriate to set the number of search results to return (resultCount) and where in the possibly infinite number of search results to start collecting results (firstSearchPosition). For instance:


   constructURL(35, 5);
 
This method call would return 5 search results, starting at the 35th result (1 based number).

Parameters:
firstSearchPosition - 1 based position in the stream of all results from which to collect resultCount number of results. If < 1, then 1 is used.
resultCount - number of results to return. If < 1, then the default result count will be used for the search (differs based on Yahoo search).
Returns:
URL representing the search.


getDefaultResultCount

protected int getDefaultResultCount()
Returns:
the default number of results returned from the web service. See the Yahoo documentation for more information about your specific web service. Defaults to 10.


getMethod

protected String getMethod()
Returns:
the method name for the web service. See the Yahoo documentation for more information about what the method name is for your particular service.


getParameters

protected Map getParameters()
Returns:
a map of parameters for your web service. See the Yahoo documentation for more information about what parameters are available for your particular service.

Note that the parameters "results" and "start" should be ommitted from this map since they are always included automatically by the constructUrl(int,int) method. Also note that you do not have to worry about url-encoding the values for these params since the constructUrl(int,int) method does this for you.


getServiceName

protected String getServiceName()
Returns:
the service name for the web service. See the Yahoo documentation for more information about what the service name is for your particular service.


getVersionNumber

protected String getVersionNumber()
Returns:
the version number of the web service. See the Yahoo documentation for more information about what the version number is for your particular service.


readResults

protected ResultsList readResults(InputStream in)
Returns:
a ResultsList containing the results read from the given InputStream.


search

public final ResultsList search()

Creates and returns a ResultsList populated with the search results. This method blocks on I/O, and should be called from a org.jdesktop.swingx.ws.BackgroundWorker or SwingWorker.

This method calls the search with the default values for resultCount (the number of results to return) and firstResultPosition (the position of the first result in the total set of results to return).

See Also:
search(int, int)


search

public final ResultsList search(int firstResultPosition, int resultCount)

Creates and returns a ResultsList populated with the search results. This method blocks on I/O, and should be called from a org.jdesktop.swingx.ws.BackgroundWorker or SwingWorker. The criteria used to perform the search is the criteria found in the beans themselves. For instance, YahooWebSearch contains many bean methods to alter the search, such as org.jdesktop.swingx.ws.yahoo.search.websearch#setCountry(Country), org.jdesktop.swingx.ws.yahoo.search.websearch#setLanguage(Language), and org.jdesktop.swingx.ws.yahoo.search.websearch#setQuery(String).

This method calls the search with the given values for resultCount (the number of results to return) and firstResultPosition (the position of the first result in the total set of results to return).

Parameters:
firstSearchPosition - 1 based position in the stream of all results from which to collect resultCount number of results. If < 1, then 1 is used.
resultCount - number of results to return. If < 1, then the default result count will be used for the search (differs based on Yahoo search).
Returns:
the list of results. Each concrete class will define the actual type of these returned results.


 

Groovy Documentation