001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.tags.divpanel;
020:
021: import org.apache.beehive.netui.pageflow.interceptor.InterceptorChain;
022: import org.apache.beehive.netui.pageflow.interceptor.InterceptorException;
023: import org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptorContext;
024: import org.apache.beehive.netui.pageflow.requeststate.INameable;
025: import org.apache.beehive.netui.pageflow.requeststate.NameService;
026: import org.apache.beehive.netui.tags.AbstractClientRequestInterceptor;
027: import org.apache.beehive.netui.core.chain.Context;
028: import org.apache.beehive.netui.core.chain.Command;
029: import org.apache.beehive.netui.core.chain.web.WebChainContext;
030:
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: public class DivPanelCRI extends AbstractClientRequestInterceptor
035: implements Command {
036: private static final String SWITCH_PAGE = "switchPage";
037:
038: public boolean execute(Context context) throws Exception {
039:
040: assert context != null;
041: assert context instanceof WebChainContext;
042: assert ((WebChainContext) context).getServletRequest() instanceof HttpServletRequest;
043: assert ((WebChainContext) context).getServletResponse() instanceof HttpServletResponse;
044:
045: WebChainContext webChainContext = (WebChainContext) context;
046: HttpServletRequest request = (HttpServletRequest) webChainContext
047: .getServletRequest();
048: HttpServletResponse response = (HttpServletResponse) webChainContext
049: .getServletResponse();
050:
051: // Create the command by striping off the context path and the extension
052: String uri = request.getRequestURI();
053: String ctxtPath = request.getContextPath();
054:
055: String cmd = getCommand(uri, ctxtPath);
056:
057: return handleCommand(cmd, request, response);
058: }
059:
060: public void preRequest(RequestInterceptorContext ctxt,
061: InterceptorChain chain) throws InterceptorException {
062: HttpServletRequest request = ctxt.getRequest();
063: HttpServletResponse response = ctxt.getResponse();
064:
065: // Create the command by striping off the context path and the extension
066: String uri = request.getRequestURI();
067: String ctxtPath = request.getContextPath();
068:
069: String cmd = getCommand(uri, ctxtPath);
070:
071: handleCommand(cmd, request, response);
072:
073: chain.continueChain();
074: }
075:
076: public void postRequest(RequestInterceptorContext context,
077: InterceptorChain chain) throws InterceptorException {
078: chain.continueChain();
079: }
080:
081: private boolean handleCommand(String command,
082: HttpServletRequest request, HttpServletResponse response) {
083: if (SWITCH_PAGE.equals(command)) {
084: handlePageSwitch(request, response);
085: return true;
086: } else
087: return false;
088: }
089:
090: private void handlePageSwitch(HttpServletRequest request,
091: HttpServletResponse response) {
092: // create an XML empty document, that isn't cached on the client
093: response.setContentType("text/xml");
094: response.setHeader("Pragma", "No-cache");
095: response.setHeader("Cache-Control", "no-cache");
096:
097: String dp = request.getParameter("divPanel");
098: String fp = request.getParameter("firstPage");
099: //System.err.println("DivPanel Command: switch, DivPanel:" + dp + " Node:" + fp);
100:
101: NameService ns = NameService.instance(request.getSession());
102: assert (ns != null);
103:
104: // get the DivPanel from the name service
105: INameable n = ns.get(dp);
106: if (n == null) {
107: System.err.println("DivPanel '" + dp
108: + "' was not found in the NameService");
109: return;
110: }
111: if (!(n instanceof DivPanelState)) {
112: System.err
113: .println("Named dp was not an instance of a DivPanelState");
114: return;
115: }
116:
117: DivPanelState state = (DivPanelState) n;
118: state.setFirstPage(fp);
119: }
120: }
|