1 16 package org.springframework.webflow.executor.jsf; 17 18 import org.springframework.util.StringUtils; 19 import org.springframework.webflow.context.ExternalContext; 20 import org.springframework.webflow.executor.support.FlowExecutorArgumentExtractionException; 21 import org.springframework.webflow.executor.support.FlowExecutorArgumentExtractor; 22 import org.springframework.webflow.executor.support.RequestParameterFlowExecutorArgumentHandler; 23 24 31 public class FlowNavigationHandlerArgumentExtractor extends RequestParameterFlowExecutorArgumentHandler { 32 33 37 38 41 private static final String FLOW_ID_PREFIX = "flowId:"; 42 43 private String flowIdPrefix = FLOW_ID_PREFIX; 44 45 48 public String getFlowIdPrefix() { 49 return flowIdPrefix; 50 } 51 52 55 public void setFlowIdPrefix(String flowIdPrefix) { 56 this.flowIdPrefix = flowIdPrefix; 57 } 58 59 public boolean isEventIdPresent(ExternalContext context) { 60 return StringUtils.hasText(getOutcome(context)) || super.isEventIdPresent(context); 61 } 62 63 public String extractEventId(ExternalContext context) throws FlowExecutorArgumentExtractionException { 65 String outcome = getOutcome(context); 66 if (StringUtils.hasText(outcome)) { 67 return outcome; 68 } 69 else { 70 return super.extractEventId(context); 71 } 72 } 73 74 public boolean isFlowIdPresent(ExternalContext context) throws FlowExecutorArgumentExtractionException { 75 String outcome = getOutcome(context); 76 if (outcome != null && outcome.startsWith(getFlowIdPrefix())) { 77 return true; 78 } 79 else { 80 return super.isFlowIdPresent(context); 81 } 82 } 83 84 public String extractFlowId(ExternalContext context) throws FlowExecutorArgumentExtractionException { 86 String outcome = getOutcome(context); 87 if (StringUtils.hasText(outcome)) { 88 int index = outcome.indexOf(getFlowIdPrefix()); 89 if (index == -1) { 90 throw new FlowExecutorArgumentExtractionException( 91 "Unable to extract flow id; make sure the JSF outcome is prefixed with '" + getFlowIdPrefix() 92 + "' to launch a new flow execution"); 93 } 94 String flowId = outcome.substring(getFlowIdPrefix().length()); 95 if (!StringUtils.hasText(flowId)) { 96 throw new FlowExecutorArgumentExtractionException( 97 "Unable to extract flow id; make sure the flow id is provided in the outcome string"); 98 } 99 return flowId; 100 } 101 else { 102 return super.extractFlowId(context); 103 } 104 } 105 106 private String getOutcome(ExternalContext context) { 107 return ((JsfExternalContext)context).getOutcome(); 108 } 109 } | Popular Tags |