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