1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.flow.util;
20
21 import java.util.List;
22 import javax.faces.context.FacesContext;
23 import javax.faces.flow.Flow;
24 import org.apache.myfaces.flow.FlowHandlerImpl;
25 import org.apache.myfaces.flow.FlowReference;
26
27
28
29
30 public class FlowUtils
31 {
32 public static String getFlowMapKey(FacesContext facesContext, FlowReference flowReference)
33 {
34 Flow flow = null;
35 if (flowReference.getDocumentId() == null)
36 {
37 flow = facesContext.getApplication().getFlowHandler().getFlow(
38 facesContext, "", flowReference.getId());
39 }
40 else
41 {
42 flow = facesContext.getApplication().getFlowHandler().getFlow(
43 facesContext, flowReference.getDocumentId(), flowReference.getId());
44 }
45 if (flow != null)
46 {
47 return FlowUtils.getFlowMapKey(facesContext, flow);
48 }
49 return null;
50 }
51
52 public static String getFlowMapKey(FacesContext facesContext, Flow flow)
53 {
54 String flowMapKey = flow.getClientWindowFlowId(
55 facesContext.getExternalContext().getClientWindow());
56 int flowIndex = getFlowIndex(facesContext, flow);
57 if (flowIndex > 0)
58 {
59 flowMapKey = flowMapKey + "_" + flowIndex;
60 }
61 return flowMapKey;
62 }
63
64 private static int getFlowIndex(FacesContext facesContext, Flow flow)
65 {
66 List<Flow> list = FlowHandlerImpl.getActiveFlows(facesContext,
67 facesContext.getApplication().getFlowHandler());
68 FlowReference flowRef = new FlowReference(flow.getDefiningDocumentId(), flow.getId());
69 int flowIndex = 0;
70 for (Flow f : list)
71 {
72 FlowReference fr = new FlowReference(f.getDefiningDocumentId(), f.getId());
73 if (flowRef.equals(fr))
74 {
75 flowIndex++;
76 }
77 }
78 return flowIndex;
79 }
80
81 }