1
2
3
4
5 package gboat2.base.plugin.struts.velocity;
6
7 import gboat2.base.bridge.GboatAppContext;
8 import gboat2.base.bridge.util.json.JsonUtil;
9
10 import java.util.HashMap;
11 import java.util.Map;
12
13 import org.apache.commons.lang3.StringUtils;
14 import org.apache.commons.lang3.time.DateFormatUtils;
15 import org.apache.commons.lang3.time.DateUtils;
16 import org.apache.velocity.VelocityContext;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class GboatVelocityContext extends VelocityContext {
43
44 public static final Map<String, Object> MAP = new HashMap<String, Object>();
45
46 static{
47 MAP.put("GboatAppContext", new GboatAppContext());
48 MAP.put("ObjectMapper", JsonUtil.generateMapper());
49 MAP.put("JsonUtil", new JsonUtil());
50 MAP.put("StringUtils", new StringUtils());
51 MAP.put("DateUtils", new DateUtils());
52 MAP.put("DateFormatUtils", new DateFormatUtils());
53 }
54
55 public Object internalGet(String key) {
56 Object obj = MAP.get(key);
57 return (obj == null) ? super.internalGet(key) : obj;
58 }
59
60 public boolean containsKey(Object key) {
61 return MAP.containsKey(key) || super.containsKey(key);
62 }
63
64 }