1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.taglib.nested.html;
19
20 import org.apache.struts.taglib.html.LinkTag;
21 import org.apache.struts.taglib.nested.NestedNameSupport;
22 import org.apache.struts.taglib.nested.NestedPropertyHelper;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.jsp.JspException;
26
27 /***
28 * NestedLinkTag.
29 *
30 * @version $Rev: 376843 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
31 * $
32 * @since Struts 1.1
33 */
34 public class NestedLinkTag extends LinkTag implements NestedNameSupport {
35
36 private String origName = null;
37 private String origProperty = null;
38 private String origParamProperty = null;
39
40 /***
41 * Overriding method of the heart of the matter. Gets the relative
42 * property and leaves the rest up to the original tag implementation.
43 * Sweet.
44 *
45 * @return int JSP continuation directive. This is in the hands of the
46 * super class.
47 */
48 public int doStartTag() throws JspException {
49 origName = super.getName();
50 origProperty = super.getProperty();
51 origParamProperty = super.getParamProperty();
52
53
54 boolean doProperty =
55 ((origProperty != null) && (origProperty.length() > 0));
56 boolean doParam =
57 ((origParamProperty != null) && (origParamProperty.length() > 0));
58
59
60 HttpServletRequest request =
61 (HttpServletRequest) pageContext.getRequest();
62
63 boolean hasName =
64 ((getName() != null) && (getName().trim().length() > 0));
65 String currentName;
66
67 if (hasName) {
68 currentName = getName();
69 } else {
70 currentName = NestedPropertyHelper.getCurrentName(request, this);
71 }
72
73
74 super.setName(currentName);
75
76
77 if (doProperty && !hasName) {
78 super.setProperty(NestedPropertyHelper.getAdjustedProperty(
79 request, origProperty));
80 }
81
82
83 if (doParam) {
84 super.setName(null);
85 super.setParamName(currentName);
86 super.setParamProperty(NestedPropertyHelper.getAdjustedProperty(
87 request, origParamProperty));
88 }
89
90
91 return super.doStartTag();
92 }
93
94 /***
95 * Complete the processing of the tag. The nested tags here will restore
96 * all the original value for the tag itself and the nesting context.
97 *
98 * @return int to describe the next step for the JSP processor
99 * @throws JspException for the bad things JSP's do
100 */
101 public int doEndTag() throws JspException {
102
103 int i = super.doEndTag();
104
105
106 setName(origName);
107 setProperty(origProperty);
108 setParamProperty(origParamProperty);
109
110
111 return i;
112 }
113
114 /***
115 * Release the tag's resources and reset the values.
116 */
117 public void release() {
118 super.release();
119
120
121 origName = null;
122 origProperty = null;
123 origParamProperty = null;
124 }
125 }