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 java.net.MalformedURLException;
22 import java.util.Locale;
23
24 import javax.servlet.http.HttpSession;
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.tagext.TagSupport;
27
28 import org.apache.struts.taglib.TagUtils;
29 import org.itracker.core.resources.ITrackerResources;
30 import org.itracker.model.UserPreferences;
31 import org.itracker.services.util.HTMLUtilities;
32 import org.itracker.web.util.Constants;
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 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 (useTextActions) {
200 buf.append(" title=\""
201 + ITrackerResources.getString(altKey, locale,
202 (arg0 == null ? "" : arg0)) + "\"");
203 buf.append(" class=\"action\">");
204 buf.append(ITrackerResources.getString(textActionKey, locale));
205 } else {
206 buf.append(">");
207 buf.append("<img src=\"");
208 try {
209 buf.append(TagUtils.getInstance().computeURL(pageContext, null,
210 null, src, null, "", null, null, false));
211
212 } catch (MalformedURLException murle) {
213 buf.append(HTMLUtilities.escapeTags(src));
214 }
215 buf.append("\"");
216 if (altKey != null) {
217 buf.append(" alt=\""
218 + ITrackerResources.getString(altKey, locale,
219 (arg0 == null ? "" : arg0)) + "\"");
220 buf.append(" title=\""
221 + ITrackerResources.getString(altKey, locale,
222 (arg0 == null ? "" : arg0)) + "\"");
223 } else {
224 buf.append(" alt=\"\"");
225 }
226 buf.append(" style=\"border:"
227 + (border == null ? "0" : border + "px") + ";\"");
228 buf.append(" />");
229 }
230 buf.append("</a>");
231
232 TagUtils.getInstance().write(pageContext, buf.toString());
233 clearState();
234 return (EVAL_PAGE);
235 }
236
237
238 public void release() {
239 super.release();
240 clearState();
241 }
242
243 private void clearState() {
244 action = null;
245 forward = null;
246 paramName = null;
247 paramValue = null;
248 src = null;
249 altKey = null;
250 arg0 = null;
251 textActionKey = null;
252 border = null;
253 caller = null;
254 target = null;
255 targetAction = null;
256 module = null;
257 }
258 }