001    /**
002     * Copyright (c) 2000-2011 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.util;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portlet.PortalPreferences;
020    import com.liferay.portlet.PortletPreferencesFactoryUtil;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     * @author Raymond Augé
027     */
028    public class SessionClicks {
029    
030            public static String get(
031                    HttpServletRequest request, String key, String defaultValue) {
032    
033                    return get(request, _DEFAULT_NAMESPACE, key, defaultValue);
034            }
035    
036            public static String get(
037                    HttpServletRequest request, String namespace, String key,
038                    String defaultValue) {
039    
040                    try {
041                            PortalPreferences preferences =
042                                    PortletPreferencesFactoryUtil.getPortalPreferences(request);
043    
044                            return preferences.getValue(namespace, key, defaultValue);
045                    }
046                    catch (Exception e) {
047                            _log.error(e, e);
048    
049                            return null;
050                    }
051            }
052    
053            public static void put(
054                    HttpServletRequest request, String key, String value) {
055    
056                    put(request, _DEFAULT_NAMESPACE, key, value);
057            }
058    
059            public static void put(
060                    HttpServletRequest request, String namespace, String key,
061                    String value) {
062    
063                    try {
064                            PortalPreferences preferences =
065                                    PortletPreferencesFactoryUtil.getPortalPreferences(request);
066    
067                            preferences.setValue(namespace, key, value);
068                    }
069                    catch (Exception e) {
070                            _log.error(e, e);
071                    }
072            }
073    
074            private static final String _DEFAULT_NAMESPACE =
075                    SessionClicks.class.getName();
076    
077            private static Log _log = LogFactoryUtil.getLog(SessionClicks.class);
078    
079    }