FileDocCategorySizeDatePackage
StockPriceBean.javaAPI DocExample4864Mon Sep 08 13:51:24 BST 2003com.jspservletcookbook

StockPriceBean

public class StockPriceBean extends Object

Fields Summary
private static final String
urlBase
The URL base for requesting a stock price; it looks like "http://finance.yahoo.com/q?d=t&s="
private BufferedReader
webPageStream
The character stream of HTML that is parsed for the stock price returned by java.net.URL.openStream() see java.net.URL
private URL
stockSite
The java.net.URL object that represents the stock Web page
private ParserDelegator
htmlParser
The ParserDelegator object for which ParserDelegator.parse() is called for the Web page
private MyParserCallback
callback
The MyParserCallback object (inner class); this object is an argument to the ParserDelegator.parse() method
private String
htmlText
This String holds the HTML text as the Web page is parsed.
private String
symbol
private float
stockVal
Constructors Summary
public StockPriceBean()


  //A JavaBean has to have a no-args constructor (we explicitly show this 
  //constructor as a reminder; the compiler would have generated a default
  //constructor with no arguments automatically
    
Methods Summary
public floatgetLatestPrice()


      stockSite = new URL(urlBase + symbol);
       
      webPageStream = new BufferedReader(new InputStreamReader(stockSite.
       openStream()));
	   
      htmlParser = new ParserDelegator();
	   
      callback = new MyParserCallback();//ParserCallback
	   
      synchronized(htmlParser){	
	
          htmlParser.parse(webPageStream,callback,true);

	     }//synchronized
	   
	  //reset symbol
	  symbol = "";

     return stockVal;

  
public voidsetSymbol(java.lang.String symbol)

	
      this.symbol = symbol;