001: /*
002: * $Id: AbstractSelectInput.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.chain.commands;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.struts.chain.contexts.ActionContext;
026: import org.apache.struts.config.ActionConfig;
027: import org.apache.struts.config.ForwardConfig;
028: import org.apache.struts.config.ModuleConfig;
029:
030: /**
031: * <p>Select and cache a <code>ForwardConfig</code> that returns us to the
032: * input page for the current action, if any.</p>
033: *
034: * @version $Rev: 471754 $ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
035: * $
036: */
037: public abstract class AbstractSelectInput extends ActionCommandBase {
038: // ------------------------------------------------------ Instance Variables
039:
040: /**
041: * <p> Provide Commons Logging instance for this class. </p>
042: */
043: private static final Log LOG = LogFactory
044: .getLog(AbstractSelectInput.class);
045:
046: // ---------------------------------------------------------- Public Methods
047:
048: /**
049: * <p>Select and cache a <code>ForwardConfig</code> for the input page for
050: * the current request.</p>
051: *
052: * @param actionCtx The <code>Context</code> for the current request
053: * @return <code>false</code> so that processing continues
054: * @throws Exception if thrown by the Action class
055: */
056: public boolean execute(ActionContext actionCtx) throws Exception {
057: // Skip processing if the current request is valid
058: Boolean valid = actionCtx.getFormValid();
059:
060: if ((valid != null) && valid.booleanValue()) {
061: return (false);
062: }
063:
064: // Acquire configuration objects that we need
065: ActionConfig actionConfig = actionCtx.getActionConfig();
066: ModuleConfig moduleConfig = actionConfig.getModuleConfig();
067:
068: // Cache an ForwardConfig back to our input page
069: ForwardConfig forwardConfig;
070: String input = actionConfig.getInput();
071:
072: if (moduleConfig.getControllerConfig().getInputForward()) {
073: if (LOG.isTraceEnabled()) {
074: LOG.trace("Finding ForwardConfig for '" + input + "'");
075: }
076:
077: forwardConfig = actionConfig.findForwardConfig(input);
078:
079: if (forwardConfig == null) {
080: forwardConfig = moduleConfig.findForwardConfig(input);
081: }
082: } else {
083: if (LOG.isTraceEnabled()) {
084: LOG
085: .trace("Delegating to forward() for '" + input
086: + "'");
087: }
088:
089: forwardConfig = forward(actionCtx, moduleConfig, input);
090: }
091:
092: if (LOG.isDebugEnabled()) {
093: LOG.debug("Forwarding back to " + forwardConfig);
094: }
095:
096: actionCtx.setForwardConfig(forwardConfig);
097:
098: return (false);
099: }
100:
101: // ------------------------------------------------------- Protected Methods
102:
103: /**
104: * <p>Create and return a <code>ForwardConfig</code> representing the
105: * specified module-relative destination.</p>
106: *
107: * @param context The context for this request
108: * @param moduleConfig The <code>ModuleConfig</code> for this request
109: * @param uri The module-relative URI to be the destination
110: * @return ForwardConfig representing destination
111: */
112: protected abstract ForwardConfig forward(ActionContext context,
113: ModuleConfig moduleConfig, String uri);
114: }
|