1 9 package org.jboss.portal.portlet.invocation; 10 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 import javax.portlet.PortletPreferences; 15 import javax.portlet.PreferencesValidator; 16 17 import org.jboss.portal.portlet.impl.PortletPreferencesImpl; 18 import org.jboss.portal.portlet.plugins.preferences.PortletPreferenceSetPlugin; 19 import org.jboss.portal.server.Component; 20 import org.jboss.portal.server.Instance; 21 import org.jboss.portal.server.PortalConstants; 22 import org.jboss.portal.server.Window; 23 import org.jboss.portal.server.invocation.AttachmentKey; 24 import org.jboss.portal.server.invocation.Interceptor; 25 import org.jboss.portal.server.invocation.Invocation; 26 import org.jboss.portal.server.invocation.InvocationType; 27 import org.jboss.portal.server.plugins.preferences.MergeStrategy; 28 import org.jboss.portal.server.plugins.preferences.MergedPreferenceSet; 29 import org.jboss.portal.server.plugins.preferences.PreferenceSet; 30 import org.jboss.portal.server.plugins.preferences.PreferenceSetPlugin; 31 import org.jboss.portal.server.plugins.preferences.PreferenceStore; 32 import org.jboss.portal.server.plugins.preferences.SimpleMergeStrategy; 33 import org.jboss.portal.server.user.UserContext; 34 35 45 public class PreferencesInterceptor 46 implements Interceptor 47 { 48 49 public Object invoke(Invocation invocation) 50 { 51 InvocationType pitype = (InvocationType)invocation.getAttachment(AttachmentKey.INVOCATION_TYPE); 52 53 boolean isAction = pitype == InvocationType.ACTION; 54 boolean isRender = pitype == InvocationType.RENDER; 55 56 if (isAction || isRender) 57 { 58 UserContext userContext = (UserContext)invocation.getAttachment(AttachmentKey.USER_CONTEXT); 59 Window window = (Window)invocation.getAttachment(PortletKey.WINDOW); 60 Instance instance = window.getInstance(); 61 Component component = instance.getComponent(); 62 63 try 64 { 65 List list = new ArrayList (); 67 68 PortletPreferenceSetPlugin componentPrefs = (PortletPreferenceSetPlugin)component.getPlugin(PortalConstants.PLUGIN_PREFS); 70 PreferencesValidator validator = componentPrefs.getPreferencesValidator(); 71 list.add(componentPrefs); 72 73 PreferenceSetPlugin instancePrefs = (PreferenceSetPlugin)instance.getPlugin(PortalConstants.PLUGIN_PREFS); 75 if (instancePrefs != null) 76 { 77 list.add(instancePrefs); 78 } 79 80 PreferenceStore store = userContext.getPreferenceStore(); 82 PreferenceSet user = store.get(instance.getID()); 83 84 PreferenceSet[] sets = (PreferenceSet[])list.toArray(new PreferenceSet[list.size()]); 86 MergeStrategy strategy = SimpleMergeStrategy.getSingleton(); 87 PreferenceSet system = new MergedPreferenceSet(sets, strategy); 88 int mode = isAction ? PortletPreferencesImpl.ACTION : PortletPreferencesImpl.RENDER; 89 PortletPreferences prefs = new PortletPreferencesImpl(system, user, validator, mode); 90 91 invocation.setAttachment(PortletKey.PORTLET_PREFERENCES, prefs); 93 return invocation.invokeNext(); 94 } 95 finally 96 { 97 invocation.removeAttachment(PortletKey.PORTLET_PREFERENCES); 98 } 99 } 100 else 101 { 102 return invocation.invokeNext(); 103 } 104 } 105 106 } 107 | Popular Tags |