View Javadoc
1   /*
2    * $Id$
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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.struts.chain.contexts.ActionContext;
24  import org.apache.struts.config.ActionConfig;
25  import org.apache.struts.config.ForwardConfig;
26  import org.apache.struts.config.ModuleConfig;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  /**
31   * <p>Select and cache the <code>ActionForward</code> for this
32   * <code>ActionConfig</code> if specified.</p>
33   *
34   * @version $Rev$ $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       * The {@code Log} instance for this class.
42       */
43      private final Logger log =
44          LoggerFactory.getLogger(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      @Override
57      protected boolean execute_(ActionContext actionCtx)
58          throws Exception {
59          // Skip processing if the current request is not valid
60          Boolean valid = actionCtx.getFormValid();
61  
62          if ((valid == null) || !valid.booleanValue()) {
63              return CONTINUE_PROCESSING;
64          }
65  
66          // Acquire configuration objects that we need
67          ActionConfig actionConfig = actionCtx.getActionConfig();
68          ModuleConfig moduleConfig = actionConfig.getModuleConfig();
69  
70          ForwardConfig forwardConfig = null;
71          String forward = actionConfig.getForward();
72  
73          if (forward != null) {
74              forwardConfig = forward(actionCtx, moduleConfig, forward);
75  
76              log.debug("Forwarding to {}", forwardConfig);
77  
78              actionCtx.setForwardConfig(forwardConfig);
79          }
80  
81          return CONTINUE_PROCESSING;
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  }