001: /*
002: * Copyright 2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package javax.faces.render;
017:
018: import javax.faces.application.StateManager;
019: import javax.faces.application.StateManager.SerializedView;
020: import javax.faces.context.FacesContext;
021: import java.io.IOException;
022:
023: /**
024: * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
025: *
026: * @author Manfred Geiler (latest modification by $Author: mbr $)
027: * @author Stan Silvert
028: * @version $Revision: 512227 $ $Date: 2007-02-27 13:25:16 +0100 (Di, 27 Feb 2007) $
029: */
030: public abstract class ResponseStateManager {
031: public static final String RENDER_KIT_ID_PARAM = "javax.faces.RenderKitId";
032: public static final String VIEW_STATE_PARAM = "javax.faces.ViewState";
033:
034: public void writeState(FacesContext context, Object state)
035: throws IOException {
036: SerializedView view;
037: if (state instanceof SerializedView) {
038: view = (SerializedView) state;
039: } else if (state instanceof Object[]) {
040: Object[] structureAndState = (Object[]) state;
041:
042: if (structureAndState.length == 2) {
043: Object structureObj = structureAndState[0];
044: Object stateObj = structureAndState[1];
045:
046: StateManager stateManager = context.getApplication()
047: .getStateManager();
048: view = stateManager.new SerializedView(structureObj,
049: stateObj);
050: } else {
051: throw new IOException(
052: "The state should be an array of Object[] of lenght 2");
053: }
054: } else {
055: throw new IOException(
056: "The state should be an array of Object[] of lenght 2, or a SerializedView instance");
057: }
058:
059: writeState(context, view);
060: }
061:
062: /**
063: * @deprecated
064: */
065: public void writeState(FacesContext context,
066: StateManager.SerializedView state) throws IOException {
067: // does nothing as per JSF 1.2 javadoc
068: }
069:
070: /**
071: * @since 1.2
072: */
073: public Object getState(FacesContext context, String viewId) {
074: Object[] structureAndState = new Object[2];
075: structureAndState[0] = getTreeStructureToRestore(context,
076: viewId);
077: structureAndState[1] = getComponentStateToRestore(context);
078: return structureAndState;
079: }
080:
081: /**
082: * @deprecated
083: */
084: public Object getTreeStructureToRestore(FacesContext context,
085: String viewId) {
086: return null;
087: }
088:
089: /**
090: * @deprecated
091: */
092: public Object getComponentStateToRestore(FacesContext context) {
093: return null;
094: }
095:
096: /**
097: * Checks if the current request is a postback
098: * @since 1.2
099: */
100: public boolean isPostback(FacesContext context) {
101: return context.getExternalContext().getRequestParameterMap()
102: .size() > 0;
103: }
104:
105: }
|