package moreservlets;

/** Small class that encapsulates how to construct a
 *  search string for a particular search engine.
 *  <P>
 *  Taken from More Servlets and JavaServer Pages
 *  from Prentice Hall and Sun Microsystems Press,
 *  http://www.moreservlets.com/.
 *  &copy; 2002 Marty Hall; may be freely used or adapted.
 */

public class SearchSpec {
  private String name, baseURL, numResultsSuffix;

  private static SearchSpec[] commonSpecs =
    { new SearchSpec
      ("google",
       "http://www.google.com/search?q=",
       "&num="),
      new SearchSpec
      ("altavista",
       "http://www.altavista.com/sites/search/web?q=",
       "&nbq="),
      new SearchSpec
      ("lycos",
       "http://lycospro.lycos.com/cgi-bin/" +
       "pursuit?query=",
       "&maxhits="),
      new SearchSpec
      ("hotbot",
       "http://www.hotbot.com/?MT=",
       "&DC=")
    };

  public SearchSpec(String name,
                    String baseURL,
                    String numResultsSuffix) {
    this.name = name;
    this.baseURL = baseURL;
    this.numResultsSuffix = numResultsSuffix;
  }

  public String makeURL(String searchString,
                        String numResults) {
    return(baseURL + searchString +
           numResultsSuffix + numResults);
  }

  public String getName() {
    return(name);
  }

  public static SearchSpec[] getCommonSpecs() {
    return(commonSpecs);
  }
}
