1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jsp;
23
24 import java.io.PrintWriter;
25
26 import javax.servlet.jsp.tagext.BodyTagSupport;
27
28 import org.apache.struts2.components.Component;
29 import org.apache.struts2.util.FastByteArrayOutputStream;
30
31 import com.opensymphony.xwork2.util.TextParseUtil;
32 import com.opensymphony.xwork2.util.ValueStack;
33
34
35 /***
36 * Contains common functonalities for Struts JSP Tags.
37 *
38 */
39 public class StrutsBodyTagSupport extends BodyTagSupport {
40
41 private static final long serialVersionUID = -1201668454354226175L;
42
43 protected ValueStack getStack() {
44 return TagUtils.getStack(pageContext);
45 }
46
47 protected String findString(String expr) {
48 return (String) findValue(expr, String.class);
49 }
50
51 protected Object findValue(String expr) {
52 expr = Component.stripExpressionIfAltSyntax(getStack(), expr);
53
54 return getStack().findValue(expr);
55 }
56
57 protected Object findValue(String expr, Class toType) {
58 if (Component.altSyntax(getStack()) && toType == String.class) {
59 return TextParseUtil.translateVariables('%', expr, getStack());
60
61 } else {
62 expr = Component.stripExpressionIfAltSyntax(getStack(), expr);
63
64 return getStack().findValue(expr, toType);
65 }
66 }
67
68 protected String toString(Throwable t) {
69 FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
70 PrintWriter wrt = new PrintWriter(bout);
71 t.printStackTrace(wrt);
72 wrt.close();
73
74 return bout.toString();
75 }
76
77 protected String getBody() {
78 if (bodyContent == null) {
79 return "";
80 } else {
81 return bodyContent.getString().trim();
82 }
83 }
84 }