1
2
3
4
5 package gboat2.base.view.components;
6
7 import gboat2.base.bridge.util.BundleUtil;
8 import gboat2.base.plugin.struts.dispatcher.GboatDispatcherResult;
9
10 import java.io.Writer;
11
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14
15 import org.apache.struts2.ServletActionContext;
16 import org.apache.struts2.views.annotations.StrutsTag;
17 import org.osgi.framework.Bundle;
18
19 import com.opensymphony.xwork2.ActionContext;
20 import com.opensymphony.xwork2.ActionInvocation;
21 import com.opensymphony.xwork2.Result;
22 import com.opensymphony.xwork2.util.ValueStack;
23 import com.opensymphony.xwork2.util.logging.Logger;
24 import com.opensymphony.xwork2.util.logging.LoggerFactory;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 @StrutsTag(
61 name="include",
62 tldTagClass="gboat2.base.view.jsp.IncludeTag",
63 description="Include a servlet's output (result of servlet or a JSP page)")
64 public class Include extends org.apache.struts2.components.Include {
65
66 private static final Logger LOG = LoggerFactory.getLogger(Include.class);
67
68 protected HttpServletRequest request;
69
70 public Include(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
71 super(stack, req, res);
72 this.request = req;
73 }
74
75 public boolean end(Writer writer, String body) {
76 String page = findString(value, "value", "You must specify the URL to include. Example: /foo.jsp");
77 page = getContextRelativePath(request, page);
78
79 ActionContext actionContext = ServletActionContext.getContext();
80 ActionInvocation invocation = actionContext.getActionInvocation();
81 Bundle bundle = BundleUtil.getBundleForRequestJsp(page, invocation);
82
83
84 if(bundle != null && !page.startsWith("/" + bundle.getSymbolicName() + "/")) {
85 page = "/" + bundle.getSymbolicName() + page;
86 }
87
88 if(page.indexOf("glodon.gbmp.index") > 0){
89 page = "/" + page;
90 }
91 try {
92 Result result = invocation.getResult();
93 if(result instanceof GboatDispatcherResult) {
94
95 page = GboatDispatcherResult.extractBundleJsp(page);
96 }
97 } catch (Exception e) {
98 LOG.error("获取请求 [#0] 的 Result 失败。", e, invocation.toString());
99 }
100 setValue(page);
101 return super.end(writer, body);
102 }
103
104 }