01: /*
02: * $Id: AbstractSelectForward.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts.chain.commands;
22:
23: import org.apache.commons.logging.Log;
24: import org.apache.commons.logging.LogFactory;
25: import org.apache.struts.chain.contexts.ActionContext;
26: import org.apache.struts.config.ActionConfig;
27: import org.apache.struts.config.ForwardConfig;
28: import org.apache.struts.config.ModuleConfig;
29:
30: /**
31: * <p>Select and cache the <code>ActionForward</code> for this
32: * <code>ActionConfig</code> if specified.</p>
33: *
34: * @version $Rev: 471754 $ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
35: * $
36: */
37: public abstract class AbstractSelectForward extends ActionCommandBase {
38: // ------------------------------------------------------ Instance Variables
39:
40: /**
41: * <p> Provide Commons Logging instance for this class. </p>
42: */
43: private static final Log LOG = LogFactory
44: .getLog(AbstractSelectForward.class);
45:
46: // ---------------------------------------------------------- Public Methods
47:
48: /**
49: * <p>Select and cache the <code>ActionForward</code> for this
50: * <code>ActionConfig</code> if specified.</p>
51: *
52: * @param actionCtx The <code>Context</code> for the current request
53: * @return <code>false</code> so that processing continues
54: * @throws Exception if thrown by the Action class
55: */
56: public boolean execute(ActionContext actionCtx) throws Exception {
57: // Skip processing if the current request is not valid
58: Boolean valid = actionCtx.getFormValid();
59:
60: if ((valid == null) || !valid.booleanValue()) {
61: return (false);
62: }
63:
64: // Acquire configuration objects that we need
65: ActionConfig actionConfig = actionCtx.getActionConfig();
66: ModuleConfig moduleConfig = actionConfig.getModuleConfig();
67:
68: ForwardConfig forwardConfig = null;
69: String forward = actionConfig.getForward();
70:
71: if (forward != null) {
72: forwardConfig = forward(actionCtx, moduleConfig, forward);
73:
74: if (LOG.isDebugEnabled()) {
75: LOG.debug("Forwarding to " + forwardConfig);
76: }
77:
78: actionCtx.setForwardConfig(forwardConfig);
79: }
80:
81: return (false);
82: }
83:
84: // ------------------------------------------------------- Protected Methods
85:
86: /**
87: * <p>Create and return a <code>ForwardConfig</code> representing the
88: * specified module-relative destination.</p>
89: *
90: * @param context The context for this request
91: * @param moduleConfig The <code>ModuleConfig</code> for this request
92: * @param uri The module-relative URI to be the destination
93: * @return ForwwardConfig representing the destination
94: */
95: protected abstract ForwardConfig forward(ActionContext context,
96: ModuleConfig moduleConfig, String uri);
97: }
|