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 2008/06/23 22:39:44 UTC
svn commit: r670744 -
/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
Author: nbubna
Date: Mon Jun 23 13:39:44 2008
New Revision: 670744
URL: http://svn.apache.org/viewvc?rev=670744&view=rev
Log:
be consistent in having getVelocityView(FilterConfig/ServletConfig/ServletContext) all create instances if none already existed
Modified:
velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/ServletUtils.java?rev=670744&r1=670743&r2=670744&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/ServletUtils.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/view/ServletUtils.java Mon Jun 23 13:39:44 2008
@@ -103,7 +103,7 @@
ServletContext application = config.getServletContext();
// check for an already initialized VelocityView to use
- VelocityView view = getVelocityView(application);
+ VelocityView view = getVelocityView(application, false);
if (view == null)
{
// only create a new one if we don't already have one
@@ -118,11 +118,30 @@
/**
* Returns the shared {@link VelocityView} for the specified
- * {@link ServletContext}, if any.
+ * {@link ServletContext}. If one has not yet been created,
+ * it will create one, store it for future access, and then return it.
*/
public static VelocityView getVelocityView(ServletContext application)
{
- return (VelocityView)application.getAttribute(VELOCITY_VIEW_KEY);
+ return getVelocityView(application, true);
+ }
+
+ /**
+ * Returns the shared {@link VelocityView} for the specified
+ * {@link ServletContext}. If one has not yet been created and
+ * the second parameter is <code>true</code>, then it will
+ * create one, store it for future access, and return it.
+ */
+ public static VelocityView getVelocityView(ServletContext application,
+ boolean createIfMissing) {
+ VelocityView view =
+ (VelocityView)application.getAttribute(VELOCITY_VIEW_KEY);
+ if (view == null && createIfMissing)
+ {
+ view = new VelocityView(application);
+ application.setAttribute(VELOCITY_VIEW_KEY, view);
+ }
+ return view;
}