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.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.PortletPreferencesFactoryUtil;
021    import com.liferay.portlet.PortletPreferencesImpl;
022    
023    import javax.portlet.ReadOnlyException;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class VelocityPortletPreferences {
029    
030            public VelocityPortletPreferences() {
031                    _portletPreferencesImpl = new PortletPreferencesImpl();
032            }
033    
034            public void reset() {
035                    _portletPreferencesImpl.reset();
036            }
037    
038            public void setValue(String key, String value) throws ReadOnlyException {
039                    _portletPreferencesImpl.setValue(key, value);
040            }
041    
042            public void setValues(String key, String[] values)
043                    throws ReadOnlyException {
044    
045                    _portletPreferencesImpl.setValues(key, values);
046            }
047    
048            @Override
049            public String toString() {
050                    try {
051                            return PortletPreferencesFactoryUtil.toXML(_portletPreferencesImpl);
052                    }
053                    catch (Exception e) {
054                            _log.error(e, e);
055    
056                            return PortletConstants.DEFAULT_PREFERENCES;
057                    }
058            }
059    
060            private static Log _log = LogFactoryUtil.getLog(
061                    VelocityPortletPreferences.class);
062    
063            private PortletPreferencesImpl _portletPreferencesImpl;
064    
065    }