1 48 49 package com.caucho.portal.generic; 50 51 import javax.portlet.PortletRequest; 52 import javax.portlet.PortletSession; 53 import java.util.Map ; 54 55 62 public class SessionPreferencesStore 63 implements PreferencesStore 64 { 65 66 private final static String SESSION_PREFERENCES 67 = "com.caucho.portal.generic.SessionPreferences"; 68 69 private boolean _alwaysCreateSession = true; 70 71 75 public void setAlwaysCreateSession(boolean alwaysCreateSession) 76 { 77 _alwaysCreateSession = alwaysCreateSession; 78 } 79 80 public Map <String , String []> getPreferencesMap( PortletRequest request, 81 String namespace ) 82 { 83 SessionPreferences pref = null; 84 85 PortletSession session = request.getPortletSession(_alwaysCreateSession); 86 87 if (session != null) { 88 91 String attributeName = SESSION_PREFERENCES; 92 93 if (namespace.length() > 0) { 94 int len = SESSION_PREFERENCES.length() + namespace.length() + 2; 95 StringBuffer buf = new StringBuffer (len); 96 buf.append(SESSION_PREFERENCES); 97 buf.append('.'); 98 buf.append(namespace); 99 attributeName = buf.toString(); 100 } 101 102 synchronized (session) { 103 pref = (SessionPreferences) session.getAttribute(attributeName); 104 105 if (pref == null) { 106 pref = new SessionPreferences(); 107 session.setAttribute(attributeName, pref); 108 } 109 } 110 } 111 112 return pref; 113 } 114 115 public void finish(Map <String , String []> preferences) 116 { 117 SessionPreferences pref = (SessionPreferences) preferences; 118 pref.updateSessionIfNeeded(); 119 } 120 } 121 122 | Popular Tags |