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.model.UserPreferences;
25 import org.itracker.web.util.Constants;
26 import org.itracker.web.util.HTMLUtilities;
27
28 import javax.servlet.http.HttpSession;
29 import javax.servlet.jsp.JspException;
30 import javax.servlet.jsp.tagext.TagSupport;
31 import java.net.MalformedURLException;
32 import java.util.Locale;
33
34 public final class FormatImageActionTag extends TagSupport {
35
36
37
38 private static final long serialVersionUID = 1L;
39
40 private String action = null;
41 private String forward = null;
42 private String module = null;
43 private String paramName = null;
44 private String paramValue = null;
45 private String src = null;
46 private String altKey = null;
47 private String arg0 = null;
48 private String textActionKey = null;
49 private String border = null;
50 private String caller = null;
51 private String targetAction = null;
52 private String target = 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 getModule() {
71 return module;
72 }
73
74 public void setModule(String module) {
75 this.module = module;
76 }
77
78 public String getParamName() {
79 return paramName;
80 }
81
82 public void setParamName(String value) {
83 paramName = value;
84 }
85
86 public Object getParamValue() {
87 return paramValue;
88 }
89
90 public void setParamValue(Object value) {
91 paramValue = (value != null ? value.toString() : null);
92 }
93
94 public String getSrc() {
95 return src;
96 }
97
98 public void setSrc(String value) {
99 src = value;
100 }
101
102 public String getAltKey() {
103 return altKey;
104 }
105
106 public void setAltKey(String value) {
107 altKey = value;
108 }
109
110 public Object getArg0() {
111 return arg0;
112 }
113
114 public void setArg0(Object value) {
115 arg0 = (value != null ? value.toString() : null);
116 }
117
118 public String getTextActionKey() {
119 return textActionKey;
120 }
121
122 public void setTextActionKey(String value) {
123 textActionKey = value;
124 }
125
126 public String getBorder() {
127 return border;
128 }
129
130 public void setBorder(String value) {
131 border = value;
132 }
133
134 public String getCaller() {
135 return caller;
136 }
137
138 public void setCaller(String value) {
139 caller = value;
140 }
141
142 public String getTargetAction() {
143 return targetAction;
144 }
145
146 public void setTargetAction(String value) {
147 targetAction = value;
148 }
149
150 public String getTarget() {
151 return target;
152 }
153
154 public void setTarget(String value) {
155 target = value;
156 }
157
158 public int doStartTag() throws JspException {
159 return SKIP_BODY;
160 }
161
162 public int doEndTag() throws JspException {
163 boolean hasParams = false;
164 boolean useTextActions = false;
165 Locale locale = null;
166
167 HttpSession session = pageContext.getSession();
168 if (session != null) {
169 locale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
170 UserPreferencesitracker/model/UserPreferences.html#UserPreferences">UserPreferences currUserPrefs = (UserPreferences) session
171 .getAttribute(Constants.PREFERENCES_KEY);
172 useTextActions = (currUserPrefs != null ? currUserPrefs
173 .getUseTextActions() : false);
174 }
175
176 StringBuffer buf = new StringBuffer("<a href=\"");
177 try {
178 buf.append(TagUtils.getInstance().computeURL(pageContext, forward,
179 null, null, action, module, null, null, false));
180 } catch (MalformedURLException murle) {
181 buf.append(HTMLUtilities.escapeTags(forward));
182 }
183 if (paramName != null && paramValue != null) {
184 buf.append("?" + paramName + "=" + paramValue);
185 hasParams = true;
186 }
187 if (caller != null) {
188 buf.append((hasParams ? "&" : "?") + "caller=" + HTMLUtilities.escapeTags(caller));
189 hasParams = true;
190 }
191 if (targetAction != null) {
192 buf.append((hasParams ? "&" : "?") + "action=" + HTMLUtilities.escapeTags(targetAction));
193 hasParams = true;
194 }
195 buf.append("\"");
196 if (target != null) {
197 buf.append(" target=\"" + target + "\"");
198 }
199 if (null != altKey) {
200 buf.append(" title=\""
201 + HTMLUtilities.escapeTags(
202 ITrackerResources.getString(altKey, locale,
203 (arg0 == null ? "" : arg0))) + "\"");
204 }
205 String styleClass = null;
206 if (StringUtils.contains(altKey, ".delete.")) {
207 styleClass = "deleteButton";
208 }
209
210 if (useTextActions) {
211 if (StringUtils.contains(altKey, ".delete.")) {
212 if (StringUtils.isEmpty(styleClass)) {
213 styleClass = "action";
214 } else {
215 styleClass += " action";
216 }
217 }
218
219 if (!StringUtils.isEmpty(styleClass)) {
220 buf.append(" class=\"").append( styleClass ).append("\"");
221 }
222 buf.append(">");
223 buf.append(HTMLUtilities.escapeTags( ITrackerResources.getString(textActionKey, locale) ));
224 } else {
225
226 if (!StringUtils.isEmpty(styleClass)) {
227 buf.append(" class=\"").append( styleClass ).append("\"");
228 }
229 buf.append(">");
230 buf.append("<img src=\"");
231 try {
232 buf.append(TagUtils.getInstance().computeURL(pageContext, null,
233 null, src, null, "", null, null, false));
234
235 } catch (MalformedURLException murle) {
236 buf.append(HTMLUtilities.escapeTags(src));
237 }
238 buf.append("\"");
239 if (altKey != null) {
240 buf.append(" alt=\""
241 + HTMLUtilities.escapeTags( ITrackerResources.getString(altKey, locale,
242 (arg0 == null ? "" : arg0)) ) + "\"");
243 buf.append(" title=\""
244 + HTMLUtilities.escapeTags( ITrackerResources.getString(altKey, locale,
245 (arg0 == null ? "" : arg0)) ) + "\"");
246 } else {
247 buf.append(" alt=\"\"");
248 }
249 buf.append(" style=\"border:"
250 + (border == null ? "0" : border + "px") + ";\"");
251 buf.append(" />");
252 }
253 buf.append("</a>");
254
255 TagUtils.getInstance().write(pageContext, buf.toString());
256 clearState();
257 return (EVAL_PAGE);
258 }
259
260
261 public void release() {
262 super.release();
263 clearState();
264 }
265
266 private void clearState() {
267 action = null;
268 forward = null;
269 paramName = null;
270 paramValue = null;
271 src = null;
272 altKey = null;
273 arg0 = null;
274 textActionKey = null;
275 border = null;
276 caller = null;
277 target = null;
278 targetAction = null;
279 module = null;
280 }
281 }