KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > MVNCoreConfig


1 /*
2  * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/MVNCoreConfig.java,v 1.15 2006/04/15 02:59:18 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.15 $
5  * $Date: 2006/04/15 02:59:18 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding MyVietnam and MyVietnam CoreLib
12  * MUST remain intact in the scripts and source code.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  *
28  * Correspondence and Marketing Questions can be sent to:
29  * info at MyVietnam net
30  *
31  * @author: Phong Ta Quoc
32  */

33 package net.myvietnam.mvncore;
34
35 import java.io.File JavaDoc;
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 JavaDoc OPTION_FILE_NAME = "mvncore.xml";
47
48     /* <Module Options> */
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     /* <Database Options> */
60     private static boolean useDataSource = false;
61     public static boolean isUseDataSource() {
62         return useDataSource;
63     }
64
65     private static String JavaDoc dataSourceName = "";
66     public static String JavaDoc getDataSourceName() {
67         return dataSourceName;
68     }
69
70     // MUST NOT refer to DBUtils, or we will get an infinite recurse ???
71
private static int databaseType = 0;//DATABASE_UNKNOWN
72
public static int getDatabaseType() {
73         return databaseType;
74     }
75
76     private static String JavaDoc driverClassName = "com.mysql.jdbc.Driver";
77     public static String JavaDoc getDriverClassName() {
78         return driverClassName;
79     }
80
81     private static String JavaDoc databaseURL = "jdbc:mysql://localhost/mvnforum";
82     public static String JavaDoc getDatabaseURL() {
83         return databaseURL;
84     }
85
86     private static String JavaDoc databaseUser = "root";
87     public static String JavaDoc getDatabaseUser() {
88         return databaseUser;
89     }
90
91     private static String JavaDoc databasePassword = "";
92     public static String JavaDoc getDatabasePassword() {
93         return databasePassword;
94     }
95
96     private static int maxConnection = 20;
97     public static int getMaxConnection() {
98         return maxConnection;
99     }
100
101     /* by default, the unit of time is milisecond */
102     private static int maxTimeToWait = 2000;// 2 seconds
103
public static int getMaxTimeToWait() {
104         return maxTimeToWait;
105     }
106
107     private static int minutesBetweenRefresh = 30;// 30 minutes
108
public static int getMinutesBetweenRefresh() {
109         return minutesBetweenRefresh;
110     }
111     /* </Database Options> */
112
113     /* <Mail Options> */
114     private static boolean useMailSource = false;
115     public static boolean isUseMailSource() {
116         return useMailSource;
117     }
118
119     private static String JavaDoc mailSourceName = "";
120     public static String JavaDoc getMailSourceName() {
121         return mailSourceName;
122     }
123
124     private static String JavaDoc mailServer = "mail.yourdomain";
125     public static String JavaDoc 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 JavaDoc defaultMailFrom = "youruser@yourdomain";
135     public static String JavaDoc getDefaultMailFrom() {
136         return defaultMailFrom;
137     }
138
139     private static String JavaDoc mailUserName = "";// allow empty username
140
public static String JavaDoc getMailUserName() {
141         return mailUserName;
142     }
143
144     private static String JavaDoc mailPassword = "";
145     public static String JavaDoc getMailPassword() {
146         return mailPassword;
147     }
148     /* </Mail Options> */
149
150     /* <Param Options> */
151     private static String JavaDoc contextPath = "";// allow ROOT context
152
public static String JavaDoc getContextPath() {
153         return contextPath;
154     }
155
156     private static String JavaDoc serverPath = "http://localhost:8080";
157     public static String JavaDoc getServerPath() {
158         return serverPath;
159     }
160     /* <Param Options> */
161
162     /* <Date Options> */
163     /* the unit of the server offset is hour*/
164     private static int serverHourOffset = 0; /* GMT timezone */
165     public static int getServerHourOffset() {
166         return serverHourOffset;
167     }
168     /* </Date Options> */
169
170     /* <User Agent Options>*/
171     private static String JavaDoc blockedUserAgents = "";
172     public static String JavaDoc getBlockedUserAgents() {
173         return blockedUserAgents;
174     }
175     /* </User Agent Options>*/
176
177     /* <IP Options>*/
178     private static String JavaDoc blockedIPs = "";
179     public static String JavaDoc getBlockedIPs() {
180         return blockedIPs;
181     }
182     /* </IP Options>*/
183
184     /* <Interceptor> */
185     private static String JavaDoc mailInterceptorClassName = "";
186     public static String JavaDoc getMailInterceptorClassName() {
187         return mailInterceptorClassName;
188     }
189
190     private static String JavaDoc contentInterceptorClassName = "";
191     public static String JavaDoc getContentInterceptorClassName() {
192         return contentInterceptorClassName;
193     }
194
195     private static String JavaDoc loginInterceptorClassName = "";
196     public static String JavaDoc getLoginIdInterceptorClassName() {
197         return loginInterceptorClassName;
198     }
199     /* </Interceptor> */
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 JavaDoc portalType = "non-portal";//Portal.DEFAULT;
212
public static String JavaDoc getPortalType() {
213         return portalType;
214     }
215
216     private static String JavaDoc urlResolverClassName = "net.myvietnam.mvncore.web.impl.URLResolverServletImpl";
217     public static String JavaDoc getURLResolverClassName() {
218         return urlResolverClassName;
219     }
220
221     private static String JavaDoc uploadParserClassName = "net.myvietnam.mvncore.web.impl.FileUploadParserServletImpl";
222     public static String JavaDoc getUploadParserClassName() {
223         return uploadParserClassName;
224     }
225
226     private static String JavaDoc mvnCoreServiceClassName = "net.myvietnam.mvncore.service.impl.MvnCoreServiceImpl";
227     public static String JavaDoc 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 JavaDoc classPath = FileUtil.getServletClassesPath();
241         String JavaDoc configFilename = classPath + OPTION_FILE_NAME;
242         try {
243             DOM4JConfiguration conf = new DOM4JConfiguration(new File JavaDoc(configFilename));
244
245             /* <Plugin Options> */
246             enable_mvnforum = conf.getBoolean("plugin_options.enable_mvnforum", true);
247             enable_mvncms = conf.getBoolean("plugin_options.enable_mvncms", false);
248
249             /* <Database Options> */
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; //min is 1 minute
267
}
268             }
269             /* <Database Options> */
270
271             /* <Mail Options> */
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             /* </Mail Options> */
284
285             /* <Parameter Options> */
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             /* </Parameter Options> */
292
293             /* <Date Time Options> */
294             serverHourOffset = conf.getInt("dateoptions.server_hour_offset", serverHourOffset);
295             if ((serverHourOffset < -13) || (serverHourOffset > 13)) {
296                 serverHourOffset = 0;
297             }
298             /* </Date Time Options> */
299
300             /* <User Agent Options>*/
301             blockedUserAgents = conf.getString("useragentoptions.blocked_user_agent", blockedUserAgents);
302             /* </User Agent Options>*/
303
304             /* <IP Options>*/
305             blockedIPs = conf.getString("ipoptions.blocked_ip", blockedIPs);
306             /* </IP Options>*/
307
308             /* <Interceptor Options>*/
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             /* </Interceptor Options>*/
313
314             /* <MVNCore Options>*/
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             /* </MVNCore Options>*/
325         } catch (Exception JavaDoc e) {
326             String JavaDoc 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