This project has retired. For details please refer to its Attic page.
SessionScopeExtractor xref
View Javadoc

1   /*
2    * $Id: SessionScopeExtractor.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.PageContext;
26  
27  import org.apache.tiles.request.attribute.AttributeExtractor;
28  
29  /**
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   */
34  public class SessionScopeExtractor implements AttributeExtractor {
35  
36      /**
37       * The page context.
38       */
39      private PageContext context;
40  
41      /**
42       * Constructor.
43       *
44       * @param context The page context.
45       */
46      public SessionScopeExtractor(PageContext context) {
47          this.context = context;
48      }
49  
50      @Override
51      public void removeValue(String name) {
52          if (context.getSession() == null) {
53              return;
54          }
55          context.removeAttribute(name, PageContext.SESSION_SCOPE);
56      }
57  
58      @Override
59      public Enumeration<String> getKeys() {
60          if (context.getSession() == null) {
61              return null;
62          }
63          return context.getAttributeNamesInScope(PageContext.SESSION_SCOPE);
64      }
65  
66      @Override
67      public Object getValue(String key) {
68          if (context.getSession() == null) {
69              return null;
70          }
71          return context.getAttribute(key, PageContext.SESSION_SCOPE);
72      }
73  
74      @Override
75      public void setValue(String key, Object value) {
76          if (context.getSession() == null) {
77              return;
78          }
79          context.setAttribute(key, value, PageContext.SESSION_SCOPE);
80      }
81  }