1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.struts.flow.core;
17
18 import org.mozilla.javascript.Undefined;
19 import org.mozilla.javascript.Wrapper;
20
21 import java.util.Map;
22
23 /***
24 * Provides the interface between the flow controller layer and the
25 * view layer. A view can obtain the context object sent by a flow
26 * script and the current web continuation, if any.
27 */
28 public class FlowHelper {
29
30
31
32
33
34
35
36
37
38
39 /***
40 * Request attribute name used to store flow context.
41 */
42 private static final String CONTEXT_OBJECT = "cocoon.flow.context";
43
44 /***
45 * Request attribute name used to store flow continuation.
46 */
47 private static final String CONTINUATION_OBJECT = "cocoon.flow.continuation";
48
49 /***
50 * Get the flow context object associated with the current request
51 *
52 * @param objectModel The Cocoon Environment's object model
53 * @return The context object
54 */
55 public final static Object getContextObject(Map objectModel) {
56 return objectModel.get(CONTEXT_OBJECT);
57 }
58
59 /***
60 * Get the web continuation associated with the current request
61 *
62 * @param objectModel The Cocoon Environment's object model
63 * @return The web continuation
64 */
65 public final static WebContinuation getWebContinuation(Map objectModel) {
66 return (WebContinuation)objectModel.get(CONTINUATION_OBJECT);
67 }
68
69 /***
70 * Set the web continuation associated with the current request
71 *
72 * @param objectModel The Cocoon Environment's object model
73 * @param kont The web continuation
74 */
75 public final static void setWebContinuation(Map objectModel,
76 WebContinuation kont) {
77 objectModel.put(CONTINUATION_OBJECT, kont);
78 }
79
80 /***
81 * Set the flow context object associated with the current request
82 *
83 * @param objectModel The Cocoon Environment's object model
84 * @param obj The context object
85 */
86 public final static void setContextObject(Map objectModel, Object obj) {
87 objectModel.put(CONTEXT_OBJECT, obj);
88 }
89
90 /***
91 * Unwrap a Rhino object (getting the raw java object) and convert undefined to null
92 */
93 public static Object unwrap(Object obj) {
94 if (obj instanceof Wrapper) {
95 obj = ((Wrapper)obj).unwrap();
96 } else if (obj == Undefined.instance) {
97 obj = null;
98 }
99 return obj;
100 }
101 }