KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > chain > AbstractRequestNoCache


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>Check to see if the controller is configured to prevent caching,
28  * and if so, request no cache flags to be set.</p>
29  *
30  * @author Don Brown
31  * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
32  */

33
34 public abstract class AbstractRequestNoCache implements Command {
35
36
37     // ------------------------------------------------------ Instance Variables
38

39
40     private String JavaDoc moduleConfigKey = Constants.MODULE_CONFIG_KEY;
41
42
43     // -------------------------------------------------------------- Properties
44

45
46     /**
47      * <p>Return the context attribute key under which the
48      * <code>ModuleConfig</code> for the currently selected application
49      * module is stored.</p>
50      */

51     public String JavaDoc getModuleConfigKey() {
52
53         return (this.moduleConfigKey);
54
55     }
56
57
58     /**
59      * <p>Set the context attribute key under which the
60      * <code>ModuleConfig</code> for the currently selected application
61      * module is stored.</p>
62      *
63      * @param moduleConfigKey The new context attribute key
64      */

65     public void setModuleConfigKey(String JavaDoc moduleConfigKey) {
66
67         this.moduleConfigKey = moduleConfigKey;
68
69     }
70
71
72     // ---------------------------------------------------------- Public Methods
73

74
75     /**
76      * <p>Check to see if the controller is configured to prevent caching,
77      * and if so, request no cache flags to be set.</p>
78      *
79      * @param context The <code>Context</code> for the current request
80      *
81      * @return <code>false</code> so that processing continues
82      */

83     public boolean execute(Context context) throws Exception JavaDoc {
84
85         // Retrieve the ModuleConfig instance
86
WebContext wcontext = (WebContext) context;
87         ModuleConfig moduleConfig = (ModuleConfig)
88             wcontext.get(getModuleConfigKey());
89             
90         // If the module is configured for no caching, request no caching
91
if (moduleConfig.getControllerConfig().getNocache()) {
92             requestNoCache(context);
93         }
94         return (false);
95
96     }
97
98
99     // ------------------------------------------------------- Protected Methods
100

101
102     /**
103      * <p>Request no cache flags are set.</p>
104      *
105      * @param context The <code>Context</code> for this request
106      */

107     protected abstract void requestNoCache(Context context);
108
109
110 }
111
Popular Tags