01: /*
02: * $Id: ServletPortletPreferences.java 502294 2007-02-01 17:28:00Z niallp $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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.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)
84: throws ReadOnlyException {
85: getMap().put(key, value);
86: }
87:
88: public void setValues(String key, String[] value)
89: throws ReadOnlyException {
90: getMap().put(key, value);
91: }
92:
93: public void store() throws IOException, ValidatorException {
94:
95: }
96:
97: }
|