001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: //
007: package com.sun.portal.ffj.options;
008:
009: //
010: import java.io.File;
011: import java.util.HashMap;
012: import java.util.StringTokenizer;
013:
014: import org.openide.options.SystemOption;
015: import org.openide.util.HelpCtx;
016: import org.openide.util.NbBundle;
017:
018: import com.sun.portal.ffj.filesystems.PSFileSystem;
019: import com.sun.portal.ffj.util.PSConstants;
020:
021: //
022: public class PSSettings extends SystemOption implements PSConstants {
023: //
024: public static final String PROP_CLASSPATH = "classpath";
025: public static final String PROP_DOCROOT = "docroot";
026: public static final String PROP_DEBUGTRACE = "debugtrace";
027: public static final String PROP_USERNAME = "username";
028: public static final String PROP_CONFIGDIR = "configdir";
029: public static HashMap debugMap = new HashMap();
030:
031: //
032: // No constructor please!
033: //
034:
035: //
036: //
037: //
038: private void initializeDebugMap() {
039: //
040: String key = NbBundle.getMessage(PSSettings.class,
041: "LBL_DEBUG_OFF");
042: debugMap.put(key, new Short(DEBUG_OFF));
043:
044: key = NbBundle
045: .getMessage(PSSettings.class, "LBL_DEBUG_WARNING");
046: debugMap.put(key, new Short(DEBUG_WARNING));
047:
048: key = NbBundle
049: .getMessage(PSSettings.class, "LBL_DEBUG_MESSAGE");
050: debugMap.put(key, new Short(DEBUG_MESSAGE));
051:
052: key = NbBundle.getMessage(PSSettings.class, "LBL_DEBUG_ERROR");
053: debugMap.put(key, new Short(DEBUG_ERROR));
054: }
055:
056: protected void initialize() {
057: //
058: super .initialize();
059:
060: // If you have more complex default values which might require
061: // other parts of the module to already be installed, do not
062: // put them here; e.g. make the getter return them as a
063: // default if getProperty returns null. (The class might be
064: // initialized partway through module installation.)
065:
066: //
067: String fsRootPath = PSFileSystem.getRootPath();
068:
069: //
070: setClasspath(fsRootPath);
071: setDocroot(fsRootPath);
072:
073: initializeDebugMap();
074: setDebugtrace(DEBUG_OFF);
075:
076: setUsername(USER_NAME);
077: setConfigdir(fsRootPath);
078: }
079:
080: //
081: //
082: //
083: public String displayName() {
084: return NbBundle.getMessage(PSSettings.class, "LBL_PSSettings");
085: }
086:
087: public HelpCtx getHelpCtx() {
088: return HelpCtx.DEFAULT_HELP;
089: // If you provide context help then use:
090: // return new HelpCtx (PSSettings.class);
091: }
092:
093: //
094: //
095: //
096: public static PSSettings getDefault() {
097: return (PSSettings) findObject(PSSettings.class, true);
098: }
099:
100: //
101: //
102: //
103: public String getClasspath() {
104: return (String) getProperty(PROP_CLASSPATH);
105: }
106:
107: public void setClasspath(String classPath) {
108: //
109: if (validClasspath(classPath))
110: putProperty(PROP_CLASSPATH, classPath, true);
111: }
112:
113: //
114: //
115: //
116: public String getDocroot() {
117: return (String) getProperty(PROP_DOCROOT);
118: }
119:
120: public void setDocroot(String docRoot) {
121: //
122: if (exists(docRoot))
123: putProperty(PROP_DOCROOT, docRoot, true);
124: }
125:
126: //
127: //
128: //
129: public short getDebugtrace() {
130: return ((Short) getProperty(PROP_DEBUGTRACE)).shortValue();
131: }
132:
133: public void setDebugtrace(short debugTrace) {
134: putProperty(PROP_DEBUGTRACE, new Short(debugTrace), true);
135: }
136:
137: //
138: //
139: //
140: public String getUsername() {
141: return (String) getProperty(PROP_USERNAME);
142: }
143:
144: public void setUsername(String userName) {
145: // Null/empty userName is not allowed.
146: if (userName == null)
147: return;
148:
149: if (userName.length() == 0)
150: return;
151:
152: //
153: putProperty(PROP_USERNAME, userName, true);
154: }
155:
156: //
157: //
158: //
159: public String getConfigdir() {
160: return (String) getProperty(PROP_CONFIGDIR);
161: }
162:
163: public void setConfigdir(String configDir) {
164: // ConfigDir cannot be null or empty.
165: // If it is, we set it to default
166: if (configDir == null)
167: configDir = "";
168:
169: if (configDir.length() == 0)
170: configDir = PSFileSystem.getRootPath();
171:
172: //
173: if (exists(configDir))
174: putProperty(PROP_CONFIGDIR, configDir, true);
175: }
176:
177: //
178: //
179: //
180: private boolean exists(String path) {
181: boolean retVal = true;
182:
183: // null Path is like empty path!
184: if (path == null)
185: return retVal;
186:
187: // Empty path is of course ok.
188: if (path.length() == 0)
189: return retVal;
190:
191: //
192: File f = new File(path);
193: retVal = f.exists();
194:
195: return retVal;
196: }
197:
198: private boolean validClasspath(String classPath) {
199: boolean retVal = true;
200:
201: // null Classpath is like empty classpath!
202: if (classPath == null)
203: return retVal;
204:
205: // Empty classpath is of course ok.
206: if (classPath.length() == 0)
207: return retVal;
208:
209: //
210: StringTokenizer tokenizer = new StringTokenizer(classPath,
211: File.pathSeparator);
212: while (tokenizer.hasMoreTokens()) {
213: String cpElement = tokenizer.nextToken();
214: retVal = exists(cpElement);
215:
216: //
217: if (!retVal)
218: break;
219: }
220:
221: return retVal;
222: }
223:
224: //
225: //
226: //
227: }
|