1 16 17 package org.apache.struts.chain; 18 19 20 import org.apache.commons.chain.Command; 21 import org.apache.commons.chain.Context; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.struts.config.ActionConfig; 25 import org.apache.struts.config.ForwardConfig; 26 import org.apache.struts.config.ModuleConfig; 27 28 29 36 37 public abstract class AbstractSelectForward implements Command { 38 39 40 42 43 private String actionConfigKey = Constants.ACTION_CONFIG_KEY; 44 private String forwardConfigKey = Constants.FORWARD_CONFIG_KEY; 45 private String validKey = Constants.VALID_KEY; 46 47 private static final Log log = 48 LogFactory.getLog(AbstractSelectForward.class); 49 50 51 53 54 59 public String getActionConfigKey() { 60 61 return (this.actionConfigKey); 62 63 } 64 65 66 73 public void setActionConfigKey(String actionConfigKey) { 74 75 this.actionConfigKey = actionConfigKey; 76 77 } 78 79 80 85 public String getForwardConfigKey() { 86 87 return (this.forwardConfigKey); 88 89 } 90 91 92 99 public void setForwardConfigKey(String forwardConfigKey) { 100 101 this.forwardConfigKey = forwardConfigKey; 102 103 } 104 105 106 110 public String getValidKey() { 111 112 return (this.validKey); 113 114 } 115 116 117 123 public void setValidKey(String validKey) { 124 125 this.validKey = validKey; 126 127 } 128 129 130 132 133 141 public boolean execute(Context context) throws Exception { 142 143 Boolean valid = (Boolean ) context.get(getValidKey()); 145 if ((valid == null) || !valid.booleanValue()) { 146 return (false); 147 } 148 149 ActionConfig actionConfig = (ActionConfig) 151 context.get(getActionConfigKey()); 152 ModuleConfig moduleConfig = actionConfig.getModuleConfig(); 153 154 ForwardConfig forwardConfig = null; 155 String forward = actionConfig.getForward(); 156 if (forward != null) { 157 forwardConfig = forward(context, moduleConfig, forward); 158 if (log.isDebugEnabled()) { 159 log.debug("Forwarding to " + forwardConfig); 160 } 161 context.put(getForwardConfigKey(), forwardConfig); 162 } 163 return (false); 164 165 } 166 167 168 170 171 179 protected abstract ForwardConfig forward(Context context, 180 ModuleConfig moduleConfig, 181 String uri); 182 183 184 185 } 186 | Popular Tags |