CS潤更罷周徭強幅雫糞??膨?
扮寂:2011-06-29 blogjava rochoc
俊CS潤更罷周徭強幅雫糞??眉? ?
Config.java侃尖塘崔猟周?
1/** *//********************************************************************
2 * ?朕兆各 ?rochoc<p>
3 * 淫兆各 ?com.rochoc.autoupdate<p>
4 * 猟周兆各 ?Config.java<p>
5 * 園亟宀 ?kfzx-luoc<p>
6 * 園亟晩豚 ?2008-12-22<p>
7 * 殻會孔嬬?窃?宙峰 ?<p>
8 * 喘噐厚仟議塘崔猟周響函斤?
9 * 殻會延厚晩豚 ?
10 * 延厚恬宀 ?
11 * 延厚傍苧 ?
12********************************************************************/
13package com.rochoc.autoupdate;
14
15import java.io.File;
16import java.text.SimpleDateFormat;
17import java.util.Date;
18import java.util.List;
19
20import org.dom4j.Document;
21import org.dom4j.Element;
22import org.dom4j.io.SAXReader;
23
24
25/** *//**
26 * @author kfzx-luoc
27 *
28 * TODO To change the template for this generated type comment go to
29 * Window - Preferences - Java - Code Style - Code Templates
30 */
31public class Config
32{
33 public static String cfgFile = ".\\config\\autoupdate.xml";
34 private static Config config = null;
35 /** *//** xml議document*/
36 private Document doc = null;
37 public static Config getInstance()
38 {
39 if(config==null)
40 {
41 config = new Config();
42 }
43 return config;
44 }
45
46 private Config()
47 {
48 try
49 {
50 SAXReader reader = new SAXReader();
51 doc = reader.read(cfgFile);
52 }catch(Exception e)
53 {
54 e.printStackTrace();
55 }
56 }
57 public void refresh()
58 {
59 config = new Config();
60 }
61 public String getVerstion()
62 {
63 if(config==null)
64 {
65 return "";
66 }
67 List lst = doc.selectNodes("Info/Version");
68 Element el = (Element)lst.get(0);
69 return el.getText();
70 }
71 public String getServerIp()
72 {
73 if(config==null)
74 {
75 return "";
76 }
77 List lst = doc.selectNodes("Info/UpdateServer/Ip");
78 Element el = (Element)lst.get(0);
79 return el.getText();
80 }
81 public UpdFile [] getFiles()
82 {
83 if(config==null)
84 {
85 return null;
86 }
87 List file = doc.selectNodes("Info/Files");
88 List lst = ((Element)file.get(0)).elements();
89 if(lst.size()==0)
90 {
91 return null;
92 }
93 UpdFile files[] = new UpdFile[lst.size()];
94 for(int i=0;i<lst.size();i++)
95 {
96 Element el = (Element)lst.get(i);
97 List childs = el.elements();
98 Element name = (Element)childs.get(0);//Name
99 Element
|