Source Code Cross Referenced for ServerConfig.java in  » Source-Control » sourcejammer » org » sourcejammer » server » 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 » Source Control » sourcejammer » org.sourcejammer.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (C) 2001, 2002 Robert MacGrogan
003:         *
004:         *  This library is free software; you can redistribute it and/or
005:         *  modify it under the terms of the GNU Lesser General Public
006:         *  License as published by the Free Software Foundation; either
007:         *  version 2.1 of the License, or (at your option) any later version.
008:         *
009:         *  This library is distributed in the hope that it will be useful,
010:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         *  Lesser General Public License for more details.
013:         *
014:         *  You should have received a copy of the GNU Lesser General Public
015:         *  License along with this library; if not, write to the Free Software
016:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:         *
018:         *
019:         * $Archive: SourceJammer$
020:         * $FileName: ServerConfig.java$
021:         * $FileID: 4525$
022:         *
023:         * Last change:
024:         * $AuthorName: Rob MacGrogan$
025:         * $VerID: 10366$
026:         * $Date: 9/17/03 1:16 PM$
027:         * $Comment: $
028:         */
029:
030:        package org.sourcejammer.server;
031:
032:        import org.w3c.dom.Document;
033:        import org.w3c.dom.Element;
034:        import org.w3c.dom.Node;
035:        import org.sourcejammer.xml.XMLUtil;
036:        import java.io.IOException;
037:        import java.io.File;
038:
039:        import javax.xml.parsers.ParserConfigurationException;
040:
041:        import org.xml.sax.SAXException;
042:        import org.sourcejammer.util.ConfigurationException;
043:
044:        /**
045:         * Title:        $FileName: ServerConfig.java$
046:         * @version      $VerNum: 9$
047:         * @author       $AuthorName: Rob MacGrogan$<br><br>
048:         * $Description: $<br>
049:         * $KeyWordsOff: $
050:         */
051:        public class ServerConfig {
052:
053:            private ServerConfig() {
054:            }
055:
056:            private static final String CONF_FILE = "serverconf.xml";
057:
058:            public static final class ConfXMLNodes {
059:                public static final String MAX_CACHE_SIZE = "MaxCacheSize";
060:                public static final String ENABLE_ANONYMOUS_ACCESS = "EnableAnonymousAccess";
061:                public static final String ANONYMOUS_USER_NAME = "AnonymousUserName";
062:                public static final String ENABLE_WEB_ACCESS = "EnableWebAccess";
063:                public static final String WEB_INTERFACE_TITLE = "WebInterfaceTitle";
064:                public static final String WEB_INTERFACE_INFO = "WebInterfaceInfo";
065:
066:                public static final String COMP_CHUNK_SIZE = "ComparisonChunkSize";
067:                public static final String BINARY_RANGE_SIZE = "BinaryRangeSize";
068:                public static final String DEFAULT_ARCHIVE_ROOT = "DefaultArchiveRoot";
069:                public static final String SERVER_DIR = "ServerDirectory";
070:                public static final String FILESYS_DIR = "FileSysDirectory";
071:            }
072:
073:            private static ServerConfig instance = null;
074:
075:            //Hard code this. Remember to update for each release.
076:            private static String msServerVersion = "2.1.0.1";
077:            private int miMaxCacheSize = -1;
078:            private boolean mbEnableAnonymous = false;
079:            private boolean mbEnableWeb = false;
080:            private String msAnonymousUserName = "anon";
081:            private String msWebInterfaceTitle = "SourceJammer";
082:            private String msWebInterfaceInfo = "The free, open-source source control and versioning system.";
083:            private String serverDirectory = "/usr/local/sourcejammer/server";
084:            private String filesysDirectory = "/usr/local/sourcejammer/server/filesys";
085:
086:            private int miComparisonChunkSize = 100;
087:            private int miBinaryRangeSize = 1000;
088:            private String msDefaultArchiveRoot = "";
089:
090:            private synchronized void load(String sBasePath)
091:                    throws IOException, SAXException {
092:
093:                File flConf = null;
094:                if (sBasePath == null) {
095:                    flConf = new File(CONF_FILE);
096:                } else {
097:                    flConf = new File(sBasePath, CONF_FILE);
098:                }
099:                System.out.println("sc - " + flConf.getAbsolutePath());
100:                if (flConf.exists()) {
101:                    Document docConf = null;
102:                    try {
103:                        docConf = XMLUtil.getXMLDoc(flConf);
104:                    } catch (ParserConfigurationException ex) {
105:                        throw new SAXException(
106:                                "Parser configuration exception in reading server conf file.",
107:                                ex);
108:                    }
109:                    Element elmRoot = docConf.getDocumentElement();
110:
111:                    //Cache size
112:                    String sMaxCacheSize = XMLUtil.getValue(
113:                            ConfXMLNodes.MAX_CACHE_SIZE, elmRoot);
114:                    miMaxCacheSize = Integer.parseInt(sMaxCacheSize.trim());
115:
116:                    //Enable anon SOAP access
117:                    String sTF = XMLUtil.getValue(
118:                            ConfXMLNodes.ENABLE_ANONYMOUS_ACCESS, elmRoot);
119:                    if (sTF.startsWith("t") || sTF.startsWith("T")) {
120:                        mbEnableAnonymous = true;
121:                    }
122:
123:                    //Enable anon Web access
124:                    sTF = XMLUtil.getValue(ConfXMLNodes.ENABLE_WEB_ACCESS,
125:                            elmRoot);
126:                    if (sTF.startsWith("t") || sTF.startsWith("T")) {
127:                        mbEnableWeb = true;
128:                    }
129:
130:                    //Anon user name
131:                    msAnonymousUserName = XMLUtil.getValue(
132:                            ConfXMLNodes.ANONYMOUS_USER_NAME, elmRoot);
133:
134:                    //Compare chunk size
135:                    String sCompareSize = XMLUtil.getValue(
136:                            ConfXMLNodes.COMP_CHUNK_SIZE, elmRoot);
137:                    miComparisonChunkSize = Integer.parseInt(sCompareSize
138:                            .trim());
139:
140:                    //Range size
141:                    String sRangeSize = XMLUtil.getValue(
142:                            ConfXMLNodes.BINARY_RANGE_SIZE, elmRoot);
143:                    miBinaryRangeSize = Integer.parseInt(sRangeSize.trim());
144:
145:                    //Server directory -- inside WEB-INF if not defined.
146:                    serverDirectory = XMLUtil.getValue(ConfXMLNodes.SERVER_DIR,
147:                            elmRoot);
148:                    if (serverDirectory == null || serverDirectory.equals("")) {
149:                        java.io.File confDir = new java.io.File(
150:                                org.sourcejammer.util.AppConfig.getInstance()
151:                                        .getConfigFilePath());
152:                        java.io.File webinfDir = confDir.getParentFile();
153:                        java.io.File flServerDir = new java.io.File(webinfDir,
154:                                "server");
155:                        if (!flServerDir.exists()) {
156:                            flServerDir.mkdir();
157:                        }
158:                        serverDirectory = flServerDir.getAbsolutePath();
159:                    }
160:
161:                    //Archives directory -- inside server directory if not defined.
162:                    msDefaultArchiveRoot = XMLUtil.getValue(
163:                            ConfXMLNodes.DEFAULT_ARCHIVE_ROOT, elmRoot);
164:                    if (msDefaultArchiveRoot == null
165:                            || msDefaultArchiveRoot.equals("")) {
166:                        java.io.File archivesDir = new java.io.File(
167:                                serverDirectory, "archives");
168:                        if (!archivesDir.exists()) {
169:                            archivesDir.mkdir();
170:                        }
171:                        msDefaultArchiveRoot = archivesDir.getAbsolutePath();
172:                    }
173:
174:                    //FileSys directory -- inside server directory if not defined.
175:                    filesysDirectory = XMLUtil.getValue(
176:                            ConfXMLNodes.FILESYS_DIR, elmRoot);
177:                    if (filesysDirectory == null || filesysDirectory.equals("")) {
178:                        java.io.File flFileSysDir = new java.io.File(
179:                                serverDirectory, "filesys");
180:                        if (!flFileSysDir.exists()) {
181:                            flFileSysDir.mkdir();
182:                        }
183:                        filesysDirectory = flFileSysDir.getAbsolutePath();
184:                    }
185:
186:                }
187:            }
188:
189:            public static ServerConfig getInstance(String basePath) {
190:                //assume that we need to reload when this is called.
191:                try {
192:                    instance = new ServerConfig();
193:                    instance.load(basePath);
194:                } catch (Exception ex) {
195:                    System.out.println("!!!Error in ServerCofig!!!");
196:                    ex.printStackTrace();
197:                }
198:                return instance;
199:            }
200:
201:            public static ServerConfig getInstance() {
202:                if (instance == null) {
203:                    throw new ConfigurationException(
204:                            "ServerConfig has not been intialized.");
205:                }
206:                return instance;
207:            }
208:
209:            public int getComparisonChunckSize() {
210:                return miComparisonChunkSize;
211:            }
212:
213:            public int getBinaryRangeSize() {
214:                return miBinaryRangeSize;
215:            }
216:
217:            public String getDefaultArchiveRoot() {
218:                return msDefaultArchiveRoot;
219:            }
220:
221:            public int getMaxCacheSize() {
222:                return miMaxCacheSize;
223:            }
224:
225:            public boolean isEnableAnonymousAccess() {
226:                return mbEnableAnonymous;
227:            }
228:
229:            public boolean isEnableWebAccess() {
230:                return mbEnableWeb;
231:            }
232:
233:            public String getAnonymousUserName() {
234:                return msAnonymousUserName;
235:            }
236:
237:            public static String getServerVersion() {
238:                return msServerVersion;
239:            }
240:
241:            public String getWebInterfaceTitle() {
242:                return msWebInterfaceTitle;
243:            }
244:
245:            public String getWebInterfaceInfo() {
246:                return msWebInterfaceInfo;
247:            }
248:
249:            /**
250:             * Returns the filesysDirectory.
251:             * @return String
252:             */
253:            public String getFilesysDirectory() {
254:                return filesysDirectory;
255:            }
256:
257:            /**
258:             * Returns the serverDirectory.
259:             * @return String
260:             */
261:            public String getServerDirectory() {
262:                return serverDirectory;
263:            }
264:
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.