You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2006/11/14 21:32:06 UTC
svn commit: r474951 - in
/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet:
ServletUtils.java VelocityViewServlet.java
Author: nbubna
Date: Tue Nov 14 12:32:06 2006
New Revision: 474951
URL: http://svn.apache.org/viewvc?view=rev&rev=474951
Log:
extract a getPath(request) method to a utility class for easy reuse
Added:
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java (with props)
Modified:
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
Added: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java?view=auto&rev=474951
==============================================================================
--- jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java (added)
+++ jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java Tue Nov 14 12:32:06 2006
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.velocity.tools.view.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * <p>A set of utility methods for the servlet environment.</p>
+ *
+ * @version $Id: ServletUtils.java 471244 2006-11-04 18:34:38Z henning $
+ */
+public class ServletUtils
+{
+
+ /**
+ * Retrieves the path for the specified request regardless of
+ * whether this is a direct request or an include by the
+ * RequestDispatcher.
+ */
+ public static String getPath(HttpServletRequest request)
+ {
+ // If we get here from RequestDispatcher.include(), getServletPath()
+ // will return the original (wrong) URI requested. The following special
+ // attribute holds the correct path. See section 8.3 of the Servlet
+ // 2.3 specification.
+ String path = (String)request.getAttribute("javax.servlet.include.servlet_path");
+ // also take into account the PathInfo stated on SRV.4.4 Request Path Elements
+ String info = (String)request.getAttribute("javax.servlet.include.path_info");
+ if (path == null)
+ {
+ path = request.getServletPath();
+ info = request.getPathInfo();
+ }
+ if (info != null)
+ {
+ path += info;
+ }
+ return path;
+ }
+
+}
Propchange: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/ServletUtils.java
------------------------------------------------------------------------------
svn:keywords = Revision
Modified: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java?view=diff&rev=474951&r1=474950&r2=474951
==============================================================================
--- jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java (original)
+++ jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java Tue Nov 14 12:32:06 2006
@@ -568,22 +568,7 @@
Context ctx)
throws Exception
{
- // If we get here from RequestDispatcher.include(), getServletPath()
- // will return the original (wrong) URI requested. The following special
- // attribute holds the correct path. See section 8.3 of the Servlet
- // 2.3 specification.
- String path = (String)request.getAttribute("javax.servlet.include.servlet_path");
- // also take into account the PathInfo stated on SRV.4.4 Request Path Elements
- String info = (String)request.getAttribute("javax.servlet.include.path_info");
- if (path == null)
- {
- path = request.getServletPath();
- info = request.getPathInfo();
- }
- if (info != null)
- {
- path += info;
- }
+ String path = ServletUtils.getPath(request);
return getTemplate(path);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org