1 16 package org.springframework.webflow.executor.support; 17 18 import org.springframework.util.StringUtils; 19 import org.springframework.web.util.WebUtils; 20 import org.springframework.webflow.context.ExternalContext; 21 import org.springframework.webflow.context.servlet.ServletExternalContext; 22 import org.springframework.webflow.execution.FlowExecutionContext; 23 import org.springframework.webflow.execution.support.FlowDefinitionRedirect; 24 25 57 public class RequestPathFlowExecutorArgumentHandler extends RequestParameterFlowExecutorArgumentHandler { 58 59 62 private static final char PATH_SEPARATOR_CHARACTER = '/'; 63 64 67 private static final String KEY_DELIMITER = "k"; 68 69 73 private String keyDelimiter = KEY_DELIMITER; 74 75 79 public String getKeyDelimiter() { 80 return keyDelimiter; 81 } 82 83 89 public void setKeyDelimiter(String keyDelimiter) { 90 this.keyDelimiter = keyDelimiter; 91 } 92 93 public boolean isFlowIdPresent(ExternalContext context) { 94 String requestPathInfo = getRequestPathInfo(context); 95 boolean hasFileName = StringUtils.hasText(WebUtils.extractFilenameFromUrlPath(requestPathInfo)); 96 return hasFileName || super.isFlowIdPresent(context); 97 } 98 99 public String extractFlowId(ExternalContext context) { 100 String requestPathInfo = getRequestPathInfo(context); 101 String extractedFilename = WebUtils.extractFilenameFromUrlPath(requestPathInfo); 102 return StringUtils.hasText(extractedFilename) ? extractedFilename : super.extractFlowId(context); 103 } 104 105 public boolean isFlowExecutionKeyPresent(ExternalContext context) { 106 String requestPathInfo = getRequestPathInfo(context); 107 return requestPathInfo.startsWith(keyPath()) || super.isFlowExecutionKeyPresent(context); 108 } 109 110 public String extractFlowExecutionKey(ExternalContext context) throws FlowExecutorArgumentExtractionException { 111 String requestPathInfo = getRequestPathInfo(context); 112 int index = requestPathInfo.indexOf(keyPath()); 113 if (index != -1) { 114 return requestPathInfo.substring(index + keyPath().length()); 115 } 116 else { 117 return super.extractFlowExecutionKey(context); 118 } 119 } 120 121 public String createFlowDefinitionUrl(FlowDefinitionRedirect flowDefinitionRedirect, ExternalContext context) { 122 StringBuffer flowUrl = new StringBuffer (); 123 appendFlowExecutorPath(flowUrl, context); 124 flowUrl.append(PATH_SEPARATOR_CHARACTER); 125 flowUrl.append(flowDefinitionRedirect.getFlowDefinitionId()); 126 if (!flowDefinitionRedirect.getExecutionInput().isEmpty()) { 127 flowUrl.append('?'); 128 appendQueryParameters(flowUrl, flowDefinitionRedirect.getExecutionInput()); 129 } 130 return flowUrl.toString(); 131 } 132 133 public String createFlowExecutionUrl(String flowExecutionKey, FlowExecutionContext flowExecution, 134 ExternalContext context) { 135 StringBuffer flowExecutionUrl = new StringBuffer (); 136 appendFlowExecutorPath(flowExecutionUrl, context); 137 flowExecutionUrl.append(PATH_SEPARATOR_CHARACTER); 138 flowExecutionUrl.append(keyDelimiter); 139 flowExecutionUrl.append(PATH_SEPARATOR_CHARACTER); 140 flowExecutionUrl.append(flowExecutionKey); 141 return flowExecutionUrl.toString(); 142 } 143 144 146 protected void appendFlowExecutorPath(StringBuffer url, ExternalContext context) { 147 url.append(context.getContextPath()); 148 url.append(context.getDispatcherPath()); 149 } 150 151 155 private String getRequestPathInfo(ExternalContext context) { 156 String requestPathInfo = context.getRequestPathInfo(); 157 return requestPathInfo != null ? requestPathInfo : ""; 158 } 159 160 163 private String keyPath() { 164 return PATH_SEPARATOR_CHARACTER + keyDelimiter + PATH_SEPARATOR_CHARACTER; 165 } 166 } | Popular Tags |