1 /*
2 * $Id: ScopeExtractor.java 1066790 2011-02-03 12:06:20Z apetrelli $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 package org.apache.tiles.request.jsp.extractor;
22
23 import java.util.Enumeration;
24
25 import javax.servlet.jsp.JspContext;
26
27 import org.apache.tiles.request.attribute.AttributeExtractor;
28
29 /**
30 * Extracts attributes from a numbered scope from {@link JspContext}.
31 *
32 * @version $Rev: 1066790 $ $Date: 2011-02-03 23:06:20 +1100 (Thu, 03 Feb 2011) $
33 */
34 public class ScopeExtractor implements AttributeExtractor {
35
36 /**
37 * The JSP context.
38 */
39 private JspContext context;
40
41 /**
42 * The scope number to use.
43 */
44 private int scope;
45
46 /**
47 * Constructor.
48 *
49 * @param context The JSP context.
50 * @param scope The scope number.
51 */
52 public ScopeExtractor(JspContext context, int scope) {
53 this.context = context;
54 this.scope = scope;
55 }
56
57 @Override
58 public void removeValue(String name) {
59 context.removeAttribute(name, scope);
60 }
61
62 @Override
63 public Enumeration<String> getKeys() {
64 return context.getAttributeNamesInScope(scope);
65 }
66
67 @Override
68 public Object getValue(String key) {
69 return context.getAttribute(key, scope);
70 }
71
72 @Override
73 public void setValue(String key, Object value) {
74 context.setAttribute(key, value, scope);
75 }
76 }