PageRenderTime 42ms CodeModel.GetById 18ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ictclas4j/src/org/ictclas4j/run/Config.java

http://ictclas4j.googlecode.com/
Java | 172 lines | 142 code | 27 blank | 3 comment | 18 complexity | 44487a517c32182ec704dc38481c9dc8 MD5 | raw file
  1package org.ictclas4j.run;
  2
  3import java.io.IOException;
  4import java.util.Calendar;
  5import java.util.Date;
  6
  7import org.apache.log4j.Logger;
  8
  9import com.gftech.util.GFDate;
 10import com.gftech.util.GFFile;
 11import com.gftech.util.GFFinal;
 12import com.gftech.util.GFString;
 13
 14public class Config {
 15	public static final String LOG4J_CONF = "conf"+GFFinal.FILE_SEP+"log4j.properties";
 16
 17	public static final String confFile = "conf"+GFFinal.FILE_SEP+"config.properties";
 18
 19	public static final String dbFile = "conf"+GFFinal.FILE_SEP+"database.properties";
 20
 21	static Logger logger = Logger.getLogger(Config.class);
 22
 23	public static void main(String[] args) {
 24		System.out.println(valid_percent());
 25	}
 26
 27	public static int listen_port() {
 28		int port = 1990;
 29		if (confFile != null) {
 30			try {
 31				String sport = GFFile.getConfig(confFile, "listen_port");
 32				port = GFString.cint(sport);
 33			} catch (IOException e) {
 34				 logger.error("load listen port",e);
 35			}
 36		}
 37
 38		return port;
 39	}
 40
 41	public static String db_driver() {
 42		if (dbFile != null) {
 43			try {
 44				return GFFile.getConfig(dbFile, "driver_oracle");
 45			} catch (IOException e) {
 46				 logger.error("load database driver",e);
 47			}
 48		}
 49		return null;
 50	}
 51
 52	public static String db5_url() {
 53		if (dbFile != null) {
 54			try {
 55				return GFFile.getConfig(dbFile, "db5_url");
 56			} catch (IOException e) {
 57				 logger.error("load db5 url",e);
 58			}
 59		}
 60		return null;
 61	}
 62
 63	public static String db5_user() {
 64		if (dbFile != null) {
 65			try {
 66				return GFFile.getConfig(dbFile, "db5_user");
 67			} catch (IOException e) {
 68				 logger.error("load db5 user",e);
 69			}
 70		}
 71		return null;
 72	}
 73
 74	public static String db5_pwd() {
 75		if (dbFile != null) {
 76			try {
 77				return GFFile.getConfig(dbFile, "db5_pwd");
 78			} catch (IOException e) {
 79				 logger.error("load db5 pwd",e);
 80			}
 81		}
 82		return null;
 83	}
 84	
 85	public static String pkg_name() {
 86		if (confFile != null) {
 87			try {
 88				return GFFile.getConfig(confFile, "pkg_name");
 89			} catch (IOException e) {
 90				 logger.error("load package name",e);
 91			}
 92		}
 93		return null;
 94	}
 95
 96	// ??????????????
 97	public static double valid_percent() {
 98		if (confFile != null) {
 99			try {
100				String temp = GFFile.getConfig(confFile, "valid_percent");
101				return Double.parseDouble(temp);
102			} catch (IOException e) {
103				 logger.error("load valid percent",e);
104			} catch (NumberFormatException e) {
105				 logger.error("load valid percent",e);
106			}
107		}
108		return 0;
109	}
110
111	public static Date update_keys_time() {
112		Date update_keys_date = null;
113
114		// set timer to load keys from database
115		Calendar cal = Calendar.getInstance();
116		cal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
117		cal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
118		int runDate = cal.get(Calendar.DAY_OF_MONTH);
119		cal.set(Calendar.DAY_OF_MONTH, runDate + 1);
120		
121
122		try {
123			String temp = GFFile.getConfig(confFile, "update_keys_time");
124			Calendar uc = GFDate.cdate(temp);
125
126			// ??????????????????????????????????
127			if (uc.get(Calendar.HOUR_OF_DAY) > cal.get(Calendar.HOUR_OF_DAY)||uc.get(Calendar.HOUR_OF_DAY) == cal.get(Calendar.HOUR_OF_DAY)&&
128					uc.get(Calendar.MINUTE)>cal.get(Calendar.MINUTE))
129				cal.set(Calendar.DAY_OF_MONTH, runDate);
130			cal.set(Calendar.HOUR_OF_DAY, uc.get(Calendar.HOUR_OF_DAY));
131			cal.set(Calendar.MINUTE, uc.get(Calendar.MINUTE));
132			cal.set(Calendar.SECOND, uc.get(Calendar.SECOND));
133			logger.info("update_keys_time:" + GFDate.cdate(cal, "yyyy-mm-dd hh24:mi:ss"));
134		} catch (IOException e) {
135			logger.error("load update keys time",e);
136			cal.set(Calendar.HOUR_OF_DAY, 2);
137		} catch (NullPointerException e) {
138			logger.error("load update keys time",e);
139			cal.set(Calendar.HOUR_OF_DAY, 2);
140		}
141
142		update_keys_date = new Date(cal.getTimeInMillis());
143		return update_keys_date;
144	}
145
146	public static int update_keys_interval() {
147		int update_keys_interval = 1440;
148
149		try {
150			int interval = GFString.cint(GFFile.getConfig(confFile, "update_keys_interval"));
151			if (update_keys_interval > 0)
152				update_keys_interval = interval;
153		} catch (IOException e) {
154			logger.error("update keys interval:", e);
155		}
156
157		return update_keys_interval;
158	}
159	
160	public boolean isShowFrm(){
161		boolean result = false;
162		try {
163			String temp = GFFile.getConfig(confFile, "is_show_frm");
164			if("1".equals(temp))
165					result=true;
166		} catch (IOException e) { 
167			logger.error("load is show frame ",e);
168		}
169
170		return result;
171	}
172}