~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/AbstractPerformInclude.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.chain.web.WebContext;
 
23
import org.apache.struts.config.ModuleConfig;
 
24
 
 
25
 
 
26
/**
 
27
 * <p>Perform forwarding or redirection based on the specified
 
28
 * <code>String</code> (if any).</p>
 
29
 *
 
30
 * @author Don Brown
 
31
 * @version $Revision: 1.4 $ $Date: 2004/04/29 03:08:44 $
 
32
 */
 
33
 
 
34
public abstract class AbstractPerformInclude implements Command {
 
35
 
 
36
 
 
37
    // ------------------------------------------------------ Instance Variables
 
38
 
 
39
 
 
40
    private String includeKey = Constants.INCLUDE_KEY;
 
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
     * include uri for the currently selected application
 
50
     * action is stored.</p>
 
51
     */
 
52
    public String getIncludeKey() {
 
53
 
 
54
        return (this.includeKey);
 
55
 
 
56
    }
 
57
 
 
58
 
 
59
    /**
 
60
     * <p>Set the context attribute key under which the
 
61
     * include uri for the currently selected application
 
62
     * action is stored.</p>
 
63
     *
 
64
     * @param includeKey The new context attribute key
 
65
     */
 
66
    public void setIncludeKey(String includeKey) {
 
67
 
 
68
        this.includeKey = includeKey;
 
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 is 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 is 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 an include based on the specified
 
103
     * include uri (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
        // Retrieve module config instance
 
112
        WebContext wcontext = (WebContext) context;
 
113
        ModuleConfig moduleConfig = (ModuleConfig)
 
114
            wcontext.get(getModuleConfigKey());
 
115
        
 
116
        // Is there an include to be performed?
 
117
        String include = (String)
 
118
            context.get(getIncludeKey());
 
119
        if (include == null) {
 
120
            return (false);
 
121
        }
 
122
        
 
123
        // Determine the currect uri
 
124
        String uri = moduleConfig.getPrefix() + include;
 
125
 
 
126
        // Perform the appropriate processing on this include uri
 
127
        perform(context, uri);
 
128
        return (true);
 
129
 
 
130
    }
 
131
 
 
132
 
 
133
    // ------------------------------------------------------- Protected Methods
 
134
 
 
135
 
 
136
    /**
 
137
     * <p>Perform the appropriate processing on the specified
 
138
     * include uri.</p>
 
139
     *
 
140
     * @param context The context for this request
 
141
     * @param include The forward to be performed
 
142
     */
 
143
    protected abstract void perform(Context context,
 
144
                                    String include)
 
145
        throws Exception;
 
146
 
 
147
 
 
148
}