1 /* 2 * Copyright 2003,2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 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.struts.config.ForwardConfig; 23 24 25 /** 26 * <p>Perform forwarding or redirection based on the specified 27 * <code>ForwardConfig</code> (if any).</p> 28 * 29 * @author Craig R. McClanahan 30 * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $ 31 */ 32 33 public abstract class AbstractPerformForward implements Command { 34 35 36 // ------------------------------------------------------ Instance Variables 37 38 39 private String forwardConfigKey = Constants.FORWARD_CONFIG_KEY; 40 41 private String moduleConfigKey = Constants.MODULE_CONFIG_KEY; 42 43 44 // -------------------------------------------------------------- Properties 45 46 47 /** 48 * <p>Return the context attribute key under which the 49 * <code>ForwardConfig</code> for the currently selected application 50 * action is stored.</p> 51 */ 52 public String getForwardConfigKey() { 53 54 return (this.forwardConfigKey); 55 56 } 57 58 59 /** 60 * <p>Set the context attribute key under which the 61 * <code>ForwardConfig</code> for the currently selected application 62 * action is stored.</p> 63 * 64 * @param forwardConfigKey The new context attribute key 65 */ 66 public void setForwardConfigKey(String forwardConfigKey) { 67 68 this.forwardConfigKey = forwardConfigKey; 69 70 } 71 72 /** 73 * <p>Return the context attribute key under which the 74 * <code>ModuleConfig</code> for the currently selected application 75 * module will be stored.</p> 76 */ 77 public String getModuleConfigKey() { 78 79 return (this.moduleConfigKey); 80 81 } 82 83 84 /** 85 * <p>Set the context attribute key under which the 86 * <code>ModuleConfig</code> for the currently selected application 87 * module will be stored.</p> 88 * 89 * @param moduleConfigKey The new context attribute key 90 */ 91 public void setModuleConfigKey(String moduleConfigKey) { 92 93 this.moduleConfigKey = moduleConfigKey; 94 95 } 96 97 98 // ---------------------------------------------------------- Public Methods 99 100 101 /** 102 * <p>Perform forwarding or redirection based on the specified 103 * <code>ActionForward</code> (if any).</p> 104 * 105 * @param context The <code>Context</code> for the current request 106 * 107 * @return <code>true</code> so that processing completes 108 */ 109 public boolean execute(Context context) throws Exception { 110 111 // Is there a ForwardConfig to be performed? 112 ForwardConfig forwardConfig = (ForwardConfig) 113 context.get(getForwardConfigKey()); 114 if (forwardConfig == null) { 115 return (false); 116 } 117 118 // Perform the appropriate processing on this ActionForward 119 perform(context, forwardConfig); 120 return (true); 121 122 } 123 124 125 // ------------------------------------------------------- Protected Methods 126 127 128 /** 129 * <p>Perform the appropriate processing on the specified 130 * <code>ForwardConfig</code>.</p> 131 * 132 * @param context The context for this request 133 * @param forwardConfig The forward to be performed 134 */ 135 protected abstract void perform(Context context, 136 ForwardConfig forwardConfig) 137 throws Exception; 138 139 140 }