1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.taglib.nested;
19
20 import org.apache.struts.taglib.TagUtils;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.jsp.JspException;
24 import javax.servlet.jsp.tagext.BodyTagSupport;
25
26 /***
27 * NestedPropertyTag.
28 *
29 * The one of only two additions in this nested suite of tags. This is so that
30 * you can specify extra levels of nesting in one elegant tag rather than
31 * having to propagate and manage an extra dot notated property in nested
32 * child tags.
33 *
34 * It's simply recognised by the helper class and it's property is added to
35 * the nesting list.
36 *
37 * @version $Rev: 376843 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
38 * $
39 * @since Struts 1.1
40 */
41 public class NestedPropertyTag extends BodyTagSupport
42 implements NestedNameSupport {
43
44 private String property = null;
45 private String originalNest = null;
46 private String originalName = null;
47 private String originalProperty = null;
48
49 public String getName() {
50 return null;
51 }
52
53 public void setName(String newNamed) {
54 }
55
56 /***
57 * Getter method for the <i>property</i> property
58 *
59 * @return String value of the property property
60 */
61 public String getProperty() {
62 return this.property;
63 }
64
65 /***
66 * Setter method for the <i>property</i> property Also, only setting the
67 * original property value to those values not set by the nested logic.
68 *
69 * @param newProperty new value for the property property
70 */
71 public void setProperty(String newProperty) {
72 property = newProperty;
73 }
74
75 /***
76 * Overriding method of the heart of the tag. Gets the relative property
77 * and tells the JSP engine to evaluate its body content.
78 *
79 * @return int JSP continuation directive.
80 */
81 public int doStartTag() throws JspException {
82 originalProperty = property;
83
84 HttpServletRequest request =
85 (HttpServletRequest) pageContext.getRequest();
86
87 originalNest = NestedPropertyHelper.getCurrentProperty(request);
88 originalName = NestedPropertyHelper.getCurrentName(request, this);
89
90 String nested =
91 NestedPropertyHelper.getAdjustedProperty(request, originalProperty);
92
93 NestedPropertyHelper.setProperty(request, nested);
94 NestedPropertyHelper.setName(request, originalName);
95
96
97 return (EVAL_BODY_TAG);
98 }
99
100 /***
101 * Render the resulting content evaluation.
102 *
103 * @return int JSP continuation directive.
104 */
105 public int doAfterBody() throws JspException {
106
107 if (bodyContent != null) {
108 TagUtils.getInstance().writePrevious(pageContext,
109 bodyContent.getString());
110 bodyContent.clearBody();
111 }
112
113 return (SKIP_BODY);
114 }
115
116 /***
117 * Evaluate the rest of the page
118 *
119 * @return int JSP continuation directive.
120 */
121 public int doEndTag() throws JspException {
122
123 HttpServletRequest request =
124 (HttpServletRequest) pageContext.getRequest();
125
126 if ((originalNest == null) && (originalName == null)) {
127 NestedPropertyHelper.deleteReference(request);
128 } else {
129 NestedPropertyHelper.setName(request, originalName);
130 NestedPropertyHelper.setProperty(request, originalNest);
131 }
132
133 property = originalProperty;
134
135 return (EVAL_PAGE);
136 }
137
138 /***
139 * JSP method to release all resources held by the tag.
140 */
141 public void release() {
142 super.release();
143 this.property = null;
144 this.originalNest = null;
145 this.originalName = null;
146 this.originalProperty = null;
147 }
148 }