001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet;
022:
023: import com.liferay.portal.util.PropsValues;
024:
025: import java.io.IOException;
026: import java.io.Serializable;
027:
028: import java.util.Enumeration;
029: import java.util.Map;
030:
031: import javax.portlet.PortletPreferences;
032: import javax.portlet.ReadOnlyException;
033: import javax.portlet.ValidatorException;
034:
035: /**
036: * <a href="PortletPreferencesWrapper.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Brian Wing Shun Chan
039: *
040: */
041: public class PortletPreferencesWrapper implements PortletPreferences,
042: Serializable {
043:
044: public PortletPreferencesWrapper(PortletPreferences prefs,
045: boolean action) {
046: _prefs = prefs;
047: _action = action;
048: }
049:
050: public Map getMap() {
051: return _prefs.getMap();
052: }
053:
054: public Enumeration getNames() {
055: return _prefs.getNames();
056: }
057:
058: public String getValue(String key, String def) {
059: return _prefs.getValue(key, def);
060: }
061:
062: public void setValue(String key, String value)
063: throws ReadOnlyException {
064: _prefs.setValue(key, value);
065: }
066:
067: public String[] getValues(String key, String[] def) {
068: return _prefs.getValues(key, def);
069: }
070:
071: public void setValues(String key, String[] values)
072: throws ReadOnlyException {
073:
074: _prefs.setValues(key, values);
075: }
076:
077: public boolean isReadOnly(String key) {
078: return _prefs.isReadOnly(key);
079: }
080:
081: public void reset(String key) throws ReadOnlyException {
082: _prefs.reset(key);
083: }
084:
085: public void store() throws IOException, ValidatorException {
086: if (PropsValues.TCK_URL) {
087:
088: // Be strict to pass the TCK
089:
090: if (_action) {
091: _prefs.store();
092: } else {
093: throw new IllegalStateException(
094: "Preferences cannot be stored inside a render call");
095: }
096: } else {
097:
098: // Relax so that poorly written portlets can still work
099:
100: _prefs.store();
101: }
102: }
103:
104: public PortletPreferencesImpl getPreferencesImpl() {
105: return (PortletPreferencesImpl) _prefs;
106: }
107:
108: private PortletPreferences _prefs = null;
109: private boolean _action;
110:
111: }
|