Implementation of automatic upgrade of CS structure Software (IV.)

Source: Internet
Author: User
Tags config gettext

Realization of automatic upgrade of CS structure software (III.):

Config.java Processing configuration file:

1/** *//********************************************************************


2 * Project name:rochoc<p>


3 * Package name:com.rochoc.autoupdate<p>


4 * File name:config.java<p>


5 * Creator:kfzx-luoc<p>


6 * Written date:2008-12-22<p>


7 * Program function (Class) Description:<p>


8 * For updated profile reads like


9 * Program Change Date:


10 * Change Author:


11 * Change Note:


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/** *//**


* @author Kfzx-luoc


27 *


TODO to the "template for" generated type comment go to


* Window-preferences-java-code Style-code Templates


30 * *


31public class Config


32{


public static String cfgfile = ". \\config\\autoupdate.xml";


private static config config = null;


/** *//** XML document*/


private Document doc = null;


Notoginseng public static Config getinstance ()


38 {


(config==null)


40 {


config = new config ();


42}


return config;


44}


45


private Config ()


47 {


a try


49 {


Saxreader reader = new Saxreader ();


Wuyi doc = Reader.read (cfgfile);


}catch (Exception e)


53 {


E.printstacktrace ();


55}


56}


public void Refresh ()


58 {


config = new config ();


60}


-Public String getverstion ()


62 {


(config==null)


64 {


"";


66}


List lst = doc.selectnodes ("info/version");


-Element el = (Element) lst.get (0);


return El.gettext ();


70}


public String Getserverip ()


72 {



if (config==null)

74 {


"";


76}


List lst = doc.selectnodes ("INFO/UPDATESERVER/IP");


-Element el = (Element) lst.get (0);


-El.gettext ();


80}


Bayi public Updfile [] GetFiles ()


82 {


-if (config==null)


84 {


return null;


86}


List file = Doc.selectnodes ("Info/files");


List lst = ((Element) file.get (0)). elements ();


(Lst.size () ==0)


90 {


return null;


92}


updfile files[] = new updfile[lst.size ()];


for (int i=0;i<lst.size (); i++)


95 {


element el = (Element) lst.get (i);


The 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 ());


102 if ("File". Equals (El.getname ())


103 {


files[i].settype (0);//File


}else


106 {


Files[i].settype (1);//Directory


108}


109 Files[i].setpath (Path.gettext ());


files[i].setversion (Ver.gettext ());


111}


112 return files;


113}


114 Public String Getserverport ()


115 {


116 if (config==null)


117 {


118 return "";


119}


The List lst = doc.selectnodes ("Info/updateserver/port");


121 Element el = (Element) lst.get (0);


122 return El.gettext ();


123}


124 public static void print (String msg)


125 {


126 SimpleDateFormat sdf = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss->>");


127 String str = sdf.format (new Date ());


128 System.out.println (str+msg);


129}


130 public static void Main (String args[])


131 {


132 Config cfg = config.getinstance ();


updfile files[] = Cfg.getfiles ();


134 for (int i=0;i<files.length;i++)


135 {


136 System.out.println (files[i]);


137}


138 config.print ("Test");


139}


140/** *//**


141 * Format path, increase the tail of the directory separator


142 *


143 * @param p the directory string to format


144 * *


145 public static string Formatpath (String p)


146 {


147 if (!p.endswith (file.separator))


148 return (p + file.separator);


149 return p;


150}


151


152/** *//**


153 * Format path, remove the trailing directory separator


154 *


* @param p The directory string to format


156 * *


157 public static string Unformatpath (String p)


158 {


159 if (P.endswith (file.separator))


160 return (p.substring (0, P.length ()-1));


161 return p;


162}


163 public static byte[] Getcmd (String cmd)


164 {


165//First is used to identify the command, and the following 8-bit is the command name


166 byte CMDB [] = new byte[9];


167 Cmdb[0] = aupd. Cmd_data_sect;


byte [] tmp = Cmd.getbytes ();


169 if (tmp.length!=8)


170 {


171 Config.print ("Wrong order:" +cmd+ "<<");


172 return null;


173}


174 for (int i=0;i<8;i++)


175 {


176 cmdb[i+1] = Tmp[i];


177}


178 return CMDB;


179}


180 public static String Parsecmd (Byte cmd[])


181 {


a new String (cmd,0,8);


183}


184 public static byte [] Getlen (int len)


185 {


186 String Slen = string.valueof (len);


187 while (Slen.length () <4)


188 {


189 Slen = "0" +slen;


190}


191 return slen.getbytes ();


192}


193 public static void Copyarray (Byte objary[], byte souary[], int o_begin,


194 int S_begin, int len)


195 {


196 for (int i = 0; i < len; i++)


197 {


198 Objary[o_begin + i] = Souary[s_begin + i];


199}


200}


201}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.