From d72076724fe6e2f5cbf7b41006e80c2c7ee00506 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Mon, 15 Sep 2008 13:09:43 +0000 Subject: [PATCH] polish --- .../webapp/WEB-INF/config/webmvc-config.xml | 12 ++--- .../webapp/WEB-INF/config/webmvc-config.xml | 19 ++++---- .../main/webapp/WEB-INF/layouts/standard.jsp | 9 ++-- .../servlet/DefaultFlowUrlHandler.java | 31 ++++++++++--- .../mvc/servlet/FlowHandlerMapping.java | 46 ------------------- .../servlet/DefaultFlowUrlHandlerTests.java | 23 +++++++++- 6 files changed, 67 insertions(+), 73 deletions(-) delete mode 100644 spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerMapping.java diff --git a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/config/webmvc-config.xml b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/config/webmvc-config.xml index 788fa858..7f5ac4c5 100644 --- a/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/config/webmvc-config.xml +++ b/spring-webflow-samples/booking-faces/src/main/webapp/WEB-INF/config/webmvc-config.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + @@ -20,12 +20,12 @@ - + + + + - - - - + \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml index 6a8ca888..6fa6b1e9 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/config/webmvc-config.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + @@ -36,15 +36,18 @@ - + - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp index fb082982..0ecf6024 100644 --- a/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp +++ b/spring-webflow-samples/booking-mvc/src/main/webapp/WEB-INF/layouts/standard.jsp @@ -1,7 +1,6 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> <%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> - @@ -38,16 +37,16 @@ diff --git a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java index 09b2e4b7..8fcb4a67 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandler.java @@ -22,7 +22,7 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.springframework.web.util.WebUtils; +import org.springframework.util.StringUtils; import org.springframework.webflow.core.collection.AttributeMap; /** @@ -71,8 +71,16 @@ public class DefaultFlowUrlHandler implements FlowUrlHandler { return pathInfo.substring(1); } else { String servletPath = request.getServletPath(); - int lastSlash = servletPath.lastIndexOf("/"); - return WebUtils.extractFilenameFromUrlPath(servletPath.substring(lastSlash)); + if (StringUtils.hasText(servletPath)) { + int dotIndex = servletPath.lastIndexOf('.'); + if (dotIndex != -1) { + return servletPath.substring(1, dotIndex); + } else { + return servletPath.substring(1); + } + } else { + return request.getContextPath().substring(1); + } } } @@ -86,12 +94,21 @@ public class DefaultFlowUrlHandler implements FlowUrlHandler { public String createFlowDefinitionUrl(String flowId, AttributeMap input, HttpServletRequest request) { StringBuffer url = new StringBuffer(); - url.append(request.getContextPath()); - url.append(request.getServletPath()); - if (!flowId.startsWith("/")) { + if (request.getPathInfo() != null) { + url.append(request.getContextPath()); + url.append(request.getServletPath()); url.append('/'); + url.append(flowId); + } else { + if (StringUtils.hasText(request.getServletPath())) { + url.append(request.getContextPath()); + url.append('/'); + url.append(flowId); + } else { + url.append('/'); + url.append(flowId); + } } - url.append(flowId); if (input != null && !input.isEmpty()) { url.append('?'); appendQueryParameters(url, input.asMap()); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerMapping.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerMapping.java deleted file mode 100644 index 26010e5d..00000000 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerMapping.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.springframework.webflow.mvc.servlet; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; - -import org.springframework.web.servlet.handler.AbstractHandlerMapping; -import org.springframework.webflow.definition.registry.FlowDefinitionRegistry; - -public class FlowHandlerMapping extends AbstractHandlerMapping { - - private FlowDefinitionRegistry flowRegistry; - - protected void initServletContext(ServletContext servletContext) { - if (flowRegistry == null) { - flowRegistry = (FlowDefinitionRegistry) getApplicationContext().getBean("flowRegistry", - FlowDefinitionRegistry.class); - } - } - - protected Object getHandlerInternal(HttpServletRequest request) throws Exception { - String flowId = request.getPathInfo().substring(1); - if (getApplicationContext().containsBean(flowId)) { - Object handler = getApplicationContext().getBean(flowId); - if (handler instanceof FlowHandler) { - return handler; - } - } - if (flowRegistry.containsFlowDefinition(flowId)) { - return new DefaultFlowHandler(flowId); - } - return null; - } - - private static class DefaultFlowHandler extends AbstractFlowHandler { - private String flowId; - - public DefaultFlowHandler(String flowId) { - this.flowId = flowId; - } - - public String getFlowId() { - return flowId; - } - } - -} diff --git a/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java index 53c7d0aa..2763aad2 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/context/servlet/DefaultFlowUrlHandlerTests.java @@ -26,7 +26,13 @@ public class DefaultFlowUrlHandlerTests extends TestCase { request.setServletPath("/app/foo.htm"); request.setPathInfo(null); request.setRequestURI("/springtravel/app/foo.htm"); - assertEquals("foo", urlHandler.getFlowId(request)); + assertEquals("app/foo", urlHandler.getFlowId(request)); + } + + public void testGetFlowIdOnlyContextPath() { + request.setContextPath("/springtravel"); + request.setRequestURI("/springtravel"); + assertEquals("springtravel", urlHandler.getFlowId(request)); } public void testGetFlowExecutionKey() { @@ -47,6 +53,21 @@ public class DefaultFlowUrlHandlerTests extends TestCase { assertEquals("/springtravel/app/bookHotel", url); } + public void testCreateFlowDefinitionUrlNoPathInfo() { + request.setContextPath("/springtravel"); + request.setServletPath("/app/foo.htm"); + request.setRequestURI("/springtravel/app/foo"); + String url = urlHandler.createFlowDefinitionUrl("app/foo", null, request); + assertEquals("/springtravel/app/foo", url); + } + + public void testCreateFlowDefinitionUrlContextPathOnly() { + request.setContextPath("/springtravel"); + request.setRequestURI("/springtravel"); + String url = urlHandler.createFlowDefinitionUrl("springtravel", null, request); + assertEquals("/springtravel", url); + } + public void testCreateFlowDefinitionUrlEmptyInput() { request.setContextPath("/springtravel"); request.setServletPath("/app");