1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.tiles.request.jakarta.servlet.extractor;
17
18 import java.util.Collections;
19 import java.util.Enumeration;
20
21 import org.apache.tiles.request.attribute.AttributeExtractor;
22
23 import jakarta.servlet.http.HttpServletRequest;
24 import jakarta.servlet.http.HttpSession;
25
26
27
28
29
30
31
32 public class SessionScopeExtractor implements AttributeExtractor {
33
34
35
36
37 private HttpServletRequest request;
38
39
40
41
42
43
44 public SessionScopeExtractor(HttpServletRequest request) {
45 this.request = request;
46 }
47
48
49
50
51
52
53
54 @Override
55 public void setValue(String name, Object value) {
56 request.getSession().setAttribute(name, value);
57 }
58
59
60
61
62
63
64 @Override
65 public void removeValue(String name) {
66 HttpSession session = request.getSession(false);
67 if (session != null) {
68 session.removeAttribute(name);
69 }
70 }
71
72
73
74
75
76
77 @Override
78 public Enumeration<String> getKeys() {
79 HttpSession session = request.getSession(false);
80 if (session != null) {
81 return session.getAttributeNames();
82 }
83
84 return Collections.enumeration(Collections.<String>emptySet());
85 }
86
87
88
89
90
91
92
93
94 @Override
95 public Object getValue(String key) {
96 HttpSession session = request.getSession(false);
97 if (session != null) {
98 return session.getAttribute(key);
99 }
100
101 return null;
102 }
103 }