Update of /cvsroot/webmacro/webmacro/src/org/webmacro
In directory sc8-pr-cvs1:/tmp/cvs-serv13677/src/org/webmacro
Modified Files:
Broker.java WM.java
Log Message:
Add WM(Properties), WM(Servlet, Properties), constructors and test case
Index: Broker.java
===================================================================
RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/Broker.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** Broker.java 23 Jul 2002 16:36:11 -0000 1.32
--- Broker.java 27 Mar 2003 00:35:30 -0000 1.33
***************
*** 122,125 ****
--- 122,143 ----
}
+ /**
+ * Equivalent to Broker("WebMacro.properties"), except that it doesn't
+ * complain if WebMacro.properties can't be found, and it loads properties
+ * from a specified Properties.
+ */
+ protected Broker(Properties props) throws InitException {
+ this( ( Broker ) null, "Ad-hoc Properties " + props.hashCode());
+ String propertySource = WEBMACRO_DEFAULTS + ", " + WEBMACRO_PROPERTIES
+ + ", (caller-supplied Properties), (System Properties)";
+ loadDefaultSettings();
+ loadSettings( WEBMACRO_PROPERTIES, true );
+ loadSettings(props);
+ loadSystemSettings();
+ initLog();
+ _log.notice( "Loaded settings from " + propertySource );
+ init();
+ }
+
/**
* Search the classpath for the properties file under
***************
*** 370,373 ****
--- 388,408 ----
}
+ public static Broker getBroker(Properties p) throws InitException {
+ try {
+ Broker b = findBroker( p );
+ if ( b == null ) {
+ b = new Broker(p);
+ register( p, b );
+ }
+ b.startClient();
+ return b;
+ }
+ catch ( InitException e ) {
+ Log log = LogSystem.getSystemLog( "wm" );
+ log.error( "Failed to initialize WebMacro with default config" );
+ throw e;
+ }
+ }
+
public static Broker getBroker( String settingsFile ) throws InitException {
try {
***************
*** 430,433 ****
--- 465,472 ----
return false;
}
+
+ protected void loadSettings(Properties p) {
+ _config.load( p );
+ }
protected void loadSystemSettings() {
Index: WM.java
===================================================================
RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/WM.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** WM.java 27 Nov 2002 04:18:57 -0000 1.39
--- WM.java 27 Mar 2003 00:35:30 -0000 1.40
***************
*** 25,28 ****
--- 25,29 ----
import java.io.*;
+ import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
***************
*** 73,76 ****
--- 74,88 ----
/**
+ * Constructs a WM which gets its properties (optionally) from the
+ * file WebMacro.properties, as found on the class path, and from properties
+ * specified in a provided Properties. No servlet
+ * integration. Templates will be loaded from the class path or from
+ * TemplatePath. Most users will want to use the WM(Servlet) constructor.
+ */
+ public WM(Properties p) throws InitException {
+ this(Broker.getBroker(p));
+ }
+
+ /**
* Constructs a WM which gets its properties from the file specified,
* which must exist on the class path or be an absolute path. No servlet
***************
*** 90,93 ****
--- 102,113 ----
this(ServletBroker.getBroker(s));
}
+
+ /**
+ * Constructs a WM is tied to a Servlet broker, with an additional set of
+ * properties passed in from the caller.
+ */
+ public WM(Servlet s, Properties additionalProperties) throws InitException {
+ this(ServletBroker.getBroker(s, additionalProperties));
+ }
/**
|