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 * NestedWriteNestingTag.
28 *
29 * Created so developers could have a more elegant way of getting to the
30 * underlying nested property their tag properties are referencing.
31 *
32 * @version $Rev: 376843 $
33 * @since Struts 1.1
34 */
35 public class NestedWriteNestingTag extends BodyTagSupport {
36
37 private boolean filter = false;
38 private String property = null;
39 private String id = null;
40 private String originalProperty = null;
41
42 /***
43 * Getter method for the <i>property</i> property
44 *
45 * @return String value of the property property
46 */
47 public String getProperty() {
48 return this.property;
49 }
50
51 /***
52 * Setter method for the <i>property</i> property
53 *
54 * @param newProperty new value for the property property
55 */
56 public void setProperty(String newProperty) {
57 this.property = newProperty;
58 }
59
60 /***
61 * Getter method for the <i>id</i> property
62 *
63 * @return String value for the id property
64 */
65 public String getId() {
66 return id;
67 }
68
69 /***
70 * Setter method for the <i>id</i> property
71 *
72 * @param id new value for the id property
73 */
74 public void setId(String id) {
75 this.id = id;
76 }
77
78 /***
79 * Getter method for the <i>filter</i> property
80 *
81 * @return String value of the filter property
82 */
83 public boolean getFilter() {
84 return this.filter;
85 }
86
87 /***
88 * Setter method for the <i>filter</i> property
89 *
90 * @param newFilter new value for the filter property
91 */
92 public void setFilter(boolean newFilter) {
93 this.filter = newFilter;
94 }
95
96 /***
97 * Overriding method of the heart of the tag. Gets the relative property
98 * and tells the JSP engine to evaluate its body content.
99 *
100 * @return int JSP continuation directive.
101 */
102 public int doStartTag() throws JspException {
103
104 originalProperty = property;
105
106 HttpServletRequest request =
107 (HttpServletRequest) pageContext.getRequest();
108 String nesting =
109 NestedPropertyHelper.getAdjustedProperty(request, property);
110
111 if (id != null) {
112
113 pageContext.setAttribute(id, nesting);
114 } else {
115
116 if (this.filter) {
117 TagUtils.getInstance().write(pageContext,
118 TagUtils.getInstance().filter(nesting));
119 } else {
120 TagUtils.getInstance().write(pageContext, nesting);
121 }
122 }
123
124
125 return (SKIP_BODY);
126 }
127
128 public int doEndTag() throws JspException {
129
130 int i = super.doEndTag();
131
132
133 property = originalProperty;
134
135
136 return i;
137 }
138
139 /***
140 * JSP method to release all resources held by the tag.
141 */
142 public void release() {
143 super.release();
144 this.filter = false;
145 this.property = null;
146 this.originalProperty = null;
147 }
148 }