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