KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > taglib > FormatImageActionTag


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.taglib;
20
21 import java.net.*;
22 import java.util.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
27
28 import org.apache.struts.Globals;
29 import org.apache.struts.action.*;
30 import org.apache.struts.util.*;
31
32 import cowsultants.itracker.ejb.client.resources.*;
33 import cowsultants.itracker.web.util.*;
34
35 public final class FormatImageActionTag extends TagSupport JavaDoc {
36     private String JavaDoc text = null;
37
38     private String JavaDoc action = null;
39     private String JavaDoc forward = null;
40     private String JavaDoc paramName = null;
41     private String JavaDoc paramValue = null;
42     private String JavaDoc src = null;
43     private String JavaDoc altKey = null;
44     private String JavaDoc arg0 = null;
45     private String JavaDoc border = null;
46     private String JavaDoc caller = null;
47     private String JavaDoc targetAction = null;
48     private String JavaDoc target = null;
49
50     public String JavaDoc getAction() {
51         return action;
52     }
53
54     public void setAction(String JavaDoc value) {
55           action = value;
56     }
57
58     public String JavaDoc getForward() {
59         return forward;
60     }
61
62     public void setForward(String JavaDoc value) {
63           forward = value;
64     }
65
66     public String JavaDoc getParamName() {
67         return paramName;
68     }
69
70     public void setParamName(String JavaDoc value) {
71           paramName = value;
72     }
73
74     public Object JavaDoc getParamValue() {
75         return paramValue;
76     }
77
78     public void setParamValue(Object JavaDoc value) {
79           paramValue = (value != null ? value.toString() : null);
80     }
81
82     public String JavaDoc getSrc() {
83         return src;
84     }
85
86     public void setSrc(String JavaDoc value) {
87           src = value;
88     }
89
90     public String JavaDoc getAltKey() {
91         return altKey;
92     }
93
94     public void setAltKey(String JavaDoc value) {
95           altKey = value;
96     }
97
98     public Object JavaDoc getArg0() {
99         return arg0;
100     }
101
102     public void setArg0(Object JavaDoc value) {
103           arg0 = (value != null ? value.toString() : null);
104     }
105
106     public String JavaDoc getBorder() {
107         return border;
108     }
109
110     public void setBorder(String JavaDoc value) {
111           border = value;
112     }
113
114     public String JavaDoc getCaller() {
115         return caller;
116     }
117
118     public void setCaller(String JavaDoc value) {
119           caller = value;
120     }
121
122     public String JavaDoc getTargetAction() {
123         return targetAction;
124     }
125
126     public void setTargetAction(String JavaDoc value) {
127           targetAction = value;
128     }
129
130     public String JavaDoc getTarget() {
131         return target;
132     }
133
134     public void setTarget(String JavaDoc value) {
135           target = value;
136     }
137
138     public int doStartTag() throws JspException JavaDoc {
139         return SKIP_BODY;
140     }
141
142     public int doEndTag() throws JspException JavaDoc {
143         boolean hasParams = false;
144         Locale currLocale = null;
145
146         HttpSession session = pageContext.getSession();
147         if(session != null) {
148             currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
149         }
150
151         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("<a HREF=\"");
152         try {
153             buf.append(RequestUtils.computeURL(pageContext, forward, null, null, action, null, null, false));
154         } catch(MalformedURLException murle) {
155             buf.append(forward);
156         }
157         if(paramName != null && paramValue != null) {
158             buf.append("?" + paramName + "=" + paramValue);
159             hasParams = true;
160         }
161         if(caller != null) {
162             buf.append((hasParams ? "&" : "?") + "caller=" + caller);
163             hasParams = true;
164         }
165         if(targetAction != null) {
166             buf.append((hasParams ? "&" : "?") + "action=" + targetAction);
167             hasParams = true;
168         }
169         buf.append("\"");
170         if(target != null) {
171             buf.append(" target=\"" + target + "\"");
172         }
173         buf.append(">");
174         buf.append("<img SRC=\"");
175         try {
176             buf.append(RequestUtils.computeURL(pageContext, null, null, src, null, null, null, false));
177         } catch(MalformedURLException murle) {
178             buf.append(src);
179         }
180         buf.append("\"");
181         if(altKey != null) {
182             buf.append(" alt=\"" + ITrackerResources.getString(altKey, currLocale, (arg0 == null ? "" : arg0)) + "\"");
183             buf.append(" title=\"" + ITrackerResources.getString(altKey, currLocale, (arg0 == null ? "" : arg0)) + "\"");
184         }
185         buf.append(" border=\"" + (border == null ? "0" : border) + "\"");
186         buf.append("></a>");
187         ResponseUtils.write(pageContext, buf.toString());
188         clearState();
189         return (EVAL_PAGE);
190     }
191
192     public void release() {
193         super.release();
194         clearState();
195     }
196
197     private void clearState() {
198         action = null;
199         forward = null;
200         paramName = null;
201         paramValue = null;
202         src = null;
203         altKey = null;
204         arg0 = null;
205         border = null;
206         caller = null;
207     }
208 }
209
Popular Tags