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

JDConstants

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.

version
$Id: JDConstants.java,v 1.18 2004/06/17 01:54:58 ian Exp $

Fields Summary
protected static String
JABADOT_DIR
This must be a full path, since ya gotta start someplace.
protected static ServletContext
ctx
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) {
			System.out.println(
				"+------------- ERROR --------------------");
			System.out.println(
				"jabadot.dir not set as a context parameter.");
			System.out.println(
				"Please RTFM and try again"); // Time to WTFM!
			System.out.println(
				"+----------------------------------------");
		} 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

return
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));
		sb.append(newStr);
		sb.append(inString.substring(start+oldStr.length()));
		return sb.toString();