原文:http://www.blogjava.net/rochoc/archive/2009/01/09/250741.html
Config.java处理配置文件:
/** *//********************************************************************
* 项目名称 :rochoc<p>
* 包名称 :com.rochoc.autoupdate<p>
* 文件名称 :Config.java<p>
* 编写者 :kfzx-luoc<p>
* 编写日期 :2008-12-22<p>
* 程序功能(类)描述 :<p>
* 用于更新的配置文件读取对像
* 程序变更日期 :
* 变更作者 :
* 变更说明 :
********************************************************************/
package com.rochoc.autoupdate;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
/** *//**
* @author kfzx-luoc
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Config
{
public static String cfgFile = ".\\config\\autoupdate.xml";
private static Config config = null;
/** *//** xml的document*/
private Document doc = null;
public static Config getInstance()
{
if(config==null)
{
config = new Config();
}
return config;
}
private Config()
{
try
{
SAXReader reader = new SAXReader();
doc = reader.read(cfgFile);
}catch(Exception e)
{
e.printStackTrace();
}
}
public void refresh()
{
config = new Config();
}
public String getVerstion()
{
if(config==null)
{
return "";
}
List lst = doc.selectNodes("Info/Version");
Element el = (Element)lst.get(0);
return el.getText();
}
public String getServerIp()
{
if(config==null)
{
return "";
}
List lst = doc.selectNodes("Info/UpdateServer/Ip");
Element el = (Element)lst.get(0);
return el.getText();
}
public UpdFile [] getFiles()
{
if(config==null)
{
return null;
}
List file = doc.selectNodes("Info/Files");
List lst = ((Element)file.get(0)).elements();
if(lst.size()==0)
{
return null;
}
UpdFile files[] = new UpdFile[lst.size()];
for(int i=0;i<lst.size();i++)
{
Element el = (Element)lst.get(i);
List childs = el.elements();
Element name = (Element)childs.get(0);//Name
Element path = (Element)childs.get(1);//Path
Element ver = (Element)childs.get(2);//Version
files[i] = new UpdFile(name.getText());
if("File".equals(el.getName()))
{
files[i].setType(0);//文件
}else
{
files[i].setType(1);//目录
}
files[i].setPath(path.getText());
files[i].setVersion(ver.getText());
}
return files;
}
public String getServerPort()
{
if(config==null)
{
return "";
}
List lst = doc.selectNodes("Info/UpdateServer/Port");
Element el = (Element)lst.get(0);
return el.getText();
}
public static void print(String msg)
{
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss->>" );
String str = sdf.format( new Date());
System.out.println(str+msg);
}
public static void main(String args[])
{
Config cfg = Config.getInstance();
UpdFile files[] = cfg.getFiles();
for(int i=0;i<files.length;i++)
{
System.out.println(files[i]);
}
Config.print("test");
}
/** *//**
* 格式化路径,增加其尾部的目录分隔符
*
* @param p 要格式化的目录字符串
*/
public static String formatPath(String p)
{
if (!p.endsWith(File.separator))
return (p + File.separator);
return p;
}
/** *//**
* 格式化路径,去除其尾部的目录分隔符
*
* @param p 要格式化的目录字符串
*/
public static String unformatPath(String p)
{
if (p.endsWith(File.separator))
return (p.substring(0, p.length()-1));
return p;
}
public static byte[] getCmd(String cmd)
{
//第一位用于标识是命令,后面8位为命令名
byte cmdb [] = new byte[9];
cmdb[0] = AUPD.CMD_DATA_SECT;
byte [] tmp = cmd.getBytes();
if(tmp.length!=8)
{
Config.print("命令有误:"+cmd+"<<");
return null;
}
for(int i=0;i<8;i++)
{
cmdb[i+1] = tmp[i];
}
return cmdb;
}
public static String parseCmd(byte cmd[])
{
return new String(cmd,0,8);
}
public static byte [] getLen(int len)
{
String slen = String.valueOf(len);
while(slen.length()<4)
{
slen = "0"+slen;
}
return slen.getBytes();
}
public static void copyArray(byte objary[], byte souary[], int o_begin,
int s_begin, int len)
{
for (int i = 0; i < len; i++)
{
objary[o_begin + i] = souary[s_begin + i];
}
}
}
UpdFile.java:这个类本来是想作为对象直接在服务端和客户端之间传递的,但后来没有采用,因此在本实现中用处不大
/** *//********************************************************************
* 项目名称 :rochoc<p>
* 包名称 :com.rochoc.autoupdate<p>
* 文件名称 :UpdFile.java<p>
* 编写者 :kfzx-luoc<p>
* 编写日期 :2008-12-23<p>
* 程序功能(类)描述 :<p>
* 版本文件对像
* 程序变更日期 :
* 变更作者 :
* 变更说明 :
********************************************************************/
package com.rochoc.autoupdate;
import java.io.Serializable;
/** *//**
* @author kfzx-luoc
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class UpdFile implements Serializable
{
private String name = "";//名称
private String path = "";//路径
private int type = 0;//类型 0.文件 1.目录
private String version = "";//版本号
public UpdFile()
{
super();
}
public UpdFile(String name)
{
this();
this.name = name;
}
public UpdFile(String name,String path,int type,String version)
{
this(name);
this.path = path;
this.type = type;
this.version = version;
}
/** *//**
* @return Returns the name.
*/
public String getName()
{
return name;
}
/** *//**
* @param name The name to set.
*/
public void setName(String name)
{
this.name = name;
}
/** *//**
* @return Returns the path.
*/
public String getPath()
{
return path;
}
/** *//**
* @param path The path to set.
*/
public void setPath(String path)
{
this.path = path;
}
/** *//**
* @return Returns the type.
*/
public int getType()
{
return type;
}
/** *//**
* @param type The type to set.
*/
public void setType(int type)
{
this.type = type;
}
/** *//**
* @return Returns the version.
*/
public String getVersion()
{
return version;
}
/** *//**
* @param version The version to set.
*/
public void setVersion(String version)
{
this.version = version;
}
public String toString()
{
return "Name:"+getName()+",Path:"+getPath()
+",Type:"+getType()+",Version:"+getVersion();
}
}
《CS结构软件自动升级实现》已经全部写完
分享到:
相关推荐
MOPAC模块:单点、几何优化、振动频率和COSMO实现并行,周期边界条件。 操作平台:Unix/Linux/Windows Mopac 2002 (通用半经验量子力学程序) 【URL】 http://www.cachesoftware.com/mopac/index.shtml ...
捆绑一般电子教室软件没有的网络考试和在线考试系统,实现自动评分的无纸化考试; B/S结构的考试系统,出卷和考试都在浏览器上完成,所有用户之间还能共享和交换试卷; 用户可以使用软件厂商提供的考试服务器,无须...
捆绑一般电子教室软件没有的网络考试和在线考试系统,实现自动评分的无纸化考试; B/S结构的考试系统,出卷和考试都在浏览器上完成,所有用户之间还能共享和交换试卷; 用户可以自行搭建考试服务器,也可以使用软件...
捆绑一般电子教室软件没有的网络考试和在线考试系统,实现自动评分的无纸化考试; B/S结构的考试系统,出卷和考试都在浏览器上完成,所有用户之间还能共享和交换试卷; 用户可以使用软件厂商提供的考试服务器,无须...
HttpModule 实现 ASP.Net (*.aspx) 中文简繁体的自动转换,不用修改原有的任何代码,直接部署即可! 服务器自定义开发二之客户端脚本回发 Web开发: 使用URL重写WEB主题切换 如何在Asp.Net1.1中实现页面模板(所谓的...
红蜘蛛软件主要在局域网络上实现多媒体信息的教学广播,是一款实现在电子教室、多媒体网络教室或者电脑教室中进行多媒体网络教学的非常好的软件产品,集电脑教室的同步教学、控制、管理、音视频广播、网络考试等功能...
·后台管理模块升级 ·优化网页,避免了现在某些服务商空间屏蔽嵌套页 ·文件归类优化 ·增加转向页 ver2.6.4 ·增加批量审核网站(感谢风之恋曲) ·针对网站界面模板优化代码 ver2.6.1 ·重构前台样式实现程序换肤...
HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空(null)键值(key),由于非线程安全,效率上可能高于Hashtable。 HashMap允许将null作为一个entry的key或者...
15.4 接口的实现 .182 15.5 抽象类与接口 .195 15.6 小 结 .196 第十六章 组织应用程序 .198 16.1 基 本 概 念 .198 16.2 使用名字空间 .200 16.3 使用指示符 .203 16.4 程 序 示 例 .206 16.5 小 ...
HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空(null)键值(key),由于非线程安全,效率上可能高于Hashtable。 HashMap允许将null作为一个entry的key或者...
7482 网吧维护\资料\xp实用技巧\升级到Windows XP应该考虑的6个方面.txt 2586 网吧维护\资料\xp实用技巧\双剑合璧 在Win XP下刻录音乐CD.txt 455 网吧维护\资料\xp实用技巧\取消WinXP专业版中的保留的带宽.txt 6217 ...
cs.ec DES加密模块 1.0.ec DIY热键框模块.ec DLL注入模块.ec DOS命令模块.ec EC.EC EdbServer1.0客户端.ec EDB、高级表格、XLS互换.ec edb到html-1.0.ec EDB数据库客户端模块 1.0.ec edb数据库转Excel...
Arhz_自动更新.ec Base64编解码.ec BASE64编解码模块.ec Bios.ec Bios 信息.ec BMP加密数据.ec BMP滤镜模块.ec BOX.EC BPL专用更新模块.ec BPL综合模 块.ec BPL高级模块.ec ButtonEx.ec bzfec.ec cards.ec change.ec...
Arhz_自动更新.ec Base64编解码.ec BASE64编解码模块.ec Bios.ec Bios 信息.ec BMP加密数据.ec BMP滤镜模块.ec BOX.EC BPL专用更新模块.ec BPL综合模 块.ec BPL高级模块.ec ButtonEx.ec bzfec.ec cards.ec change.ec...
install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户。 2.格式 (1)install [选项]... 来源 目的地 (2)install [选项]... 来源... 目录 (3)install -d [选项]... 目录... 在前两种格式中,会...
using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Data; using System.Drawing;...using System.Windows.Forms;...using System.Runtime.InteropServices;...
2004-08-11 00:34 1667 598 易语言模块大全\cs.ec 2005-10-21 15:30 4047 1417 易语言模块大全\DES加密模块 1.0.ec 2005-08-06 14:55 12387 3460 易语言模块大全\DIY热键框模块.ec 2005-10-21 15:30 10219 3288 ...
2004-08-11 00:34 1667 598 易语言模块大全\cs.ec 2005-10-21 15:30 4047 1417 易语言模块大全\DES加密模块 1.0.ec 2005-08-06 14:55 12387 3460 易语言模块大全\DIY热键框模块.ec 2005-10-21 15:30 10219 3288 ...