001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: package com.jcorporate.expresso.core.misc;
066:
067: import java.util.Hashtable;
068: import java.util.Vector;
069:
070: /**
071: * Bean class helping with expresso-config.xml and working with the Digester
072: * to read the configuration.
073: * <p/>
074: * A config context is in the past called a 'db'. It represents one connection
075: * to a database. (May be separate database), each context has it's own
076: * job handler, potentially it's own security setup. etc.
077: */
078: public class ConfigContext {
079:
080: /**
081: * Name of this context
082: */
083: private String name = null;
084: private String hasSetupTables = "y";
085:
086: /**
087: * Description of this context
088: */
089: private String description = null;
090:
091: /**
092: * JDBC configuration information for this context.
093: */
094: private ConfigJdbc myJdbc = null;
095:
096: /**
097: * LDAP configuration for this context (optional)
098: */
099: private ConfigLdap myLdap = null;
100:
101: /**
102: * Location of images directory
103: */
104: private String images = null;
105:
106: /**
107: * Should the job handler for this context be started?
108: */
109: private String startJobHandler = null;
110:
111: /**
112: * Used for if you want stack trace information on error pages. This is
113: * a security hazard if turned on. Use only for development.
114: */
115: private String showStackTrace = null;
116:
117: /**
118: * Set if you want mail debugging
119: */
120: private String mailDebug = null;
121:
122: /**
123: * Contains custom properties for this context.
124: */
125: private Hashtable customProperties = new Hashtable();
126:
127: /**
128: * Contains the database type mappings for this context.
129: */
130: private Vector typeMappings = new Vector();
131: private Vector pathMappings = new Vector();
132:
133: /**
134: * Set to yes if the context is loaded, set to no if the context
135: * should be ignored upon startup.
136: */
137: private String active = "y";
138:
139: /**
140: * When set to true, it will direct controllers to redirect to secured
141: * states when transferring to a state. Otherwise, this will be ignored.
142: */
143: private String useSSL = "n";
144:
145: /**
146: * Used for getting the proper message bundles for this context
147: */
148: private String language = "en";
149:
150: /**
151: * Used for getting the proper message bundles for this context
152: */
153: private String country = "US";
154:
155: /**
156: * What subdirectory of the expresso distribution that Expresso sits in.
157: */
158: private String expressoDir = "expresso";
159:
160: /**
161: *
162: */
163: private Vector setupDefaults = new Vector();
164:
165: /**
166: * minimum password length for users.
167: */
168: private String minPasswordSize = "6";
169:
170: /**
171: * Stylesheet to use with this context.
172: */
173: private String styleSheet = null;
174:
175: /**
176: * Is email address used for the login name in this context?
177: */
178: private String useEmailAsLogin = "n";
179:
180: public ConfigContext() {
181: }
182:
183: public void setUseEmailAsLogin(String newUse) {
184: StringUtil.assertBoolean(newUse,
185: "You must specify a boolean value");
186: useEmailAsLogin = newUse;
187: }
188:
189: public boolean useEmailAsLogin() {
190: return StringUtil.toBoolean(useEmailAsLogin);
191: }
192:
193: public void setStyleSheet(String newSheet) {
194: styleSheet = newSheet;
195: }
196:
197: public String getStyleSheet() {
198: return styleSheet;
199: }
200:
201: public void setMinPasswordSize(String newSize) {
202: minPasswordSize = newSize;
203: }
204:
205: public String getMinPasswordSize() {
206: return minPasswordSize;
207: }
208:
209: public Vector getSetupDefaults() {
210: return setupDefaults;
211: }
212:
213: public void addSetupDefault(ConfigSetupDefault newDefault) {
214: setupDefaults.addElement(newDefault);
215: }
216:
217: public Vector getCustomProperties() {
218: return new Vector(customProperties.entrySet());
219: }
220:
221: /**
222: * @return property value, or null if not found
223: */
224: public String getCustomProperty(String customPropertyName) {
225: String result = null;
226: ConfigCustomProperty prop = (ConfigCustomProperty) customProperties
227: .get(customPropertyName);
228: if (prop != null) {
229: result = prop.getValue();
230: }
231:
232: return result;
233: }
234:
235: public void addJdbc(ConfigJdbc newJdbc) {
236: myJdbc = newJdbc;
237: }
238:
239: public void addPathMapping(ConfigPathMapping newPathMapping) {
240: pathMappings.addElement(newPathMapping);
241: }
242:
243: public Vector getPathMappings() {
244: return pathMappings;
245: }
246:
247: public void addLdap(ConfigLdap newLdap) {
248: myLdap = newLdap;
249: }
250:
251: public void setExpressoDir(String newDir) {
252: StringUtil.assertNotBlank(newDir,
253: "You must specify a directory");
254: expressoDir = newDir;
255: }
256:
257: public String getExpressoDir() {
258: return ConfigManager.expandValue(expressoDir);
259: }
260:
261: public void setLanguage(String newLang) {
262: language = newLang;
263: }
264:
265: public String getLanguage() {
266: return language;
267: }
268:
269: public void setCountry(String newCountry) {
270: country = newCountry;
271: }
272:
273: public String getCountry() {
274: return country;
275: }
276:
277: public void setActive(String newActive) {
278: StringUtil.assertBoolean(newActive,
279: "You must specify a boolean value");
280: active = newActive;
281: }
282:
283: public void setActive(boolean newValue) {
284: active = Boolean.toString(newValue);
285: }
286:
287: public void setUseSSL(String newValue) {
288: StringUtil.assertBoolean(newValue,
289: "You must specify a boolean value");
290: useSSL = newValue;
291: }
292:
293: public void setUseSSL(boolean newValue) {
294: useSSL = Boolean.toString(newValue);
295: }
296:
297: public boolean isActive() {
298: return StringUtil.toBoolean(active);
299: }
300:
301: public boolean isUseSSL() {
302: return StringUtil.toBoolean(useSSL);
303: }
304:
305: public void addTypeMapping(ConfigTypeMapping newMapping) {
306: typeMappings.addElement(newMapping);
307: }
308:
309: public Vector getTypeMappings() {
310: return typeMappings;
311: }
312:
313: public ConfigJdbc getJdbc() {
314: return myJdbc;
315: }
316:
317: public ConfigLdap getLdap() {
318: return myLdap;
319: }
320:
321: public void addCustomProperty(ConfigCustomProperty newCustom) {
322: customProperties.put(newCustom.getName(), newCustom);
323: }
324:
325: public void setStartJobHandler(String newJobHandler) {
326: StringUtil.assertBoolean(newJobHandler,
327: "You must specify a boolean value");
328: startJobHandler = newJobHandler;
329: }
330:
331: public boolean startJobHandler() {
332: return StringUtil.toBoolean(startJobHandler);
333: }
334:
335: public void setShowStackTrace(String newStackTrace) {
336: StringUtil.assertBoolean(newStackTrace,
337: "You must specify a boolean value");
338: showStackTrace = newStackTrace;
339: }
340:
341: public boolean showStackTrace() {
342: return StringUtil.toBoolean(showStackTrace);
343: }
344:
345: public void setMailDebug(String newMailDebug) {
346: StringUtil.assertBoolean(newMailDebug,
347: "You must specify a boolean value");
348: mailDebug = newMailDebug;
349: }
350:
351: public boolean mailDebug() {
352: return StringUtil.toBoolean(mailDebug);
353: }
354:
355: public void setName(String newName) {
356: StringUtil.assertNotBlank(newName, "You must specify a name");
357: name = newName;
358: }
359:
360: public String getName() {
361: return name;
362: }
363:
364: public void setDescription(String newDescrip) {
365: StringUtil.assertNotBlank(newDescrip,
366: "You must specify a description");
367: description = newDescrip;
368: }
369:
370: public String getDescription() {
371: return description;
372: }
373:
374: public void setImages(String newImages) {
375: StringUtil.assertNotBlank(newImages,
376: "You may not specify an empty location");
377: images = newImages;
378: }
379:
380: public String getImages() {
381: return ConfigManager.expandValue(images);
382: }
383:
384: public void setHasSetupTables(String newHasSetup) {
385: StringUtil.assertBoolean(newHasSetup,
386: "You must specify a boolean value");
387: hasSetupTables = newHasSetup;
388: }
389:
390: public boolean hasSetupTables() {
391: return StringUtil.toBoolean(hasSetupTables);
392: }
393: }
|