1 33 package net.myvietnam.mvncore; 34 35 import java.io.File ; 36 37 import net.myvietnam.mvncore.configuration.DOM4JConfiguration; 38 import net.myvietnam.mvncore.util.FileUtil; 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 public class MVNCoreConfig { 43 44 private static Log log = LogFactory.getLog(MVNCoreConfig.class); 45 46 final static String OPTION_FILE_NAME = "mvncore.xml"; 47 48 49 private static boolean enable_mvnforum = true; 50 public static boolean getEnableMVNForum() { 51 return enable_mvnforum; 52 } 53 54 private static boolean enable_mvncms = false; 55 public static boolean getEnableMVNCMS() { 56 return enable_mvncms; 57 } 58 59 60 private static boolean useDataSource = false; 61 public static boolean isUseDataSource() { 62 return useDataSource; 63 } 64 65 private static String dataSourceName = ""; 66 public static String getDataSourceName() { 67 return dataSourceName; 68 } 69 70 private static int databaseType = 0; public static int getDatabaseType() { 73 return databaseType; 74 } 75 76 private static String driverClassName = "com.mysql.jdbc.Driver"; 77 public static String getDriverClassName() { 78 return driverClassName; 79 } 80 81 private static String databaseURL = "jdbc:mysql://localhost/mvnforum"; 82 public static String getDatabaseURL() { 83 return databaseURL; 84 } 85 86 private static String databaseUser = "root"; 87 public static String getDatabaseUser() { 88 return databaseUser; 89 } 90 91 private static String databasePassword = ""; 92 public static String getDatabasePassword() { 93 return databasePassword; 94 } 95 96 private static int maxConnection = 20; 97 public static int getMaxConnection() { 98 return maxConnection; 99 } 100 101 102 private static int maxTimeToWait = 2000; public static int getMaxTimeToWait() { 104 return maxTimeToWait; 105 } 106 107 private static int minutesBetweenRefresh = 30; public static int getMinutesBetweenRefresh() { 109 return minutesBetweenRefresh; 110 } 111 112 113 114 private static boolean useMailSource = false; 115 public static boolean isUseMailSource() { 116 return useMailSource; 117 } 118 119 private static String mailSourceName = ""; 120 public static String getMailSourceName() { 121 return mailSourceName; 122 } 123 124 private static String mailServer = "mail.yourdomain"; 125 public static String getMailServer() { 126 return mailServer; 127 } 128 129 private static int mailServerPort = 25; 130 public static int getMailServerPort() { 131 return mailServerPort; 132 } 133 134 private static String defaultMailFrom = "youruser@yourdomain"; 135 public static String getDefaultMailFrom() { 136 return defaultMailFrom; 137 } 138 139 private static String mailUserName = ""; public static String getMailUserName() { 141 return mailUserName; 142 } 143 144 private static String mailPassword = ""; 145 public static String getMailPassword() { 146 return mailPassword; 147 } 148 149 150 151 private static String contextPath = ""; public static String getContextPath() { 153 return contextPath; 154 } 155 156 private static String serverPath = "http://localhost:8080"; 157 public static String getServerPath() { 158 return serverPath; 159 } 160 161 162 163 164 private static int serverHourOffset = 0; 165 public static int getServerHourOffset() { 166 return serverHourOffset; 167 } 168 169 170 171 private static String blockedUserAgents = ""; 172 public static String getBlockedUserAgents() { 173 return blockedUserAgents; 174 } 175 176 177 178 private static String blockedIPs = ""; 179 public static String getBlockedIPs() { 180 return blockedIPs; 181 } 182 183 184 185 private static String mailInterceptorClassName = ""; 186 public static String getMailInterceptorClassName() { 187 return mailInterceptorClassName; 188 } 189 190 private static String contentInterceptorClassName = ""; 191 public static String getContentInterceptorClassName() { 192 return contentInterceptorClassName; 193 } 194 195 private static String loginInterceptorClassName = ""; 196 public static String getLoginIdInterceptorClassName() { 197 return loginInterceptorClassName; 198 } 199 200 201 private static boolean enableLinkNofollow = false; 202 public static boolean getEnableLinkNofollow() { 203 return enableLinkNofollow; 204 } 205 206 private static boolean enableEncodeURL = true; 207 public static boolean getEnableEncodeURL() { 208 return enableEncodeURL; 209 } 210 211 private static String portalType = "non-portal"; public static String getPortalType() { 213 return portalType; 214 } 215 216 private static String urlResolverClassName = "net.myvietnam.mvncore.web.impl.URLResolverServletImpl"; 217 public static String getURLResolverClassName() { 218 return urlResolverClassName; 219 } 220 221 private static String uploadParserClassName = "net.myvietnam.mvncore.web.impl.FileUploadParserServletImpl"; 222 public static String getUploadParserClassName() { 223 return uploadParserClassName; 224 } 225 226 private static String mvnCoreServiceClassName = "net.myvietnam.mvncore.service.impl.MvnCoreServiceImpl"; 227 public static String getMvnCoreServiceClassName() { 228 return mvnCoreServiceClassName; 229 } 230 231 static { 232 load(); 233 } 234 235 public static void load() { 236 reload(); 237 } 238 239 public static void reload() { 240 String classPath = FileUtil.getServletClassesPath(); 241 String configFilename = classPath + OPTION_FILE_NAME; 242 try { 243 DOM4JConfiguration conf = new DOM4JConfiguration(new File (configFilename)); 244 245 246 enable_mvnforum = conf.getBoolean("plugin_options.enable_mvnforum", true); 247 enable_mvncms = conf.getBoolean("plugin_options.enable_mvncms", false); 248 249 250 useDataSource = conf.getBoolean("dboptions.use_datasource", false); 251 databaseType = conf.getInt("dboptions.database_type", 0); 252 253 if (useDataSource) { 254 dataSourceName = conf.getString("dboptions.datasource_name"); 255 } else { 256 driverClassName = conf.getString("dboptions.driver_class_name", driverClassName); 257 databaseURL = conf.getString("dboptions.database_url", databaseURL); 258 databaseUser = conf.getString("dboptions.database_user", databaseUser); 259 databasePassword = conf.getString("dboptions.database_password",databasePassword); 260 261 maxConnection = conf.getInt("dboptions.max_connection", maxConnection); 262 maxTimeToWait = conf.getInt("dboptions.max_time_to_wait", maxTimeToWait); 263 264 minutesBetweenRefresh = conf.getInt("dboptions.minutes_between_refresh", minutesBetweenRefresh); 265 if (minutesBetweenRefresh < 1) { 266 minutesBetweenRefresh = 1; } 268 } 269 270 271 272 useMailSource = conf.getBoolean("mailoptions.use_mailsource", false); 273 274 if (useMailSource) { 275 mailSourceName = conf.getString("mailoptions.mailsource_name"); 276 } else { 277 mailServer = conf.getString("mailoptions.mail_server", mailServer); 278 defaultMailFrom = conf.getString("mailoptions.default_mail_from", defaultMailFrom); 279 mailUserName = conf.getString("mailoptions.username", mailUserName); 280 mailPassword = conf.getString("mailoptions.password", mailPassword); 281 mailServerPort = conf.getInt("mailoptions.port", mailServerPort); 282 } 283 284 285 286 contextPath = conf.getString("paramoptions.context_path", contextPath); 287 serverPath = conf.getString("paramoptions.server_path", serverPath); 288 if (serverPath.endsWith("/")) { 289 serverPath = serverPath.substring(0, serverPath.length() - 1); 290 } 291 292 293 294 serverHourOffset = conf.getInt("dateoptions.server_hour_offset", serverHourOffset); 295 if ((serverHourOffset < -13) || (serverHourOffset > 13)) { 296 serverHourOffset = 0; 297 } 298 299 300 301 blockedUserAgents = conf.getString("useragentoptions.blocked_user_agent", blockedUserAgents); 302 303 304 305 blockedIPs = conf.getString("ipoptions.blocked_ip", blockedIPs); 306 307 308 309 mailInterceptorClassName = conf.getString("interceptor.mailinterceptor_implementation", mailInterceptorClassName); 310 contentInterceptorClassName = conf.getString("interceptor.contentinterceptor_implementation", contentInterceptorClassName); 311 loginInterceptorClassName = conf.getString("interceptor.loginidinterceptor_implementation", loginInterceptorClassName); 312 313 314 315 enableLinkNofollow = conf.getBoolean("mvncoreconfig.enable_link_nofollow", false); 316 enableEncodeURL = conf.getBoolean("mvncoreconfig.enable_encode_url", true); 317 portalType = conf.getString("mvncoreconfig.portal_type", portalType); 318 319 urlResolverClassName = conf.getString("mvncoreconfig.urlresolver_implementation", urlResolverClassName); 320 321 uploadParserClassName = conf.getString("mvncoreconfig.uploadparser_implementation", uploadParserClassName); 322 323 mvnCoreServiceClassName = conf.getString("mvncoreconfig.mvncoreservice_implementation", mvnCoreServiceClassName); 324 325 } catch (Exception e) { 326 String message = "com.mvnforum.MVNCoreConfig: Can't read the configuration file: '" + configFilename + "'. Make sure the file is in your CLASSPATH"; 327 log.error(message, e); 328 } 329 } 330 } 331 | Popular Tags |