1/*2 * $Id: SessionScopeExtractor.java 1066790 2011-02-03 12:06:20Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */21package org.apache.tiles.request.jsp.extractor;
2223import java.util.Enumeration;
2425import javax.servlet.jsp.PageContext;
2627import org.apache.tiles.request.attribute.AttributeExtractor;
2829/**30 * Extracts attributes from session scope from {@link PageContext}.31 *32 * @version $Rev: 1066790 $ $Date: 2011-02-03 23:06:20 +1100 (Thu, 03 Feb 2011) $33 */34publicclassSessionScopeExtractorimplementsAttributeExtractor {
3536/**37 * The page context.38 */39private PageContext context;
4041/**42 * Constructor.43 *44 * @param context The page context.45 */46publicSessionScopeExtractor(PageContext context) {
47this.context = context;
48 }
4950 @Override
51publicvoid removeValue(String name) {
52if (context.getSession() == null) {
53return;
54 }
55 context.removeAttribute(name, PageContext.SESSION_SCOPE);
56 }
5758 @Override
59public Enumeration<String> getKeys() {
60if (context.getSession() == null) {
61returnnull;
62 }
63return context.getAttributeNamesInScope(PageContext.SESSION_SCOPE);
64 }
6566 @Override
67public Object getValue(String key) {
68if (context.getSession() == null) {
69returnnull;
70 }
71return context.getAttribute(key, PageContext.SESSION_SCOPE);
72 }
7374 @Override
75publicvoid setValue(String key, Object value) {
76if (context.getSession() == null) {
77return;
78 }
79 context.setAttribute(key, value, PageContext.SESSION_SCOPE);
80 }
81 }