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.script.el;
020:
021: import javax.servlet.ServletRequest;
022: import javax.servlet.ServletResponse;
023: import javax.servlet.http.HttpServletRequest;
024:
025: import org.apache.beehive.netui.script.IllegalExpressionException;
026: import org.apache.beehive.netui.script.common.ImplicitObjectUtil;
027: import org.apache.beehive.netui.script.el.util.RequestAttributeMapFacade;
028: import org.apache.beehive.netui.script.el.util.SessionAttributeMapFacade;
029: import org.apache.beehive.netui.util.logging.Logger;
030:
031: /**
032: *
033: */
034: public class NetUIUpdateVariableResolver extends NetUIVariableResolver {
035:
036: private static final Logger LOGGER = Logger
037: .getInstance(NetUIVariableResolver.class);
038:
039: private boolean _requestParameter = true;
040: private Object _form = null;
041: private ServletRequest _request = null;
042: private ServletResponse _response = null;
043:
044: public NetUIUpdateVariableResolver(Object form,
045: ServletRequest request, ServletResponse response,
046: boolean requestParameter) {
047: super ();
048:
049: _requestParameter = requestParameter;
050: _form = form;
051: _request = request;
052: _response = response;
053: }
054:
055: public Object resolveVariable(String name) {
056: if (name.equals("actionForm"))
057: return _form;
058: else if (name.equals("pageFlow"))
059: return ImplicitObjectUtil.getPageFlow(_request, _response);
060: else if (name.equals("globalApp"))
061: return ImplicitObjectUtil.getGlobalApp(_request);
062: else if (name.equals("sharedFlow"))
063: return ImplicitObjectUtil.getSharedFlow(_request);
064: else if (name.equals("requestScope")) {
065: if (!_requestParameter)
066: return new RequestAttributeMapFacade(_request);
067: else
068: throw new IllegalExpressionException(
069: "The request data binding context can not be updated from a request parameter.");
070: } else if (name.equals("sessionScope")) {
071: if (!_requestParameter)
072: return new SessionAttributeMapFacade(
073: ((HttpServletRequest) _request).getSession());
074: else
075: throw new IllegalExpressionException(
076: "The session data binding context can not be updated from a request parameter.");
077: }
078: // @bug: need to get the ServletContext from somewhere
079: else if (name.equals("applicationScope")) {
080: if (!_requestParameter)
081: return null;
082: else
083: throw new IllegalExpressionException(
084: "The application data binding context can not be updated from a request parameter.");
085: } else {
086: String msg = "Could not resolve variable named \"" + name
087: + "\" for an expression update.";
088: LOGGER.error(msg);
089: throw new IllegalExpressionException(msg);
090: }
091: }
092:
093: public String[] getAvailableVariables() {
094: if (_requestParameter)
095: return new String[] { "actionForm", "pageFlow", "globalApp" };
096: else
097: return new String[] { "actionForm", "pageFlow",
098: "globalApp", "request", "session", "application" };
099: }
100: }
|