You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2006/12/19 01:02:17 UTC
svn commit: r488461 -
/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
Author: nbubna
Date: Mon Dec 18 16:02:16 2006
New Revision: 488461
URL: http://svn.apache.org/viewvc?view=rev&rev=488461
Log:
provide conventions for looking up toolbox.xml and velocity.properties to reduce required configuration
Modified:
velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
Modified: velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java?view=diff&rev=488461&r1=488460&r2=488461
==============================================================================
--- velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java (original)
+++ velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java Mon Dec 18 16:02:16 2006
@@ -144,6 +144,20 @@
protected static final String INIT_PROPS_KEY =
"org.apache.velocity.properties";
+ /**
+ * Default toolbox configuration file path. If no alternate value for
+ * this is specified, the servlet will look here.
+ */
+ protected static final String DEFAULT_TOOLBOX_PATH =
+ "/WEB-INF/toolbox.xml";
+
+ /**
+ * Default velocity properties file path. If no alternate value for
+ * this is specified, the servlet will look here.
+ */
+ protected static final String DEFAULT_PROPERTIES_PATH =
+ "/WEB-INF/velocity.properties";
+
/** A reference to the toolbox manager. */
protected ToolboxManager toolboxManager = null;
@@ -291,17 +305,17 @@
{
/* check the servlet config and context for a toolbox param */
String file = findInitParameter(config, TOOLBOX_KEY);
-
- /* if we have a toolbox, get a manager for it */
- if (file != null)
+ if (file == null)
{
- toolboxManager =
- ServletToolboxManager.getInstance(getServletContext(), file);
- }
- else
- {
- velocity.info("VelocityViewServlet: No toolbox entry in configuration.");
+ // ok, look in the default location
+ file = DEFAULT_TOOLBOX_PATH;
+ velocity.debug("VelocityViewServlet: No toolbox entry in configuration."
+ + " Looking for '" + DEFAULT_TOOLBOX_PATH + "'");
}
+
+ /* try to get a manager for this toolbox file */
+ toolboxManager =
+ ServletToolboxManager.getInstance(getServletContext(), file);
}
@@ -454,20 +468,28 @@
{
// grab the path to the custom props file (if any)
String propsFile = findInitParameter(config, INIT_PROPS_KEY);
+ if (propsFile == null)
+ {
+ // ok, look in the default location for custom props
+ propsFile = DEFAULT_PROPERTIES_PATH;
+ velocity.debug("VelocityViewServlet: Looking for custom properties at '"
+ + DEFAULT_PROPERTIES_PATH + "'");
+ }
ExtendedProperties p = new ExtendedProperties();
- if (propsFile != null)
+ InputStream is = getServletContext().getResourceAsStream(propsFile);
+ if (is != null)
{
- p.load(getServletContext().getResourceAsStream(propsFile));
-
- velocity.info("VelocityViewServlet: Custom Properties File: "+propsFile);
+ // load the properties from the input stream
+ p.load(is);
+ velocity.info("VelocityViewServlet: Using custom properties at '"
+ + propsFile + "'");
}
else
{
- velocity.info("VelocityViewServlet: No custom properties found. " +
- "Using default Velocity configuration.");
+ velocity.debug("VelocityViewServlet: No custom properties found. " +
+ "Using default Velocity configuration.");
}
-
return p;
}