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 2007/03/31 01:42:06 UTC
svn commit: r524329 - in
/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view:
ServletUtils.java VelocityViewServlet.java
Author: nbubna
Date: Fri Mar 30 16:42:05 2007
New Revision: 524329
URL: http://svn.apache.org/viewvc?view=rev&rev=524329
Log:
move VelocityView retrieval/creation to ServletUtils for reusability
Modified:
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ServletUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ServletUtils.java?view=diff&rev=524329&r1=524328&r2=524329
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ServletUtils.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/ServletUtils.java Fri Mar 30 16:42:05 2007
@@ -19,6 +19,8 @@
* under the License.
*/
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
/**
@@ -28,6 +30,8 @@
*/
public class ServletUtils
{
+ public static final String VELOCITY_VIEW_KEY =
+ VelocityView.class.getName();
/**
* Retrieves the path for the specified request regardless of
@@ -53,6 +57,30 @@
path += info;
}
return path;
+ }
+
+ /**
+ * Returns the shared {@link VelocityView} for the specified
+ * {@link ServletConfig}. If one has not yet been created, it
+ * will create, store it for future access, and then return it.
+ */
+ public static VelocityView getVelocityView(ServletConfig config)
+ {
+ ServletContext application = config.getServletContext();
+
+ // check for an already initialized VelocityView to use
+ VelocityView view =
+ (VelocityView)application.getAttribute(VELOCITY_VIEW_KEY);
+ if (view == null)
+ {
+ // only create a new one if we don't already have one
+ view = new VelocityView(config);
+
+ // and store it in the application attributes, so other
+ // servlets, filters, or tags can use it
+ application.setAttribute(VELOCITY_VIEW_KEY, view);
+ }
+ return view;
}
}
Modified: velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java?view=diff&rev=524329&r1=524328&r2=524329
==============================================================================
--- velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java (original)
+++ velocity/tools/branches/2.x/src/main/java/org/apache/velocity/tools/view/VelocityViewServlet.java Fri Mar 30 16:42:05 2007
@@ -76,8 +76,6 @@
public static final String SHARED_CONFIG_PARAM =
"org.apache.velocity.tools.shared.config";
- public static final String VELOCITY_VIEW_KEY =
- VelocityView.class.getName();
/**
* <p>Initializes servlet and VelocityView used to process requests.
@@ -95,20 +93,7 @@
String shared = findInitParameter(config, SHARED_CONFIG_PARAM);
if (shared == null || shared.equals("false"))
{
- ServletContext application = config.getServletContext();
-
- // check for an already initialized VelocityView to use
- VelocityView view =
- (VelocityView)application.getAttribute(VELOCITY_VIEW_KEY);
- if (view == null)
- {
- // only create a new one if we don't already have one
- view = new VelocityView(config);
-
- // and store it in the application attributes, so other
- // servlets, filters, or tags can use it
- application.setAttribute(VELOCITY_VIEW_KEY, view);
- }
+ setVelocityView(ServletUtils.getVelocityView(config));
}
else
{