This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch use-contants in repository https://gitbox.apache.org/repos/asf/velocity-tools.git
commit 712cfbd26b2d1a423712aba6a5cae3b8b973912e Author: eduarddrenth <[email protected]> AuthorDate: Thu Jul 18 15:56:03 2024 +0200 Prefer constants over literals --- .../src/main/java/org/apache/velocity/tools/view/ServletUtils.java | 5 +++-- .../java/org/apache/velocity/tools/view/WebappResourceLoader.java | 4 ++-- .../test/java/org/apache/velocity/tools/view/VelocityViewTest.java | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java index 3c9a2c32..698cce2b 100644 --- a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java +++ b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java @@ -26,6 +26,7 @@ import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; import javax.servlet.FilterConfig; +import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -80,9 +81,9 @@ public class ServletUtils // 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"); + String path = (String)request.getAttribute(RequestDispatcher.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"); + String info = (String)request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO); if (path == null) { path = request.getServletPath(); diff --git a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java index e24b63d7..18b5bbfa 100644 --- a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java +++ b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java @@ -65,9 +65,9 @@ public class WebappResourceLoader extends ResourceLoader /** * This is abstract in the base class, so we need it. * <br> - * NOTE: this expects that the ServletContext has already + * NOTE: this expects that the {@link ServletContext} has already * been placed in the runtime's application attributes - * under its full class name (i.e. "javax.servlet.ServletContext"). + * under its full class name. * * @param configuration the {@link ExtProperties} associated with * this resource loader. diff --git a/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java b/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java index 2a11316c..aa5a1925 100644 --- a/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java +++ b/velocity-tools-view/src/test/java/org/apache/velocity/tools/view/VelocityViewTest.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.io.StringWriter; import java.net.URL; +import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -80,8 +81,8 @@ public class VelocityViewTest extends BaseWebappMockTest expect(config.getInitParameter(VelocityView.TOOLS_KEY)).andAnswer(eval(null)); expect(servletContext.getAttribute(ServletUtils.CONFIGURATION_KEY)).andAnswer(eval((String)null)); expect(servletContext.getResource(VelocityView.USER_TOOLS_PATH)).andAnswer(eval(null)); - expect(request.getAttribute("javax.servlet.include.servlet_path")).andAnswer(eval("/charset-test.vm")); - expect(request.getAttribute("javax.servlet.include.path_info")).andAnswer(eval((String)null)); + expect(request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH)).andAnswer(eval("/charset-test.vm")); + expect(request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO)).andAnswer(eval((String)null)); // This was necessary to verify the bug, now it is not called at all. // expect(response.getCharacterEncoding()).andReturn("ISO-8859-1");
