001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.util.PropsValues;
018
019 import java.io.IOException;
020 import java.io.Serializable;
021
022 import java.util.Enumeration;
023 import java.util.Map;
024
025 import javax.portlet.PortletPreferences;
026 import javax.portlet.PortletRequest;
027 import javax.portlet.ReadOnlyException;
028 import javax.portlet.ValidatorException;
029
030
033 public class PortletPreferencesWrapper
034 implements PortletPreferences, Serializable {
035
036 public PortletPreferencesWrapper(
037 PortletPreferences portletPreferences, String lifecycle) {
038
039 _portletPreferences = portletPreferences;
040 _lifecycle = lifecycle;
041 }
042
043 public Map<String, String[]> getMap() {
044 return _portletPreferences.getMap();
045 }
046
047 public Enumeration<String> getNames() {
048 return _portletPreferences.getNames();
049 }
050
051 public String getValue(String key, String def) {
052 return _portletPreferences.getValue(key, def);
053 }
054
055 public void setValue(String key, String value) throws ReadOnlyException {
056 _portletPreferences.setValue(key, value);
057 }
058
059 public String[] getValues(String key, String[] def) {
060 return _portletPreferences.getValues(key, def);
061 }
062
063 public void setValues(String key, String[] values)
064 throws ReadOnlyException {
065
066 _portletPreferences.setValues(key, values);
067 }
068
069 public boolean isReadOnly(String key) {
070 return _portletPreferences.isReadOnly(key);
071 }
072
073 public void reset(String key) throws ReadOnlyException {
074 _portletPreferences.reset(key);
075 }
076
077 public void store() throws IOException, ValidatorException {
078 if (PropsValues.TCK_URL) {
079
080
081
082 if (_lifecycle.equals(PortletRequest.ACTION_PHASE)) {
083 _portletPreferences.store();
084 }
085 else {
086 throw new IllegalStateException(
087 "Preferences cannot be stored inside a render call");
088 }
089 }
090 else {
091
092
093
094 _portletPreferences.store();
095 }
096 }
097
098 public PortletPreferencesImpl getPortletPreferencesImpl() {
099 return (PortletPreferencesImpl)_portletPreferences;
100 }
101
102
105 public PortletPreferencesImpl getPreferencesImpl() {
106 return getPortletPreferencesImpl();
107 }
108
109 @Override
110 public boolean equals(Object obj) {
111 PortletPreferencesWrapper portletPreferencesWrapper =
112 (PortletPreferencesWrapper)obj;
113
114 if (this == portletPreferencesWrapper) {
115 return true;
116 }
117
118 if (getPortletPreferencesImpl().equals(
119 portletPreferencesWrapper.getPortletPreferencesImpl())) {
120
121 return true;
122 }
123 else {
124 return false;
125 }
126 }
127
128 @Override
129 public int hashCode() {
130 return _portletPreferences.hashCode();
131 }
132
133 private String _lifecycle;
134 private PortletPreferences _portletPreferences;
135
136 }