⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stockquoteservice.java

📁 《JAVA WEB服务应用开发详解》代码.zip
💻 JAVA
字号:
   //samples.stockquote.StockQuoteService.java
   package samples.stockquote;
   
   import java.net.URL;
   import java.io.*;
   import org.w3c.dom.*;
   import org.xml.sax.*;
   import javax.xml.parsers.*;
   import org.apache.soap.util.xml.*;
   
   /**
    * See \samples\stockquote\readme for info.
    *
    * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
    */
   public class StockQuoteService {
     DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
   
     public float getQuote (String symbol) throws Exception {
       // get a real (delayed by 20min) stockquote from 
       // http://www.xmltoday.com/examples/stockquote/. The IP addr 
       // below came from the host that the above form posts to ..
       URL url = new URL (
"http://www.xmltoday.com/examples/stockquote/getxmlquote.vep?s="+symbol);
       InputStream is = url.openStream ();
       Document d = xdb.parse(is);
       Element e = d.getDocumentElement ();
       NodeList nl = e.getElementsByTagName ("price");
       e = (Element) nl.item (0);
       String quoteStr = e.getAttribute ("value");
       try {
         return Float.valueOf (quoteStr).floatValue ();
       } catch (NumberFormatException e1) {
         // mebbe its an int?
         try {
   	return Integer.valueOf (quoteStr).intValue () * 1.0F;
         } catch (NumberFormatException e2) {
   	return -1.0F;
         }
       }
     }
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -