1 16 package org.springframework.webflow.engine.support; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.springframework.binding.expression.Expression; 22 import org.springframework.util.StringUtils; 23 import org.springframework.webflow.engine.ViewSelector; 24 import org.springframework.webflow.execution.RequestContext; 25 import org.springframework.webflow.execution.ViewSelection; 26 import org.springframework.webflow.execution.support.FlowDefinitionRedirect; 27 28 37 public class FlowDefinitionRedirectSelector implements ViewSelector { 38 39 43 private Expression expression; 44 45 50 public FlowDefinitionRedirectSelector(Expression expression) { 51 this.expression = expression; 52 } 53 54 public boolean isEntrySelectionRenderable(RequestContext context) { 55 return true; 56 } 57 58 public ViewSelection makeEntrySelection(RequestContext context) { 59 String encodedRedirect = (String )expression.evaluate(context, null); 60 if (encodedRedirect == null) { 61 throw new IllegalStateException ( 62 "Flow definition redirect expression evaluated to [null], the expression was " + expression); 63 } 64 int index = encodedRedirect.indexOf('?'); 68 String flowDefinitionId; 69 Map executionInput = null; 70 if (index != -1) { 71 flowDefinitionId = encodedRedirect.substring(0, index); 72 String [] parameters = StringUtils.delimitedListToStringArray(encodedRedirect.substring(index + 1), "&"); 73 executionInput = new HashMap (parameters.length, 1); 74 for (int i = 0; i < parameters.length; i++) { 75 String nameAndValue = parameters[i]; 76 index = nameAndValue.indexOf('='); 77 if (index != -1) { 78 executionInput.put(nameAndValue.substring(0, index), nameAndValue.substring(index + 1)); 79 } 80 else { 81 executionInput.put(nameAndValue, ""); 82 } 83 } 84 } 85 else { 86 flowDefinitionId = encodedRedirect; 87 } 88 if (!StringUtils.hasText(flowDefinitionId)) { 89 flowDefinitionId = context.getFlowExecutionContext().getDefinition().getId(); 91 } 92 return new FlowDefinitionRedirect(flowDefinitionId, executionInput); 93 } 94 95 public ViewSelection makeRefreshSelection(RequestContext context) { 96 return makeEntrySelection(context); 97 } 98 } | Popular Tags |