001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.velocity;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.model.PortletConstants;
020    import com.liferay.portlet.PortletPreferencesImpl;
021    import com.liferay.portlet.PortletPreferencesSerializer;
022    
023    import javax.portlet.ReadOnlyException;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class VelocityPortletPreferences {
029    
030            public VelocityPortletPreferences() {
031                    _preferencesImpl = new PortletPreferencesImpl();
032            }
033    
034            public void reset() {
035                    _preferencesImpl.reset();
036            }
037    
038            public void setValue(String key, String value) throws ReadOnlyException {
039                    _preferencesImpl.setValue(key, value);
040            }
041    
042            public void setValues(String key, String[] values)
043                    throws ReadOnlyException {
044    
045                    _preferencesImpl.setValues(key, values);
046            }
047    
048            public String toString() {
049                    try {
050                            return PortletPreferencesSerializer.toXML(_preferencesImpl);
051                    }
052                    catch (Exception e) {
053                            _log.error(e, e);
054    
055                            return PortletConstants.DEFAULT_PREFERENCES;
056                    }
057            }
058    
059            private static Log _log = LogFactoryUtil.getLog(
060                    VelocityPortletPreferences.class);
061    
062            private PortletPreferencesImpl _preferencesImpl;
063    
064    }