FileDocCategorySizeDatePackage
AmazonBean.javaAPI DocExample3906Mon Feb 23 20:51:10 GMT 2004com.jspservletcookbook

AmazonBean

public class AmazonBean extends Object

Fields Summary
private static final String
AMAZON_KEY
private static final String
END_POINT
private static final String
AMAZON_TAG
private URL
endpointUrl
private String
lineSep
private String
totalResults
private String
keyword
private String
page
private String
type
private String
mode
Constructors Summary
public AmazonBean()

  

     
Methods Summary
public java.lang.StringgetKeyword()

  
      return keyword;
  
public KeywordRequestgetKeywordRequest()

  
      KeywordRequest request = new KeywordRequest();
      request.setKeyword(keyword);
      request.setMode(mode);
      request.setPage(page);
      request.setType(type);
      
      request.setDevtag(AMAZON_KEY);
      
      request.setTag(AMAZON_TAG);
      
      return request;
  
  
public java.lang.StringgetLineSep()

  
      return lineSep;
  
public java.lang.StringgetMode()

  
      return mode;
  
public java.lang.StringgetPage()

  
      return page;
  
public java.lang.StringgetSearchResults()

  
     endpointUrl = new URL(END_POINT);

    AmazonSearchService  webService = new AmazonSearchServiceLocator();
      
      AmazonSearchPort port = webService.getAmazonSearchPort(endpointUrl);
      
      KeywordRequest request = getKeywordRequest();
      
      ProductInfo prodInfo = port.keywordSearchRequest(request);
      
      setTotalResults( prodInfo.getTotalResults() );
      
      return structureResult(prodInfo);
      
  
public java.lang.StringgetTotalResults()

  
      return totalResults;
  
public java.lang.StringgetType()

  
      return type;
  
public static voidmain(java.lang.String[] args)

  
      AmazonBean bean = new AmazonBean();
      bean.setKeyword("Lance%20Armstrong");
      bean.setType("heavy");
      bean.setMode("books");
      bean.setPage("1");
      
      System.out.println( bean.getSearchResults() );
  
public voidrelease()

   
   
public voidsetKeyword(java.lang.String keyword)

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

  
      this.lineSep=lineSep;
  
public voidsetMode(java.lang.String mode)

  
      this.mode = mode;
  
  
public voidsetPage(java.lang.String page)

  
  this.page = page;
  
  
public voidsetTotalResults(java.lang.String results)

  
  totalResults = results;
  
  
public voidsetType(java.lang.String type)

  
  this.type = type;
  
  
public java.lang.StringstructureResult(ProductInfo info)

      
      Details[] details = info.getDetails();
      
      String results = "";
	  
      String[] authors = null;
      String usedP = null;
      String rank = null;
      
      for (int i = 0; i < details.length; i++){
      
	      
	  if(mode != null && mode.equals("books")){
          authors = details[i].getAuthors(); }
          
          results += "<strong>"+(i+1)+". Product name:</strong> " + details[i].getProductName() + lineSep;
          
		  if(mode != null && mode.equals("books")){
                for (int j = 0; j < authors.length; j++)
                    results += "Author name "+(j+1)+": " + authors[j] + lineSep;
		  }

          usedP = details[i].getUsedPrice();
          rank = details[i].getSalesRank();
                    
          results += "Sales rank: " + (rank == null ? "N/A" : rank) + lineSep +
          "List price: " + details[i].getListPrice() + lineSep +
          "Our price: " + details[i].getOurPrice() + lineSep + 
          "Used price: " + (usedP == null ? "N/A" : usedP) + lineSep + lineSep;  
      
      }
      
      return results;