1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.chain.commands;
19
20 import java.util.Map;
21 import org.apache.struts.Globals;
22 import org.apache.struts.chain.contexts.ActionContext;
23 import org.apache.struts.action.ActionMessages;
24
25 /***
26 * <p>Remove cached messages stored in the session.</p>
27 *
28 * @version $Id: RemoveCachedMessages.java 421117 2006-07-12 04:35:47Z wsmoak $
29 * @since Struts 1.3.5
30 */
31 public class RemoveCachedMessages extends ActionCommandBase {
32
33 /***
34 * <p>Removes any <code>ActionMessages</code> object stored in the session
35 * under <code>Globals.MESSAGE_KEY</code> and <code>Globals.ERROR_KEY</code>
36 * if the messages' <code>isAccessed</code> method returns true. This
37 * allows messages to be stored in the session, displayed one time, and be
38 * released here.</p>
39 *
40 * @param actionCtx The <code>Context</code> for the current request
41 * @return <code>false</code> so that processing continues
42 * @throws Exception on any error
43 */
44 public boolean execute(ActionContext actionCtx)
45 throws Exception {
46
47
48 Map session = actionCtx.getSessionScope();
49
50
51 removeAccessedMessages(session, Globals.MESSAGE_KEY);
52
53
54 removeAccessedMessages(session, Globals.ERROR_KEY);
55
56 return false;
57 }
58
59 /***
60 * <p>Removes any <code>ActionMessages</code> object from the specified
61 * scope stored under the specified key if the messages'
62 * <code>isAccessed</code> method returns true.
63 *
64 * @param scope The scope to check for messages in.
65 * @param key The key the messages are stored under.
66 */
67 private void removeAccessedMessages(Map scope, String key) {
68 ActionMessages messages = (ActionMessages)scope.get(key);
69 if (messages != null && messages.isAccessed()) {
70 scope.remove(key);
71 }
72 }
73 }