- /*
- * Copyright 1999,2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /*
- * Created on 2007-2-14
- *
- */
- package peaklau.eaglefund;
- import java.util.Enumeration;
- import nanoxml.kXMLElement;
- /**
- * Display information of one's selected funds class<br>
- * <br>
- * First step, synchronize the newest fund's value from http://www.peaklau.com/fund/index.php .<br>
- * The request format is like this: http://www.peaklau.com/fund/index.php?C0=162703&C1=110002.<br>
- * The response from http://www.peaklau.com/fund/index.php is in XML format.<br>
- * <I> <VERSION>1.0.7 </VERSION><br>
- * <F><br>
- * <C>162703 </C><br>
- * <N>广发小盘成长股票基金 </N><br>
- * <D>2007-04-30 </D><br>
- * <V>21570 </V><br>
- * <P>11347 </P><br>
- * </F><br>
- * <F><br>
- * <C>110002 </C><br>
- * <N>xxx基金 </N><br>
- * <D>2007-04-30 </D><br>
- * <V>35940 </V><br>
- * <P>29504 </P><br>
- * </F><br>
- * </I><br>
- *
- * <br>
- *
- * Second step, parse XML data and update local records.<br>
- *
- * <br>
- *
- * Finally, call setTxt() to show the data and the processing time.
- * <br>
- * @author peaklau <br>
- * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
- * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
- * @version $Revision: 1.2 $ $Date: 2007/10/21 14:26:24 $
- */
- public class ValueScreen extends ScrollScreen {
- public ValueScreen(String title,String txt,String backDisplayable,INavigator navigator){
- super(title,txt,backDisplayable,navigator);
- }
- protected void execute(){
- setTxt(DataCenter.getValueDesc());
- String requestString=DataCenter.getFundRequestString();
- if((requestString==null)||(requestString.length()==0)) return;
- setStatus("正在同步...");
- HttpClient httpClient=navigator.getHttpClient();
- try{
- httpClient.httpGet("http://"+host+"/fund/index.php?"+requestString);
- byte[]buf=httpClient.getData();
- int size=httpClient.getSize();
- String xml=new String(buf,0,size,"UTF-8");
- kXMLElement foo = new kXMLElement();
- foo.parseString(xml, 0);
- Enumeration listFundEnum = foo.enumerateChildren();
- while (listFundEnum.hasMoreElements()) {
- kXMLElement fund= (kXMLElement)(listFundEnum.nextElement());
- if(fund.getTagName().equals("VERSION")){
- navigator.setAppVersion(fund.getContents());
- continue;
- }
- Enumeration list= fund.enumerateChildren();
- String code="000000";
- String name="未知";
- String date="未知";
- int value=0;
- int percent=0;
- while (list.hasMoreElements()) {
- kXMLElement p= (kXMLElement)(list.nextElement());
- if(p.getTagName().equals("C")){
- code=p.getContents();
- }else if(p.getTagName().equals("N")){
- name=p.getContents();
- }else if(p.getTagName().equals("D")){
- date=p.getContents();
- }else if(p.getTagName().equals("V")){
- value=Integer.parseInt(p.getContents());
- }else if(p.getTagName().equals("P")){
- percent=Integer.parseInt(p.getContents());
- }
- }
- DataCenter.updateRecord(code,name,date,value,percent);
- }
- }catch(Exception e){
- setStatus("网络故障");
- e.printStackTrace();
- return;
- }
- setTxt(DataCenter.getValueDesc());
- setStatus("同步完成时间 "+getCurrentTime());
- }
- }