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 | 0 | { |
41 | 0 | this.tokenGenerator = tokenGenerator; |
42 | 0 | } |
43 | |
|
44 | |
@Override |
45 | |
public void decode(FacesContext context) |
46 | |
{ |
47 | 0 | String windowId = calculateWindowId(context); |
48 | |
|
49 | 0 | if (windowId != null) |
50 | |
{ |
51 | |
|
52 | 0 | setId(windowId); |
53 | |
} |
54 | |
else |
55 | |
{ |
56 | |
|
57 | 0 | setId(tokenGenerator._getNextToken()); |
58 | |
} |
59 | 0 | } |
60 | |
|
61 | |
protected String calculateWindowId(FacesContext context) |
62 | |
{ |
63 | |
|
64 | |
|
65 | 0 | String windowId = context.getExternalContext().getRequestParameterMap().get( |
66 | |
ResponseStateManager.CLIENT_WINDOW_PARAM); |
67 | 0 | if (windowId != null) |
68 | |
{ |
69 | 0 | return windowId; |
70 | |
} |
71 | 0 | windowId = context.getExternalContext().getRequestParameterMap().get( |
72 | |
ResponseStateManager.CLIENT_WINDOW_URL_PARAM); |
73 | 0 | if (windowId != null) |
74 | |
{ |
75 | 0 | return windowId; |
76 | |
} |
77 | 0 | return null; |
78 | |
} |
79 | |
|
80 | |
@Override |
81 | |
public String getId() |
82 | |
{ |
83 | 0 | return windowId; |
84 | |
} |
85 | |
|
86 | |
public void setId(String id) |
87 | |
{ |
88 | 0 | windowId = id; |
89 | 0 | queryParamsMap = null; |
90 | 0 | } |
91 | |
|
92 | |
@Override |
93 | |
public Map<String, String> getQueryURLParameters(FacesContext context) |
94 | |
{ |
95 | 0 | if (queryParamsMap == null) |
96 | |
{ |
97 | 0 | String id = context.getExternalContext().getClientWindow().getId(); |
98 | 0 | if (id != null) |
99 | |
{ |
100 | 0 | queryParamsMap = new HashMap<String, String>(2,1); |
101 | 0 | queryParamsMap.put(ResponseStateManager.CLIENT_WINDOW_URL_PARAM, id); |
102 | |
} |
103 | |
} |
104 | 0 | return queryParamsMap; |
105 | |
} |
106 | |
|
107 | |
} |