~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/struts-chain/src/java/org/apache/struts/chain/AbstractSelectInput.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.commons.logging.Log;
 
23
import org.apache.commons.logging.LogFactory;
 
24
import org.apache.struts.chain.Constants;
 
25
import org.apache.struts.config.ActionConfig;
 
26
import org.apache.struts.config.ForwardConfig;
 
27
import org.apache.struts.config.ModuleConfig;
 
28
 
 
29
 
 
30
/**
 
31
 * <p>Select and cache a <code>ForwardConfig</code> that returns us to the
 
32
 * input page for the current action, if any.</p>
 
33
 *
 
34
 * @author Craig R. McClanahan
 
35
 * @version $Revision: 1.4 $ $Date: 2004/03/08 02:50:53 $
 
36
 */
 
37
 
 
38
public abstract class AbstractSelectInput implements Command {
 
39
 
 
40
 
 
41
    // ------------------------------------------------------ Instance Variables
 
42
 
 
43
 
 
44
    private String actionConfigKey = Constants.ACTION_CONFIG_KEY;
 
45
    private String forwardConfigKey = Constants.FORWARD_CONFIG_KEY;
 
46
    private String validKey = Constants.VALID_KEY;
 
47
 
 
48
    private static final Log log = LogFactory.getLog(AbstractSelectInput.class);
 
49
 
 
50
 
 
51
    // -------------------------------------------------------------- Properties
 
52
 
 
53
 
 
54
    /**
 
55
     * <p>Return the context attribute key under which the
 
56
     * <code>ActionConfig</code> for the currently selected application
 
57
     * action is stored.</p>
 
58
     */
 
59
    public String getActionConfigKey() {
 
60
 
 
61
        return (this.actionConfigKey);
 
62
 
 
63
    }
 
64
 
 
65
 
 
66
    /**
 
67
     * <p>Set the context attribute key under which the
 
68
     * <code>ActionConfig</code> for the currently selected application
 
69
     * action is stored.</p>
 
70
     *
 
71
     * @param actionConfigKey The new context attribute key
 
72
     */
 
73
    public void setActionConfigKey(String actionConfigKey) {
 
74
 
 
75
        this.actionConfigKey = actionConfigKey;
 
76
 
 
77
    }
 
78
 
 
79
 
 
80
    /**
 
81
     * <p>Return the context attribute key under which the
 
82
     * <code>ForwardConfig</code> for the currently selected application
 
83
     * action is stored.</p>
 
84
     */
 
85
    public String getForwardConfigKey() {
 
86
 
 
87
        return (this.forwardConfigKey);
 
88
 
 
89
    }
 
90
 
 
91
 
 
92
    /**
 
93
     * <p>Set the context attribute key under which the
 
94
     * <code>ForwardConfig</code> for the currently selected application
 
95
     * action is stored.</p>
 
96
     *
 
97
     * @param forwardConfigKey The new context attribute key
 
98
     */
 
99
    public void setForwardConfigKey(String forwardConfigKey) {
 
100
 
 
101
        this.forwardConfigKey = forwardConfigKey;
 
102
 
 
103
    }
 
104
 
 
105
 
 
106
    /**
 
107
     * <p>Return the context attribute key under which the
 
108
     * validity flag for this request is stored.</p>
 
109
     */
 
110
    public String getValidKey() {
 
111
 
 
112
        return (this.validKey);
 
113
 
 
114
    }
 
115
 
 
116
 
 
117
    /**
 
118
     * <p>Set the context attribute key under which the
 
119
     * validity flag for this request is stored.</p>
 
120
     *
 
121
     * @param validKey The new context attribute key
 
122
     */
 
123
    public void setValidKey(String validKey) {
 
124
 
 
125
        this.validKey = validKey;
 
126
 
 
127
    }
 
128
 
 
129
 
 
130
    // ---------------------------------------------------------- Public Methods
 
131
 
 
132
 
 
133
    /**
 
134
     * <p>Select and cache a <code>ForwardConfig</code> for the input page
 
135
     * for the current request.</p>
 
136
     *
 
137
     * @param context The <code>Context</code> for the current request
 
138
     *
 
139
     * @return <code>false</code> so that processing continues
 
140
     */
 
141
    public boolean execute(Context context) throws Exception {
 
142
 
 
143
        // Skip processing if the current request is valid
 
144
        Boolean valid = (Boolean) context.get(getValidKey());
 
145
        if ((valid != null) && valid.booleanValue()) {
 
146
            return (false);
 
147
        }
 
148
 
 
149
        // Acquire configuration objects that we need
 
150
        ActionConfig actionConfig = (ActionConfig)
 
151
            context.get(getActionConfigKey());
 
152
        ModuleConfig moduleConfig = actionConfig.getModuleConfig();
 
153
 
 
154
        // Cache an ForwardConfig back to our input page
 
155
        ForwardConfig forwardConfig = null;
 
156
        String input = actionConfig.getInput();
 
157
        if (moduleConfig.getControllerConfig().getInputForward()) {
 
158
            if (log.isTraceEnabled()) {
 
159
                log.trace("Finding ForwardConfig for '" + input + "'");
 
160
            }
 
161
            forwardConfig = actionConfig.findForwardConfig(input);
 
162
            if (forwardConfig == null) {
 
163
                forwardConfig = moduleConfig.findForwardConfig(input);
 
164
            }
 
165
        } else {
 
166
            if (log.isTraceEnabled()) {
 
167
                log.trace("Delegating to forward() for '" + input + "'");
 
168
            }
 
169
            forwardConfig = forward(context, moduleConfig, input);
 
170
        }
 
171
        if (log.isDebugEnabled()) {
 
172
            log.debug("Forwarding back to " + forwardConfig);
 
173
        }
 
174
        context.put(getForwardConfigKey(), forwardConfig);
 
175
        return (false);
 
176
 
 
177
    }
 
178
 
 
179
 
 
180
    // ------------------------------------------------------- Protected Methods
 
181
 
 
182
 
 
183
    /**
 
184
     * <p>Create and return a <code>ForwardConfig</code> representing the
 
185
     * specified module-relative destination.</p>
 
186
     *
 
187
     * @param context The context for this request
 
188
     * @param moduleConfig The <code>ModuleConfig</code> for this request
 
189
     * @param uri The module-relative URI to be the destination
 
190
     */
 
191
    protected abstract ForwardConfig forward(Context context,
 
192
                                             ModuleConfig moduleConfig,
 
193
                                             String uri);
 
194
 
 
195
 
 
196
}
 
197
 
 
198
 
 
199