1 16 21 package org.apache.jetspeed.modules.actions.portlets; 22 23 import java.lang.reflect.Method ; 24 25 import java.util.Enumeration ; 26 import java.util.HashMap ; 27 28 import org.apache.jetspeed.portal.Portlet; 29 import org.apache.jetspeed.portal.portlets.GenericMVCPortlet; 30 import org.apache.jetspeed.util.PortletSessionState; 31 import org.apache.turbine.modules.ActionEvent; 32 import org.apache.turbine.services.velocity.TurbineVelocity; 33 import org.apache.turbine.util.ParameterParser; 34 import org.apache.turbine.util.RunData; 35 36 import org.apache.velocity.context.Context; 37 38 39 49 public abstract class PortletActionEvent 50 extends ActionEvent 51 { 52 53 57 private static final HashMap eventMethods = new HashMap (); 58 59 66 public abstract void doPerform(RunData data) 67 throws Exception ; 68 69 77 protected void perform(RunData data) 78 throws Exception 79 { 80 81 try 82 { 83 executeEvents(data, TurbineVelocity.getContext(data)); 84 } 85 catch (NoSuchMethodException e) 86 { 87 doPerform(data); 88 } 89 } 90 91 98 public void executeEvents(RunData data, Context context) 99 throws Exception 100 { 101 102 String theButton = null; 104 105 Portlet portlet = (Portlet) context.get(GenericMVCPortlet.PORTLET); 107 108 ParameterParser pp = data.getParameters(); 110 String button = pp.convert(BUTTON); 111 112 for (Enumeration e = pp.keys(); e.hasMoreElements();) 114 { 115 116 String key = (String ) e.nextElement(); 117 118 if (key.startsWith(button)) 119 { 120 theButton = formatString(key); 121 122 break; 123 } 124 } 125 126 if (theButton == null ) 127 { 128 throw new NoSuchMethodException ("ActionEvent: The button was null"); 129 } 130 131 132 133 if (!fireEvent(data, Context.class, context, theButton) && PortletSessionState.isMyRequest(data, portlet)) 134 { 135 if (!fireEvent(data, Portlet.class, 138 portlet, 139 theButton)) 140 { 141 super.executeEvents(data); 143 } 144 } 145 146 } 147 148 152 protected boolean fireEvent(RunData data, Class deltaClass, Object deltaValue, String theButton) 153 { 154 try 155 { 156 Class [] classes = new Class [2]; 158 classes[0] = RunData.class; 159 classes[1] = deltaClass; 160 161 Object [] args = new Object [2]; 163 164 String methodKey = getClass().getName()+":" 165 +theButton+":"+classes[0].getName() 166 +":"+classes[1].getName(); 167 168 Method method = (Method )eventMethods.get(methodKey); 169 if(method == null) 170 { 171 method = getClass().getMethod(theButton, classes); 172 eventMethods.put(methodKey, method); 173 } 174 args[0] = data; 175 args[1] = deltaValue; 176 method.invoke(this, args); 177 return true; 178 } 179 catch (Exception e) 180 { 181 return false; 182 } 183 184 } 185 186 187 } 188 | Popular Tags |