01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.views.util;
06:
07: import com.opensymphony.xwork.util.OgnlValueStack;
08: import com.opensymphony.xwork.ActionInvocation;
09: import com.opensymphony.xwork.ActionContext;
10: import com.opensymphony.webwork.views.jsp.ui.OgnlTool;
11: import com.opensymphony.webwork.config.Configuration;
12: import com.opensymphony.webwork.util.WebWorkUtil;
13: import com.opensymphony.webwork.WebWorkConstants;
14:
15: import javax.servlet.http.HttpServletRequest;
16: import javax.servlet.http.HttpServletResponse;
17: import java.util.HashMap;
18: import java.util.Map;
19:
20: /**
21: * Value Stack's Context related Utilities.
22: *
23: * @author plightbo
24: * @author tm_jee
25: * @version $Date: 2006-01-25 18:21:01 +0100 (Wed, 25 Jan 2006) $ $Id: ContextUtil.java 2029 2006-01-25 17:21:01Z rainerh $
26: */
27: public class ContextUtil {
28: public static final String REQUEST = "req";
29: public static final String REQUEST2 = "request";
30: public static final String RESPONSE = "res";
31: public static final String RESPONSE2 = "response";
32: public static final String SESSION = "session";
33: public static final String BASE = "base";
34: public static final String STACK = "stack";
35: public static final String OGNL = "ognl";
36: public static final String WEBWORK = "webwork";
37: public static final String ACTION = "action";
38:
39: public static Map getStandardContext(OgnlValueStack stack,
40: HttpServletRequest req, HttpServletResponse res) {
41: HashMap map = new HashMap();
42: map.put(REQUEST, req);
43: map.put(REQUEST2, req);
44: map.put(RESPONSE, res);
45: map.put(RESPONSE2, res);
46: map.put(SESSION, req.getSession(false));
47: map.put(BASE, req.getContextPath());
48: map.put(STACK, stack);
49: map.put(OGNL, OgnlTool.getInstance());
50: map.put(WEBWORK, new WebWorkUtil(stack, req, res));
51:
52: ActionInvocation invocation = (ActionInvocation) stack
53: .getContext().get(ActionContext.ACTION_INVOCATION);
54: if (invocation != null) {
55: map.put(ACTION, invocation.getAction());
56: }
57: return map;
58: }
59:
60: /**
61: * Return true if either Configuration's altSyntax is on or the stack context's useAltSyntax is on
62: * @param context stack's context
63: * @return boolean
64: */
65: public static boolean isUseAltSyntax(Map context) {
66: // We didn't make altSyntax static cause, if so, webwork.configuration.xml.reload will not work
67: // plus the Configuration implementation should cache the properties, which WW's
68: // configuration implementation does
69: boolean altSyntax = "true".equals(Configuration
70: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX));
71: return altSyntax
72: || ((context.containsKey("useAltSyntax")
73: && context.get("useAltSyntax") != null && "true"
74: .equals(context.get("useAltSyntax").toString())));
75: }
76:
77: /**
78: * Returns a String for overriding the default templateSuffix if templateSuffix is on the stack
79: * @param context stack's context
80: * @return String
81: */
82: public static String getTemplateSuffix(Map context) {
83: return context.containsKey("templateSuffix") ? (String) context
84: .get("templateSuffix") : null;
85: }
86: }
|