source: other-projects/tipple-android/i-greenstone-server-files/greenstone/webapps/greenstone3/StockQuoteService.jws@ 26917

Last change on this file since 26917 was 26899, checked in by davidb, 11 years ago

Tipple reborn after Chris's Summer of Code 2013

File size: 1.9 KB
Line 
1/*
2 * Copyright 2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import org.apache.axis.utils.XMLUtils;
18import org.w3c.dom.Document;
19import org.w3c.dom.Element;
20import org.w3c.dom.NodeList;
21
22/**
23 * See \samples\stock\readme for info.
24 *
25 * @author Sanjiva Weerawarana ([email protected])
26 * @author Doug Davis ([email protected])
27 */
28public class StockQuoteService {
29 public float getQuote (String symbol) throws Exception {
30 // get a real (delayed by 20min) stockquote from
31 // http://www.xmltoday.com/examples/stockquote/. The IP addr
32 // below came from the host that the above form posts to ..
33
34 if ( symbol.equals("XXX") ) return( (float) 66.25 );
35
36
37 Document doc = null ;
38
39 doc = XMLUtils.newDocument( "http://www.xmltoday.com/examples/" +
40 "stockquote/getxmlquote.vep?s="+symbol );
41
42 Element elem = doc.getDocumentElement();
43 NodeList list = elem.getElementsByTagName("stock_quote");
44
45 elem = (Element) list.item(0);
46 list = elem.getElementsByTagName( "price" );
47 elem = (Element) list.item( 0 );
48 String quoteStr = elem.getAttribute("value");
49 try {
50 return Float.valueOf(quoteStr).floatValue();
51 } catch (NumberFormatException e1) {
52 // maybe its an int?
53 try {
54 return Integer.valueOf(quoteStr).intValue() * 1.0F;
55 } catch (NumberFormatException e2) {
56 return -1.0F;
57 }
58 }
59 }
60}
Note: See TracBrowser for help on using the repository browser.