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