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.common;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.Map;
024: import java.util.Set;
025: import javax.servlet.ServletRequest;
026: import javax.servlet.http.HttpServletRequest;
027:
028: import org.apache.beehive.netui.pageflow.PageFlowUtils;
029: import org.apache.beehive.netui.pageflow.internal.InternalUtils;
030: import org.apache.beehive.netui.util.logging.Logger;
031:
032: /**
033: * <p>
034: * Provide a {@link java.util.Map} object that exposes a set of page inputs to
035: * expression language clients. Access to these page inputs is based on the
036: * name of the page input.
037: * </p>
038: * <p>
039: * Access is optimized for read in that the "get" method is fast. The entrySet()
040: * method is only used if needed, which is generally to toString the Map.
041: * </p>
042: * @deprecated
043: */
044: public class ScriptablePageInput extends AbstractScriptableMap {
045:
046: private static final Logger LOGGER = Logger
047: .getInstance(ScriptablePageInput.class);
048:
049: private HttpServletRequest _request = null;
050: private Set _entrySet = null;
051:
052: public ScriptablePageInput(ServletRequest request) {
053: assert request instanceof HttpServletRequest;
054:
055: _request = (HttpServletRequest) request;
056: }
057:
058: public Object get(Object name) {
059: if (LOGGER.isDebugEnabled())
060: LOGGER.debug("page input get: " + name);
061:
062: assert name instanceof String;
063:
064: return PageFlowUtils.getActionOutput((String) name, _request);
065: }
066:
067: /**
068: * Create a {@link java.util.Set} of page input entries. This implementation
069: * assumes that the page input set does not change, which is acceptable for
070: * JSP clients as the page inputs have been specified when the JSP starts
071: * to render.
072: *
073: * @return Set
074: */
075: public Set entrySet() {
076: if (_entrySet == null) {
077: Map piMap = InternalUtils.getPageInputMap(_request);
078: ArrayList list = new ArrayList();
079: if (piMap != null) {
080: Iterator iterator = piMap.keySet().iterator();
081: while (iterator.hasNext()) {
082: Object name = iterator.next();
083: Object value = piMap.get(name);
084: list.add(new Entry(name, value));
085: }
086: }
087:
088: _entrySet = new EntrySet((Entry[]) list
089: .toArray(new Entry[] {}));
090: }
091:
092: return _entrySet;
093: }
094:
095: public boolean equals(Object obj) {
096: if (obj == null || !(obj instanceof ScriptablePageInput))
097: return false;
098: return super .equals(obj);
099: }
100:
101: public boolean containsKey(Object key) {
102: Map piMap = InternalUtils.getPageInputMap(_request);
103: return (piMap != null && piMap.containsKey(key));
104: }
105: }
|