1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.taglib;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.struts.taglib.TagUtils;
23 import org.itracker.core.resources.ITrackerResources;
24 import org.itracker.web.util.Constants;
25 import org.itracker.web.util.HTMLUtilities;
26
27 import javax.servlet.http.HttpSession;
28 import javax.servlet.jsp.JspException;
29 import javax.servlet.jsp.tagext.BodyTagSupport;
30 import java.net.MalformedURLException;
31 import java.util.Locale;
32
33
34 public final class FormatLinkTag extends BodyTagSupport {
35
36
37
38 private static final long serialVersionUID = 1L;
39
40 private String text = null;
41
42 private String action = null;
43 private String forward = null;
44 private String paramName = null;
45 private String paramValue = null;
46 private String titleKey = null;
47 private String arg0 = null;
48 private String caller = null;
49 private String targetAction = null;
50 private String target = null;
51 private String styleClass = null;
52 private String queryString = null;
53
54 public String getAction() {
55 return action;
56 }
57
58 public void setAction(String value) {
59 action = value;
60 }
61
62 public String getForward() {
63 return forward;
64 }
65
66 public void setForward(String value) {
67 forward = value;
68 }
69
70 public String getParamName() {
71 return paramName;
72 }
73
74 public void setParamName(String value) {
75 paramName = value;
76 }
77
78 public Object getParamValue() {
79 return paramValue;
80 }
81
82 public void setParamValue(Object value) {
83 paramValue = (value != null ? value.toString() : null);
84 }
85
86 public String getQueryString() {
87 return queryString;
88 }
89
90 public void setQueryString(String value) {
91 queryString = value;
92 }
93
94 public String getTitleKey() {
95 return titleKey;
96 }
97
98 public void setTitleKey(String value) {
99 titleKey = value;
100 }
101
102 public Object getArg0() {
103 return arg0;
104 }
105
106 public void setArg0(Object value) {
107 arg0 = (value != null ? value.toString() : null);
108 }
109
110 public String getCaller() {
111 return caller;
112 }
113
114 public void setCaller(String value) {
115 caller = value;
116 }
117
118 public String getTargetAction() {
119 return targetAction;
120 }
121
122 public void setTargetAction(String value) {
123 targetAction = value;
124 }
125
126 public String getTarget() {
127 return target;
128 }
129
130 public void setTarget(String value) {
131 target = value;
132 }
133
134 public String getStyleClass() {
135 return styleClass;
136 }
137
138 public void setStyleClass(String value) {
139 styleClass = value;
140 }
141
142 public int doStartTag() throws JspException {
143 text = null;
144 return EVAL_BODY_BUFFERED;
145 }
146
147 public int doAfterBody() throws JspException {
148 if (bodyContent != null) {
149 String value = bodyContent.getString().trim();
150 if (value.length() > 0) {
151 text = value;
152 }
153 }
154 return SKIP_BODY;
155 }
156
157 public int doEndTag() throws JspException {
158 boolean hasParams = false;
159 Locale locale = null;
160
161 HttpSession session = pageContext.getSession();
162 if (session != null) {
163 locale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
164 }
165
166 StringBuffer buf = new StringBuffer("<a href=\"");
167 try {
168 buf.append(TagUtils.getInstance().computeURL(pageContext, forward, null, null, action, null, null, null, false));
169 } catch (MalformedURLException murle) {
170 buf.append(HTMLUtilities.escapeTags(forward));
171 }
172 if (queryString != null) {
173 buf.append("?" + HTMLUtilities.escapeTags(queryString));
174 hasParams = true;
175 }
176 if (paramName != null && paramValue != null) {
177 buf.append((hasParams ? "&" : "?") + paramName + "=" + paramValue);
178 hasParams = true;
179 }
180 if (caller != null) {
181 buf.append((hasParams ? "&" : "?") + "caller=" + HTMLUtilities.escapeTags(caller));
182 hasParams = true;
183 }
184 if (targetAction != null) {
185 buf.append((hasParams ? "&" : "?") + "action=" + HTMLUtilities.escapeTags(targetAction));
186 hasParams = true;
187 }
188 buf.append("\"");
189 if (target != null) {
190 buf.append(" target=\"" + HTMLUtilities.escapeTags(target) + "\"");
191 }
192 if (titleKey != null) {
193 if (StringUtils.contains(titleKey, ".delete.")) {
194 if (StringUtils.isEmpty(styleClass)) {
195 styleClass = "deleteButton";
196 } else {
197 styleClass += " deleteButton";
198 }
199 }
200 buf.append(" title=\"" + HTMLUtilities.escapeTags(ITrackerResources.getString(titleKey, locale, (arg0 == null ? "" : arg0))) + "\"");
201 }
202 if (styleClass != null) {
203 buf.append(" class=\"" + styleClass + "\"");
204 }
205 buf.append(">");
206 buf.append(HTMLUtilities.escapeTags(text));
207 buf.append("</a>");
208
209 TagUtils.getInstance().write(pageContext, buf.toString());
210 clearState();
211 return (EVAL_PAGE);
212 }
213
214 public void release() {
215 super.release();
216 clearState();
217 }
218
219 private void clearState() {
220 text = null;
221 action = null;
222 forward = null;
223 paramName = null;
224 paramValue = null;
225 titleKey = null;
226 arg0 = null;
227 caller = null;
228 target = null;
229 targetAction = null;
230 styleClass = null;
231 queryString = null;
232 }
233 }