1 package org.apache.turbine.modules.actions; 2 3 56 57 import java.lang.reflect.Method ; 58 import java.util.Enumeration ; 59 60 import org.apache.fulcrum.parser.ParameterParser; 61 import org.apache.turbine.RunData; 62 import org.apache.turbine.TemplateContext; 63 import org.apache.turbine.modules.ActionEvent; 64 65 82 public abstract class TemplateAction 83 extends ActionEvent 84 { 85 86 93 public void doPerform( RunData data ) 94 throws Exception 95 { 96 doPerform(data, getTemplateContext(data)); 97 } 98 99 107 public void doPerform( RunData data, TemplateContext context ) 108 throws Exception 109 { 110 } 111 112 119 public void executeEvents(RunData data) 120 throws Exception 121 { 122 String theButton = null; 124 125 ParameterParser pp = data.getParameters(); 127 128 String button = pp.convert(BUTTON); 129 130 for (Enumeration e = pp.keys() ; e.hasMoreElements() ;) 132 { 133 String key = (String ) e.nextElement(); 134 if (key.startsWith(button)) 135 { 136 theButton = formatString(key); 137 break; 138 } 139 } 140 141 if (theButton == null) 142 { 143 throw new NoSuchMethodException ( 144 "ActionEvent: The button was null"); 145 } 146 147 try 148 { 149 Class [] classes = new Class [2]; 151 classes[0] = RunData.class; 152 classes[1] = TemplateContext.class; 153 154 Object [] args = new Object [2]; 156 157 Method method = getClass().getMethod(theButton, classes); 158 args[0] = data; 159 args[1] = getTemplateContext(data); 160 method.invoke(this, args); 161 } 162 catch (NoSuchMethodException nsme) 163 { 164 super.executeEvents(data); 166 } 167 } 168 } 169 | Popular Tags |