1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.portlet.interceptor;
23
24 import java.io.IOException;
25 import java.util.Enumeration;
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.Vector;
29
30 import javax.portlet.PortletPreferences;
31 import javax.portlet.ReadOnlyException;
32 import javax.portlet.ValidatorException;
33
34 /***
35 * Simple portlet preferences implementation that uses a map in the Session
36 * as storage.
37 */
38 public class ServletPortletPreferences implements PortletPreferences {
39
40 private Map session;
41 private String PREFERENCES_KEY = "_portlet-preferences";
42
43 public ServletPortletPreferences(Map session) {
44 this.session = session;
45 }
46
47 public Map getMap() {
48 Map map = (Map) session.get(PREFERENCES_KEY);
49 if (map == null) {
50 map = new HashMap();
51 session.put(PREFERENCES_KEY, map);
52 }
53 return map;
54 }
55
56 public Enumeration getNames() {
57 return new Vector(getMap().keySet()).elements();
58 }
59
60 public String getValue(String key, String def) {
61 String val = (String) getMap().get(key);
62 if (val == null) {
63 val = def;
64 }
65 return val;
66 }
67
68 public String[] getValues(String key, String[] def) {
69 String[] val = (String[]) getMap().get(key);
70 if (val == null) {
71 val = def;
72 }
73 return val;
74 }
75
76 public boolean isReadOnly(String arg0) {
77 return false;
78 }
79
80 public void reset(String arg0) throws ReadOnlyException {
81 session.put(PREFERENCES_KEY, new HashMap());
82 }
83
84 public void setValue(String key, String value) throws ReadOnlyException {
85 getMap().put(key, value);
86 }
87
88 public void setValues(String key, String[] value) throws ReadOnlyException {
89 getMap().put(key, value);
90 }
91
92 public void store() throws IOException, ValidatorException {
93
94 }
95
96 }