JDConstants.javaAPI DocExample2706Wed Jun 16 21:54:58 BST 2004None


public class JDConstants extends HttpServlet
The main "properties"-like class for configuring JabaDot. All of its properties starting with "jabadot.dir" are loaded from Initialization Parameters.

This program has been configured as a "servlet" - which it really is not -- just so it can get the value for JABADOT_DIR from the servlet parameters. As a result, this file should be listed as "preload" in the servlet engine configuration.

$Id:,v 1.18 2004/06/17 01:54:58 ian Exp $

Fields Summary
protected static String
This must be a full path, since ya gotta start someplace.
protected static ServletContext
Constructors Summary
Methods Summary
public static java.lang.StringgetProperty(java.lang.String key)
Get a property, but substitute $DIR with JABADOT_DIR

		if (ctx==null)
			throw new IllegalStateException(
				"JDConstants.getProperty: not initialized!");
		return lookup(key);
public voidinit()
This init servlet method loads the Properties. We know we'll get called once at the beginning of time, since we're set up that way in web.xml (as a pre-loaded servlet).

		ctx = getServletConfig().getServletContext();

		// Get the JABADOT_DIR before all else!

		// Be careful of the difference between 
		// ServletContext.getInitParameter and Servlet.getInitParameter!
		// Be sure the installer puts in in jabadot/WEB-INF/web.xml,
		// NOT in tomcat/conf/web.xml - it will be ignored there!!

		JABADOT_DIR = ctx.getInitParameter("jabadot.dir");
		if (JABADOT_DIR == null) {
				"+------------- ERROR --------------------");
				"jabadot.dir not set as a context parameter.");
				"Please RTFM and try again"); // Time to WTFM!
		} else {
			System.out.println("JABADOT_DIR " + JABADOT_DIR);

private static java.lang.Stringlookup(java.lang.String key)

		String val = ctx.getInitParameter(key);
		if (val == null)
			return null;
		return replace("$DIR", JABADOT_DIR, val);
public static java.lang.Stringreplace(java.lang.String oldStr, java.lang.String newStr, java.lang.String inString)
Replace one string in another

The modified string, or the original if no change made.

		int start = inString.indexOf(oldStr);
		if (start == -1) {
			return inString;
		StringBuffer sb = new StringBuffer();
		sb.append(inString.substring(0, start));
		return sb.toString();