1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.util;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portlet.PortalPreferences;
20  import com.liferay.portlet.PortletPreferencesFactoryUtil;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  /**
25   * <a href="SessionClicks.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class SessionClicks {
30  
31      public static final String CLASS_NAME = SessionClicks.class.getName();
32  
33      public static String get(
34          HttpServletRequest request, String key, String defaultValue) {
35  
36          try {
37              PortalPreferences preferences =
38                  PortletPreferencesFactoryUtil.getPortalPreferences(request);
39  
40              return preferences.getValue(CLASS_NAME, key, defaultValue);
41          }
42          catch (Exception e) {
43              _log.error(e, e);
44  
45              return null;
46          }
47      }
48  
49      public static void put(
50          HttpServletRequest request, String key, String value) {
51  
52          try {
53              PortalPreferences preferences =
54                  PortletPreferencesFactoryUtil.getPortalPreferences(request);
55  
56              preferences.setValue(CLASS_NAME, key, value);
57          }
58          catch (Exception e) {
59              _log.error(e, e);
60          }
61      }
62  
63      private static Log _log = LogFactoryUtil.getLog(SessionClicks.class);
64  
65  }