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            /**
031             * @deprecated {@link #_DEFAULT_NAMESPACE}
032             */
033            public static final String CLASS_NAME = SessionClicks.class.getName();
034    
035            public static String get(
036                    HttpServletRequest request, String key, String defaultValue) {
037    
038                    return get(request, _DEFAULT_NAMESPACE, key, defaultValue);
039            }
040    
041            public static String get(
042                    HttpServletRequest request, String namespace, String key,
043                    String defaultValue) {
044    
045                    try {
046                            PortalPreferences preferences =
047                                    PortletPreferencesFactoryUtil.getPortalPreferences(request);
048    
049                            return preferences.getValue(namespace, key, defaultValue);
050                    }
051                    catch (Exception e) {
052                            _log.error(e, e);
053    
054                            return null;
055                    }
056            }
057    
058            public static void put(
059                    HttpServletRequest request, String key, String value) {
060    
061                    put(request, _DEFAULT_NAMESPACE, key, value);
062            }
063    
064            public static void put(
065                    HttpServletRequest request, String namespace, String key,
066                    String value) {
067    
068                    try {
069                            PortalPreferences preferences =
070                                    PortletPreferencesFactoryUtil.getPortalPreferences(request);
071    
072                            preferences.setValue(namespace, key, value);
073                    }
074                    catch (Exception e) {
075                            _log.error(e, e);
076                    }
077            }
078    
079            private static final String _DEFAULT_NAMESPACE =
080                    SessionClicks.class.getName();
081    
082            private static Log _log = LogFactoryUtil.getLog(SessionClicks.class);
083    
084    }