1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.lifecycle;
20
21 import java.util.HashMap;
22 import java.util.Map;
23 import javax.faces.context.FacesContext;
24 import javax.faces.lifecycle.ClientWindow;
25 import javax.faces.render.ResponseStateManager;
26
27
28
29
30
31 public class UrlClientWindow extends ClientWindow
32 {
33 private String windowId;
34
35 private TokenGenerator tokenGenerator;
36
37 private Map<String,String> queryParamsMap;
38
39 public UrlClientWindow(TokenGenerator tokenGenerator)
40 {
41 this.tokenGenerator = tokenGenerator;
42 }
43
44 @Override
45 public void decode(FacesContext context)
46 {
47 String windowId = calculateWindowId(context);
48
49 if (windowId != null)
50 {
51
52 setId(windowId);
53 }
54 else
55 {
56
57 setId(tokenGenerator._getNextToken());
58 }
59 }
60
61 protected String calculateWindowId(FacesContext context)
62 {
63
64
65 String windowId = context.getExternalContext().getRequestParameterMap().get(
66 ResponseStateManager.CLIENT_WINDOW_PARAM);
67 if (windowId != null)
68 {
69 return windowId;
70 }
71 windowId = context.getExternalContext().getRequestParameterMap().get(
72 ResponseStateManager.CLIENT_WINDOW_URL_PARAM);
73 if (windowId != null)
74 {
75 return windowId;
76 }
77 return null;
78 }
79
80 @Override
81 public String getId()
82 {
83 return windowId;
84 }
85
86 public void setId(String id)
87 {
88 windowId = id;
89 queryParamsMap = null;
90 }
91
92 @Override
93 public Map<String, String> getQueryURLParameters(FacesContext context)
94 {
95 if (queryParamsMap == null)
96 {
97 String id = context.getExternalContext().getClientWindow().getId();
98 if (id != null)
99 {
100 queryParamsMap = new HashMap<String, String>(2,1);
101 queryParamsMap.put(ResponseStateManager.CLIENT_WINDOW_URL_PARAM, id);
102 }
103 }
104 return queryParamsMap;
105 }
106
107 }