polish
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<!-- Maps request paths to flows in the flowRegistry; e.g. a path of /hotels/booking looks for a flow with id "hotels/booking" -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowIdHandlerMapping">
|
||||
<property name="defaultHandler">
|
||||
<!-- If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->
|
||||
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
|
||||
@@ -20,12 +20,12 @@
|
||||
<property name="suffix" value=".xhtml" />
|
||||
</bean>
|
||||
|
||||
<!-- Handles requests mapped to the Spring Web Flow system -->
|
||||
<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
|
||||
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
|
||||
|
||||
<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
|
||||
<property name="flowExecutor" ref="flowExecutor" />
|
||||
</bean>
|
||||
|
||||
<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
|
||||
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
|
||||
|
||||
|
||||
</beans>
|
||||
@@ -6,7 +6,7 @@
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<!-- Maps request paths to flows in the flowRegistry; e.g. a path of /hotels/booking looks for a flow with id "hotels/booking" -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowIdHandlerMapping">
|
||||
<property name="order" value="0" />
|
||||
</bean>
|
||||
|
||||
@@ -36,15 +36,18 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Dispatches requests mapped to POJO @Controller implementations -->
|
||||
<!-- Dispatches requests mapped to POJO @Controllers implementations -->
|
||||
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
|
||||
|
||||
<!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller implementations -->
|
||||
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
|
||||
|
||||
<!-- Dispatches requests mapped to flows -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
|
||||
<property name="flowExecutor" ref="flowExecutor"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- Dispatches requests mapped to flows to FlowHandler implementations -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
|
||||
<property name="flowExecutor" ref="flowExecutor"/>
|
||||
</bean>
|
||||
|
||||
<!-- Custom FlowHandler for the hotel booking flow -->
|
||||
<bean name="hotels/booking" class="org.springframework.webflow.samples.booking.BookingFlowHandler" />
|
||||
|
||||
</beans>
|
||||
@@ -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" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
@@ -38,16 +37,16 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="branding" class="spring">
|
||||
<a href="<c:url value="/" />"><img src="<c:url value="/images/header.jpg"/>" alt="Spring Travel" /></a>
|
||||
<a href="<c:url value="/" />"><img src="<c:url value="/resources/images/header.jpg"/>" alt="Spring Travel" /></a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="content" class="clearfix spring">
|
||||
<div id="local" class="spring">
|
||||
<a href="http://www.thespringexperience.com">
|
||||
<img src="<c:url value="/images/diplomat.jpg"/>" alt="generic hotel" />
|
||||
<img src="<c:url value="/resources/images/diplomat.jpg"/>" alt="generic hotel" />
|
||||
</a>
|
||||
<a href="http://www.thespringexperience.com">
|
||||
<img src="<c:url value="/images/tse.gif"/>" alt="The Spring Experience" />
|
||||
<img src="<c:url value="/resources/images/tse.gif"/>" alt="The Spring Experience" />
|
||||
</a>
|
||||
<p>
|
||||
</p>
|
||||
@@ -58,7 +57,7 @@
|
||||
</div>
|
||||
<div id="footer" class="clearfix spring">
|
||||
<a href="http://www.springframework.org">
|
||||
<img src="<c:url value="/images/powered-by-spring.png"/>" alt="Powered by Spring" />
|
||||
<img src="<c:url value="/resources/images/powered-by-spring.png"/>" alt="Powered by Spring" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user