Source Code Cross Referenced for MVNCoreConfig.java in  » Forum » mvnforum-1.1 » net » myvietnam » mvncore » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Forum » mvnforum 1.1 » net.myvietnam.mvncore 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/MVNCoreConfig.java,v 1.34 2008/01/24 02:35:41 minhnn Exp $
003:         * $Author: minhnn $
004:         * $Revision: 1.34 $
005:         * $Date: 2008/01/24 02:35:41 $
006:         *
007:         * ====================================================================
008:         *
009:         * Copyright (C) 2002-2007 by MyVietnam.net
010:         *
011:         * All copyright notices regarding MyVietnam and MyVietnam CoreLib
012:         * MUST remain intact in the scripts and source code.
013:         *
014:         * This library is free software; you can redistribute it and/or
015:         * modify it under the terms of the GNU Lesser General Public
016:         * License as published by the Free Software Foundation; either
017:         * version 2.1 of the License, or (at your option) any later version.
018:         *
019:         * This library is distributed in the hope that it will be useful,
020:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
021:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
022:         * Lesser General Public License for more details.
023:         *
024:         * You should have received a copy of the GNU Lesser General Public
025:         * License along with this library; if not, write to the Free Software
026:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
027:         *
028:         * Correspondence and Marketing Questions can be sent to:
029:         * info at MyVietnam net
030:         *
031:         * @author: Phong Ta Quoc  
032:         */
033:        package net.myvietnam.mvncore;
034:
035:        import java.io.File;
036:        import java.lang.reflect.Method;
037:        import java.util.*;
038:
039:        import net.myvietnam.mvncore.configuration.DOM4JConfiguration;
040:        import net.myvietnam.mvncore.util.*;
041:
042:        import org.apache.commons.logging.Log;
043:        import org.apache.commons.logging.LogFactory;
044:
045:        public class MVNCoreConfig {
046:
047:            private static Log log = LogFactory.getLog(MVNCoreConfig.class);
048:
049:            final static String OPTION_FILE_NAME = "mvncore.xml";
050:
051:            /* <Database Options> */
052:            private static boolean useDataSource = false;
053:
054:            public static boolean isUseDataSource() {
055:                return useDataSource;
056:            }
057:
058:            public static void setUseDataSource(boolean useDataSource) {
059:                MVNCoreConfig.useDataSource = useDataSource;
060:            }
061:
062:            private static String dataSourceName = "";
063:
064:            public static String getDataSourceName() {
065:                return dataSourceName;
066:            }
067:
068:            public static void setDataSourceName(String dataSourceName) {
069:                MVNCoreConfig.dataSourceName = dataSourceName;
070:            }
071:
072:            // MUST NOT refer to DBUtils, or we will get an infinite recurse ???
073:            private static int databaseType = 0;//DATABASE_UNKNOWN
074:
075:            public static int getDatabaseType() {
076:                return databaseType;
077:            }
078:
079:            public static void setDatabaseType(int databaseType) {
080:                MVNCoreConfig.databaseType = databaseType;
081:            }
082:
083:            private static String driverClassName = "com.mysql.jdbc.Driver";
084:
085:            public static String getDriverClassName() {
086:                return driverClassName;
087:            }
088:
089:            public static void setDriverClassName(String driverClassName) {
090:                MVNCoreConfig.driverClassName = driverClassName;
091:            }
092:
093:            private static String databaseURL = "jdbc:mysql://localhost/mvnforum";
094:
095:            public static String getDatabaseURL() {
096:                return databaseURL;
097:            }
098:
099:            public static void setDatabaseURL(String databaseURL) {
100:                MVNCoreConfig.databaseURL = databaseURL;
101:            }
102:
103:            private static String databaseUser = "root";
104:
105:            public static String getDatabaseUser() {
106:                return databaseUser;
107:            }
108:
109:            public static void setDatabaseUser(String databaseUser) {
110:                MVNCoreConfig.databaseUser = databaseUser;
111:            }
112:
113:            private static String databasePassword = "";
114:
115:            public static String getDatabasePassword() {
116:                return databasePassword;
117:            }
118:
119:            public static void setDatabasePassword(String databasePassword) {
120:                MVNCoreConfig.databasePassword = databasePassword;
121:            }
122:
123:            private static int maxConnection = 20;
124:
125:            public static int getMaxConnection() {
126:                return maxConnection;
127:            }
128:
129:            public static void setMaxConnection(int maxConnection) {
130:                MVNCoreConfig.maxConnection = maxConnection;
131:            }
132:
133:            /* by default, the unit of time is millisecond */
134:            private static int maxTimeToWait = 2000;// 2 seconds
135:
136:            public static int getMaxTimeToWait() {
137:                return maxTimeToWait;
138:            }
139:
140:            public static void setMaxTimeToWait(int maxTimeToWait) {
141:                MVNCoreConfig.maxTimeToWait = maxTimeToWait;
142:            }
143:
144:            private static int minutesBetweenRefresh = 30;// 30 minutes
145:
146:            public static int getMinutesBetweenRefresh() {
147:                return minutesBetweenRefresh;
148:            }
149:
150:            public static void setMinutesBetweenRefresh(
151:                    int minutesBetweenRefresh) {
152:                MVNCoreConfig.minutesBetweenRefresh = minutesBetweenRefresh;
153:            }
154:
155:            /* </Database Options> */
156:
157:            /* <Mail_Options> */
158:            private static MailConfig receiveMail = new MailConfig(
159:                    "receive_mail");
160:
161:            public static MailConfig getReceiveMailConfig() {
162:                return receiveMail;
163:            }
164:
165:            public static void setReceiveMail(MailConfig receiveMail) {
166:                MVNCoreConfig.receiveMail = receiveMail;
167:            }
168:
169:            private static MailConfig sendMail = new MailConfig("send_mail");
170:
171:            public static MailConfig getSendMailConfig() {
172:                return sendMail;
173:            }
174:
175:            public static void setSendMail(MailConfig sendMail) {
176:                MVNCoreConfig.sendMail = sendMail;
177:            }
178:
179:            private static String defaultMailFrom = "youruser@yourdomain";
180:
181:            public static String getDefaultMailFrom() {
182:                return defaultMailFrom;
183:            }
184:
185:            public static void setDefaultMailFrom(String defaultMailFrom) {
186:                MVNCoreConfig.defaultMailFrom = defaultMailFrom;
187:            }
188:
189:            /* </Mail_Options> */
190:
191:            /* <Param Options> */
192:            private static String contextPath = "";// allow ROOT context
193:
194:            public static String getContextPath() {
195:                return contextPath;
196:            }
197:
198:            public static void setContextPath(String contextPath) {
199:                MVNCoreConfig.contextPath = contextPath;
200:            }
201:
202:            private static String serverPath = "http://localhost:8080";
203:
204:            public static String getServerPath() {
205:                return serverPath;
206:            }
207:
208:            public static void setServerPath(String serverPath) {
209:                MVNCoreConfig.serverPath = serverPath;
210:            }
211:
212:            /* <Param Options> */
213:
214:            /* <Date Options> */
215:            /* the unit of the server offset is hour*/
216:            private static int serverHourOffset = 0; /* GMT timezone */
217:
218:            public static int getServerHourOffset() {
219:                return serverHourOffset;
220:            }
221:
222:            public static void setServerHourOffset(int serverHourOffset) {
223:                MVNCoreConfig.serverHourOffset = serverHourOffset;
224:            }
225:
226:            /* </Date Options> */
227:
228:            /* <User Agent Options>*/
229:            private static String blockedUserAgents = "";
230:
231:            public static String getBlockedUserAgents() {
232:                return blockedUserAgents;
233:            }
234:
235:            public static void setBlockedUserAgents(String blockedUserAgents) {
236:                MVNCoreConfig.blockedUserAgents = blockedUserAgents;
237:            }
238:
239:            /* </User Agent Options>*/
240:
241:            /* <IP Options>*/
242:            private static String blockedIPs = "";
243:
244:            public static String getBlockedIPs() {
245:                return blockedIPs;
246:            }
247:
248:            public static void setBlockedIPs(String blockedIPs) {
249:                MVNCoreConfig.blockedIPs = blockedIPs;
250:            }
251:
252:            /* </IP Options>*/
253:
254:            /* <Interceptor> */
255:            private static String mailInterceptorClassName = "";
256:
257:            public static String getMailInterceptorClassName() {
258:                return mailInterceptorClassName;
259:            }
260:
261:            public static void setMailInterceptorClassName(
262:                    String mailInterceptorClassName) {
263:                MVNCoreConfig.mailInterceptorClassName = mailInterceptorClassName;
264:            }
265:
266:            private static String contentInterceptorClassName = "";
267:
268:            public static String getContentInterceptorClassName() {
269:                return contentInterceptorClassName;
270:            }
271:
272:            public static void setContentInterceptorClassName(
273:                    String contentInterceptorClassName) {
274:                MVNCoreConfig.contentInterceptorClassName = contentInterceptorClassName;
275:            }
276:
277:            private static String loginInterceptorClassName = "";
278:
279:            public static String getLoginIdInterceptorClassName() {
280:                return loginInterceptorClassName;
281:            }
282:
283:            public static void setLoginInterceptorClassName(
284:                    String loginInterceptorClassName) {
285:                MVNCoreConfig.loginInterceptorClassName = loginInterceptorClassName;
286:            }
287:
288:            private static String passwordInterceptorClassName = "";
289:
290:            public static String getPasswordInterceptorClassName() {
291:                return passwordInterceptorClassName;
292:            }
293:
294:            public static void setPasswordInterceptorClassName(
295:                    String passwordInterceptorClassName) {
296:                MVNCoreConfig.passwordInterceptorClassName = passwordInterceptorClassName;
297:            }
298:
299:            /* </Interceptor> */
300:
301:            private static boolean enableLinkNofollow = false;
302:
303:            public static boolean getEnableLinkNofollow() {
304:                return enableLinkNofollow;
305:            }
306:
307:            public static void setEnableLinkNofollow(boolean enableLinkNofollow) {
308:                MVNCoreConfig.enableLinkNofollow = enableLinkNofollow;
309:            }
310:
311:            private static boolean enableEncodeURL = true;
312:
313:            public static boolean getEnableEncodeURL() {
314:                return enableEncodeURL;
315:            }
316:
317:            public static void setEnableEncodeURL(boolean enableEncodeURL) {
318:                MVNCoreConfig.enableEncodeURL = enableEncodeURL;
319:            }
320:
321:            private static String portalType = "non-portal";//Portal.DEFAULT;
322:
323:            public static String getPortalType() {
324:                return portalType;
325:            }
326:
327:            public static void setPortalType(String portalType) {
328:                MVNCoreConfig.portalType = portalType;
329:            }
330:
331:            private static String mvnCoreServiceClassName = "net.myvietnam.mvncore.service.impl.MvnCoreServiceImplDefault";
332:
333:            public static String getMvnCoreServiceClassName() {
334:                return mvnCoreServiceClassName;
335:            }
336:
337:            public static void setMvnCoreServiceClassName(
338:                    String mvnCoreServiceClassName) {
339:                MVNCoreConfig.mvnCoreServiceClassName = mvnCoreServiceClassName;
340:            }
341:
342:            private static List timerTaskExtList = new ArrayList();
343:
344:            public static List getTimerTaskExtList() {
345:                return timerTaskExtList;
346:            }
347:
348:            public static void setTimerTaskExtList(List tasks) {
349:                timerTaskExtList = tasks;
350:            }
351:
352:            static {
353:                load();
354:            }
355:
356:            public static void load() {
357:                reload();
358:            }
359:
360:            public static void reload() {
361:                final String classPath = FileUtil.getServletClassesPath();
362:                final String configFilename = classPath + OPTION_FILE_NAME;
363:                try {
364:                    final DOM4JConfiguration conf = new DOM4JConfiguration(
365:                            new File(configFilename));
366:
367:                    /* <Database Options> */
368:                    useDataSource = conf.getBoolean("dboptions.use_datasource",
369:                            false);
370:                    databaseType = conf.getInt("dboptions.database_type", 0);
371:
372:                    if (useDataSource) {
373:                        dataSourceName = conf
374:                                .getString("dboptions.datasource_name");
375:                    } else {
376:                        driverClassName = conf.getString(
377:                                "dboptions.driver_class_name", driverClassName);
378:                        databaseURL = conf.getString("dboptions.database_url",
379:                                databaseURL);
380:                        databaseUser = conf.getString(
381:                                "dboptions.database_user", databaseUser);
382:                        databasePassword = conf
383:                                .getString("dboptions.database_password",
384:                                        databasePassword);
385:
386:                        maxConnection = conf.getInt("dboptions.max_connection",
387:                                maxConnection);
388:                        maxTimeToWait = conf.getInt(
389:                                "dboptions.max_time_to_wait", maxTimeToWait);
390:
391:                        minutesBetweenRefresh = conf.getInt(
392:                                "dboptions.minutes_between_refresh",
393:                                minutesBetweenRefresh);
394:                        if (minutesBetweenRefresh < 1) {
395:                            minutesBetweenRefresh = 1; //min is 1 minute
396:                        }
397:                    }
398:                    /* <Database Options> */
399:
400:                    /* <Mail Options> */
401:                    defaultMailFrom = conf.getString(
402:                            "mailoptions.default_mail_from", defaultMailFrom);
403:
404:                    receiveMail.config(conf);
405:                    sendMail.config(conf);
406:                    /* </Mail Options> */
407:
408:                    /* <Parameter Options> */
409:                    contextPath = conf.getString("paramoptions.context_path",
410:                            contextPath);
411:                    serverPath = conf.getString("paramoptions.server_path",
412:                            serverPath);
413:                    if (serverPath.endsWith("/")) {
414:                        serverPath = serverPath.substring(0, serverPath
415:                                .length() - 1);
416:                    }
417:                    /* </Parameter Options> */
418:
419:                    /* <Date Time Options> */
420:                    serverHourOffset = conf.getInt(
421:                            "dateoptions.server_hour_offset", serverHourOffset);
422:                    if ((serverHourOffset < -13) || (serverHourOffset > 13)) {
423:                        serverHourOffset = 0;
424:                    }
425:                    /* </Date Time Options> */
426:
427:                    /* <User Agent Options>*/
428:                    blockedUserAgents = conf.getString(
429:                            "useragentoptions.blocked_user_agent",
430:                            blockedUserAgents);
431:                    /* </User Agent Options>*/
432:
433:                    /* <IP Options>*/
434:                    blockedIPs = conf.getString("ipoptions.blocked_ip",
435:                            blockedIPs);
436:                    /* </IP Options>*/
437:
438:                    /* <Interceptor Options>*/
439:                    mailInterceptorClassName = conf.getString(
440:                            "interceptor.mailinterceptor_implementation",
441:                            mailInterceptorClassName);
442:                    contentInterceptorClassName = conf.getString(
443:                            "interceptor.contentinterceptor_implementation",
444:                            contentInterceptorClassName);
445:                    loginInterceptorClassName = conf.getString(
446:                            "interceptor.loginidinterceptor_implementation",
447:                            loginInterceptorClassName);
448:                    passwordInterceptorClassName = conf.getString(
449:                            "interceptor.passwordinterceptor_implementation",
450:                            passwordInterceptorClassName);
451:                    /* </Interceptor Options>*/
452:
453:                    /* <MVNCore Options>*/
454:                    enableLinkNofollow = conf.getBoolean(
455:                            "mvncoreconfig.enable_link_nofollow", false);
456:                    enableEncodeURL = conf.getBoolean(
457:                            "mvncoreconfig.enable_encode_url", true);
458:                    portalType = conf.getString("mvncoreconfig.portal_type",
459:                            portalType);
460:
461:                    mvnCoreServiceClassName = conf.getString(
462:                            "mvncoreconfig.mvncoreservice_implementation",
463:                            mvnCoreServiceClassName);
464:
465:                    String taskClasses = conf.getString(
466:                            "mvncoreconfig.timertaskext_implementation_list",
467:                            null);
468:                    if (taskClasses != null) {
469:                        String[] token = StringUtil.getStringArray(taskClasses,
470:                                ";");
471:                        for (int i = 0; i < token.length; i++) {
472:                            String className = token[i];
473:                            if (className.equals("") == false) {
474:                                try {
475:                                    Class c = Class.forName(className);
476:                                    Method getInstanceMethod = c.getMethod(
477:                                            "getInstance", (Class[]) null);
478:                                    TimerTaskExt timerTaskExt = (TimerTaskExt) getInstanceMethod
479:                                            .invoke(null, (Object[]) null);
480:                                    timerTaskExtList.add(timerTaskExt);
481:                                } catch (Throwable t) {
482:                                    log.warn("Error in loading TimerTaskExt: "
483:                                            + className, t);
484:                                }
485:                            }
486:                        }
487:                    }
488:
489:                    /* </MVNCore Options>*/
490:
491:                } catch (Exception e) {
492:                    final String message = "com.mvnforum.MVNCoreConfig: Can't read the configuration file: '"
493:                            + configFilename
494:                            + "'. Make sure the file is in your CLASSPATH";
495:                    log.error(message, e);
496:                }
497:            }
498:
499:            public static class MailConfig {
500:
501:                String configName;
502:
503:                boolean useMailSource;
504:                boolean useEmbededSMTPMailServer;
505:                String sourceName = "";
506:
507:                String mailServer = "mail.localhost.com";
508:
509:                int port;
510:                String userName = "";
511:                String password = "";
512:
513:                MailConfig(String configName) {
514:                    this .configName = configName;
515:                }
516:
517:                /**
518:                 * @return Returns the useMailSource.
519:                 */
520:                public boolean useMailSource() {
521:                    return useMailSource;
522:                }
523:
524:                /**
525:                 * @return Returns the useMailSource.
526:                 */
527:                public boolean useEmbededSMTPMailServer() {
528:                    return useEmbededSMTPMailServer;
529:                }
530:
531:                /**
532:                 * @return Returns the sourceName.
533:                 */
534:                public String getSourceName() {
535:                    return sourceName;
536:                }
537:
538:                /**
539:                 * @return Returns the mailServer.
540:                 */
541:                public String getMailServer() {
542:                    return mailServer;
543:                }
544:
545:                /**
546:                 * @return Returns the password.
547:                 */
548:                public String getPassword() {
549:                    return password;
550:                }
551:
552:                /**
553:                 * @return Returns the port.
554:                 */
555:                public int getPort() {
556:                    return port;
557:                }
558:
559:                /**
560:                 * @return Returns the userName.
561:                 */
562:                public String getUserName() {
563:                    return userName;
564:                }
565:
566:                /**
567:                 * @param mailServer The mailServer to set.
568:                 */
569:                void setMailServer(String mailServer) {
570:                    this .mailServer = mailServer;
571:                }
572:
573:                /**
574:                 * @param password The password to set.
575:                 */
576:                void setPassword(String password) {
577:                    this .password = password;
578:                }
579:
580:                /**
581:                 * @param port The port to set.
582:                 */
583:                void setPort(int port) {
584:                    this .port = port;
585:                }
586:
587:                /**
588:                 * @param useMailSource The useMailSource to set.
589:                 */
590:                void setUseMailSource(boolean useMailSource) {
591:                    this .useMailSource = useMailSource;
592:                }
593:
594:                /**
595:                 * @param useEmbededSMTPMailServer The useEmbededSMTPMailServer to set.
596:                 */
597:                void setUseEmbededSMTPMailServer(
598:                        boolean useEmbededSMTPMailServer) {
599:                    this .useEmbededSMTPMailServer = useEmbededSMTPMailServer;
600:                }
601:
602:                /**
603:                 * @param userName The userName to set.
604:                 */
605:                void setUserName(String userName) {
606:                    this .userName = userName;
607:                }
608:
609:                void config(DOM4JConfiguration conf) {
610:
611:                    useMailSource = conf.getBoolean("mailoptions." + configName
612:                            + ".enable_mail_source", false);
613:                    if (configName.equals("receive_mail") == false) {
614:                        useEmbededSMTPMailServer = conf
615:                                .getBoolean("mailoptions." + configName
616:                                        + ".use_embeded_smtp_mail_server", true);
617:                    }
618:                    if (useMailSource) {
619:                        sourceName = conf.getString("mailoptions." + configName
620:                                + ".mail_source_name");
621:                    } else {
622:                        mailServer = conf.getString("mailoptions." + configName
623:                                + ".mail_server", mailServer);
624:                        userName = conf.getString("mailoptions." + configName
625:                                + ".username", userName);
626:                        password = conf.getString("mailoptions." + configName
627:                                + ".password", password);
628:                        port = conf.getInt("mailoptions." + configName
629:                                + ".port", port);
630:                    }
631:                }
632:            }
633:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.