View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @since 2.2
31   * @author Leonardo Uribe
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              //No need to do anything
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                  //clientWindow = new DefaultClientWindow(windowTokenGenerator);
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 }