geirm 01/11/02 04:07:00
Modified: src/java/org/apache/velocity/servlet VelocityServlet.java
Log:
Reworked the Velocity init() - the idea is that you want to be able to
have better control over the Velocity init() sequence so if you have to
set the application context, you have an opportunity to do that before
Velocity.init() is called (so any loaders/loggers/etc that need it at
init time can have it...)
An override is simple :
protected void initVelocity( ServletConfig config )
{
Velocity.setApplicationContext( new MyFoo() );
super.initVelocity( config );
}
should do the trick.
You would also use this to init Velocity in other ways, not using the
canonical Properties.
Revision Changes Path
1.42 +35 -10
jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java
Index: VelocityServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/servlet/VelocityServlet.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- VelocityServlet.java 2001/09/11 18:05:47 1.41
+++ VelocityServlet.java 2001/11/02 12:07:00 1.42
@@ -127,7 +127,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="[EMAIL PROTECTED]">Kent Johnson</a>
- * $Id: VelocityServlet.java,v 1.41 2001/09/11 18:05:47 geirm Exp $
+ * $Id: VelocityServlet.java,v 1.42 2001/11/02 12:07:00 geirm Exp $
*/
public abstract class VelocityServlet extends HttpServlet
{
@@ -191,7 +191,34 @@
throws ServletException
{
super.init( config );
-
+
+ /*
+ * do whatever we have to do to init Velocity
+ */
+ initVelocity( config );
+
+ /*
+ * we can get these now that velocity is initialized
+ */
+ defaultContentType = RuntimeSingleton.getString( CONTENT_TYPE,
DEFAULT_CONTENT_TYPE);
+ encoding = RuntimeSingleton.getString( RuntimeSingleton.OUTPUT_ENCODING,
+ DEFAULT_OUTPUT_ENCODING);
+
+ return;
+ }
+
+ /**
+ * Initializes the Velocity runtime, first calling
+ * loadConfiguration(ServletConvig) to get a
+ * java.util.Properties of configuration information
+ * and then calling Velocity.init(). Override this
+ * to do anything to the environment before the
+ * initialization of the singelton takes place, or to
+ * initialize the singleton in other ways.
+ */
+ protected void initVelocity( ServletConfig config )
+ throws ServletException
+ {
try
{
/*
@@ -203,17 +230,15 @@
Properties props = loadConfiguration( config );
Velocity.init( props );
-
- defaultContentType = RuntimeSingleton.getString( CONTENT_TYPE,
DEFAULT_CONTENT_TYPE);
-
- encoding = RuntimeSingleton.getString(
RuntimeSingleton.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
}
catch( Exception e )
{
- throw new ServletException("Error configuring the loader: " + e);
- }
- }
-
+ throw new ServletException("Error initializing Velocity: " + e);
+ }
+
+ return;
+ }
+
/**
* Loads the configuration information and returns that
* information as a Properties, which will be used to
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>