/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

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