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 javax.faces.context.FacesContext;
22 import javax.faces.lifecycle.ClientWindow;
23 import javax.faces.lifecycle.ClientWindowFactory;
24 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
25 import org.apache.myfaces.config.FacesConfigurator;
26 import org.apache.myfaces.shared.util.WebConfigParamUtils;
27
28
29
30
31
32
33 public class ClientWindowFactoryImpl extends ClientWindowFactory
34 {
35 @JSFWebConfigParam(since="2.2",defaultValue="url")
36 public static final String INIT_PARAM_DEFAULT_WINDOW_MODE =
37 "org.apache.myfaces.DEFAULT_WINDOW_MODE";
38
39 private String windowMode;
40 private TokenGenerator windowTokenGenerator;
41 private ClientConfig clientConfig;
42 private WindowContextConfig windowContextConfig;
43
44 public static final String WINDOW_MODE_NONE = "none";
45 public static final String WINDOW_MODE_URL = "url";
46 public static final String WINDOW_MODE_CLIENT = "client";
47
48 public ClientWindowFactoryImpl()
49 {
50 windowTokenGenerator = new TokenGenerator();
51 clientConfig = new ClientConfig();
52 windowContextConfig = new WindowContextConfig();
53 }
54
55 @Override
56 public ClientWindow getClientWindow(FacesContext facesContext)
57 {
58 if (WINDOW_MODE_NONE.equals(getWindowMode(facesContext)))
59 {
60
61 return null;
62 }
63 else
64 {
65 if (WINDOW_MODE_URL.equals(getWindowMode(facesContext)))
66 {
67 return new UrlClientWindow(windowTokenGenerator);
68 }
69 else if (WINDOW_MODE_CLIENT.equals(getWindowMode(facesContext)))
70 {
71
72 return new CODIClientSideWindow(windowTokenGenerator,
73 windowContextConfig, clientConfig);
74 }
75 else
76 {
77 return null;
78 }
79 }
80 }
81
82 private String getWindowMode(FacesContext context)
83 {
84 if (windowMode == null)
85 {
86 if (FacesConfigurator.isEnableDefaultWindowMode(context))
87 {
88 String defaultWindowMode = WebConfigParamUtils.getStringInitParameter(
89 context.getExternalContext(),
90 INIT_PARAM_DEFAULT_WINDOW_MODE,
91 WINDOW_MODE_URL);
92 windowMode = WebConfigParamUtils.getStringInitParameter(
93 context.getExternalContext(),
94 ClientWindow.CLIENT_WINDOW_MODE_PARAM_NAME,
95 defaultWindowMode);
96 }
97 else
98 {
99 windowMode = WebConfigParamUtils.getStringInitParameter(
100 context.getExternalContext(),
101 ClientWindow.CLIENT_WINDOW_MODE_PARAM_NAME,
102 WINDOW_MODE_NONE);
103 }
104 }
105 return windowMode;
106 }
107
108 }