001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import java.io.IOException;
018    import java.io.Serializable;
019    
020    import java.util.Enumeration;
021    import java.util.Map;
022    
023    import javax.portlet.PortletPreferences;
024    import javax.portlet.ReadOnlyException;
025    import javax.portlet.ValidatorException;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class PortletPreferencesWrapper
031            implements PortletPreferences, Serializable {
032    
033            public PortletPreferencesWrapper(PortletPreferences portletPreferences) {
034                    _portletPreferences = portletPreferences;
035            }
036    
037            /**
038             * @deprecated
039             */
040            public PortletPreferencesWrapper(
041                    PortletPreferences portletPreferences, String lifecycle) {
042    
043                    _portletPreferences = portletPreferences;
044            }
045    
046            @Override
047            public boolean equals(Object obj) {
048                    if (this == obj) {
049                            return true;
050                    }
051    
052                    if (!(obj instanceof PortletPreferencesWrapper)) {
053                            return false;
054                    }
055    
056                    PortletPreferencesWrapper portletPreferencesWrapper =
057                            (PortletPreferencesWrapper)obj;
058    
059                    if (getPortletPreferencesImpl().equals(
060                                    portletPreferencesWrapper.getPortletPreferencesImpl())) {
061    
062                            return true;
063                    }
064                    else {
065                            return false;
066                    }
067            }
068    
069            @Override
070            public Map<String, String[]> getMap() {
071                    return _portletPreferences.getMap();
072            }
073    
074            @Override
075            public Enumeration<String> getNames() {
076                    return _portletPreferences.getNames();
077            }
078    
079            public PortletPreferencesImpl getPortletPreferencesImpl() {
080                    return (PortletPreferencesImpl)_portletPreferences;
081            }
082    
083            /**
084             * @deprecated As of 6.1.0, replaced by {@link #getPortletPreferencesImpl}
085             */
086            public PortletPreferencesImpl getPreferencesImpl() {
087                    return getPortletPreferencesImpl();
088            }
089    
090            @Override
091            public String getValue(String key, String def) {
092                    return _portletPreferences.getValue(key, def);
093            }
094    
095            @Override
096            public String[] getValues(String key, String[] def) {
097                    return _portletPreferences.getValues(key, def);
098            }
099    
100            @Override
101            public int hashCode() {
102                    return _portletPreferences.hashCode();
103            }
104    
105            @Override
106            public boolean isReadOnly(String key) {
107                    return _portletPreferences.isReadOnly(key);
108            }
109    
110            @Override
111            public void reset(String key) throws ReadOnlyException {
112                    _portletPreferences.reset(key);
113            }
114    
115            @Override
116            public void setValue(String key, String value) throws ReadOnlyException {
117                    _portletPreferences.setValue(key, value);
118            }
119    
120            @Override
121            public void setValues(String key, String[] values)
122                    throws ReadOnlyException {
123    
124                    _portletPreferences.setValues(key, values);
125            }
126    
127            @Override
128            public void store() throws IOException, ValidatorException {
129    
130                    // PLT.17.1, clv
131    
132                    throw new IllegalStateException(
133                            "Preferences cannot be stored inside a render call");
134            }
135    
136            private PortletPreferences _portletPreferences;
137    
138    }