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 javax.faces.render;
20  
21  import javax.faces.application.StateManager;
22  import javax.faces.application.StateManager.SerializedView;
23  import javax.faces.context.FacesContext;
24  import java.io.IOException;
25  
26  /**
27   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
28   */
29  public abstract class ResponseStateManager
30  {
31      public static final String RENDER_KIT_ID_PARAM = "javax.faces.RenderKitId";
32      public static final String VIEW_STATE_PARAM = "javax.faces.ViewState";
33      
34      public static final String CLIENT_WINDOW_PARAM = "javax.faces.ClientWindow";
35      public static final String CLIENT_WINDOW_URL_PARAM = "jfwid";
36      
37      public static final String NON_POSTBACK_VIEW_TOKEN_PARAM = "javax.faces.Token";
38  
39      public void writeState(FacesContext context, Object state) throws IOException
40      {
41          SerializedView view;
42          if (state instanceof SerializedView)
43          {
44              view = (SerializedView)state;
45          }
46          else if (state instanceof Object[])
47          {
48              Object[] structureAndState = (Object[])state;
49  
50              if (structureAndState.length == 2)
51              {
52                  Object structureObj = structureAndState[0];
53                  Object stateObj = structureAndState[1];
54  
55                  StateManager stateManager = context.getApplication().getStateManager();
56                  view = stateManager.new SerializedView(structureObj, stateObj);
57              }
58              else
59              {
60                  throw new IOException("The state should be an array of Object[] of lenght 2");
61              }
62          }
63          else
64          {
65              throw new IOException("The state should be an array of Object[] of lenght 2, or a SerializedView instance");
66          }
67  
68          writeState(context, view);
69      }
70  
71      /**
72       * @throws IOException 
73       * @deprecated
74       */
75      public void writeState(FacesContext context, StateManager.SerializedView state) throws IOException
76      {
77          // does nothing as per JSF 1.2 javadoc
78      }
79      
80      /**
81       * 
82       * @since 2.0
83       * @param context
84       * @param state
85       * @return
86       */
87      public String getViewState(FacesContext context, Object state)
88      {
89          // TODO: IMPLEMENT HERE
90          
91          return null;
92      }
93  
94      /**
95       * @since 1.2
96       */
97      public Object getState(FacesContext context, String viewId)
98      {
99          Object[] structureAndState = new Object[2];
100         structureAndState[0] = getTreeStructureToRestore(context, viewId);
101         structureAndState[1] = getComponentStateToRestore(context);
102         return structureAndState;
103     }
104 
105     /**
106      * @deprecated
107      */
108     public Object getTreeStructureToRestore(FacesContext context, String viewId)
109     {
110         return null;
111     }
112 
113     /**
114      * @deprecated
115      */
116     public Object getComponentStateToRestore(FacesContext context)
117     {
118         return null;
119     }
120 
121     /**
122      * Checks if the current request is a postback
123      * 
124      * @since 1.2
125      */
126     public boolean isPostback(FacesContext context)
127     {
128         return context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
129     }
130 
131     /**
132      * @since 2.2
133      * @param context
134      * @return 
135      */
136     public String getCryptographicallyStrongTokenFromSession(FacesContext context)
137     {
138         return null;
139     }
140     
141     /**
142      * @since 2.2
143      * @param context
144      * @param viewId
145      * @return 
146      */
147     public boolean isStateless(FacesContext context, String viewId)
148     {
149         return false;
150     }
151 }