1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package javax.faces.internal; |
17 | |
|
18 | |
import java.util.Map; |
19 | |
import java.util.Random; |
20 | |
|
21 | |
import javax.faces.FacesException; |
22 | |
import javax.faces.context.ExternalContext; |
23 | |
|
24 | |
import org.seasar.framework.util.StringUtil; |
25 | |
import org.seasar.teeda.core.JsfConstants; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public abstract class WindowIdUtil { |
32 | |
|
33 | |
public static final String NEWWINDOW = "newwindow"; |
34 | |
|
35 | |
public static final String WID = "wid"; |
36 | |
|
37 | |
private static final String BLANK = "_blank"; |
38 | |
|
39 | 1 | private static Random random = new Random(System.currentTimeMillis()); |
40 | |
|
41 | 0 | protected WindowIdUtil() { |
42 | 0 | } |
43 | |
|
44 | |
public static String setupWindowId(final ExternalContext externalContext) |
45 | |
throws FacesException { |
46 | 3 | String wid = null; |
47 | 3 | if (needNewWindow(externalContext.getRequestParameterMap())) { |
48 | 1 | wid = createWindowId(); |
49 | |
} else { |
50 | 2 | Map paramMap = externalContext.getRequestParameterMap(); |
51 | 2 | wid = (String) paramMap.get(WID); |
52 | |
} |
53 | 3 | setWindowId(externalContext, wid); |
54 | 3 | return wid; |
55 | |
} |
56 | |
|
57 | |
public static synchronized String createWindowId() { |
58 | 3 | return Long.toString(random.nextLong()); |
59 | |
} |
60 | |
|
61 | |
public static String getWindowId(final ExternalContext externalContext) |
62 | |
throws FacesException { |
63 | 30 | Map requestMap = externalContext.getRequestMap(); |
64 | 30 | return (String) requestMap.get(WindowIdUtil.WID); |
65 | |
} |
66 | |
|
67 | |
public static void setWindowId(final ExternalContext externalContext, |
68 | |
String wid) throws FacesException { |
69 | 7 | Map requestMap = externalContext.getRequestMap(); |
70 | 7 | requestMap.put(WID, wid); |
71 | 7 | } |
72 | |
|
73 | |
public static boolean isNewWindowTarget(String target) { |
74 | 33 | if (StringUtil.isEmpty(target)) { |
75 | 26 | return false; |
76 | |
} |
77 | 7 | return BLANK.equals(target) || target.charAt(0) != '_'; |
78 | |
} |
79 | |
|
80 | |
public static boolean needNewWindow(final Map parameterMap) { |
81 | 6 | final String newwindow = (String) parameterMap.get(NEWWINDOW); |
82 | 6 | return JsfConstants.TRUE.equals(newwindow); |
83 | |
} |
84 | |
} |