KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26 import javax.servlet.jsp.tagext.*;
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 FormatLinkTag extends BodyTagSupport {
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 titleKey = null;
43     private String JavaDoc arg0 = null;
44     private String JavaDoc caller = null;
45     private String JavaDoc targetAction = null;
46     private String JavaDoc target = null;
47     private String JavaDoc styleClass = null;
48     private String JavaDoc queryString = 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 getQueryString() {
83         return queryString;
84     }
85
86     public void setQueryString(String JavaDoc value) {
87         queryString = value;
88     }
89
90     public String JavaDoc getTitleKey() {
91         return titleKey;
92     }
93
94     public void setTitleKey(String JavaDoc value) {
95           titleKey = 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 getCaller() {
107         return caller;
108     }
109
110     public void setCaller(String JavaDoc value) {
111           caller = value;
112     }
113
114     public String JavaDoc getTargetAction() {
115         return targetAction;
116     }
117
118     public void setTargetAction(String JavaDoc value) {
119           targetAction = value;
120     }
121
122     public String JavaDoc getTarget() {
123         return target;
124     }
125
126     public void setTarget(String JavaDoc value) {
127           target = value;
128     }
129
130     public String JavaDoc getStyleClass() {
131         return styleClass;
132     }
133
134     public void setStyleClass(String JavaDoc value) {
135           styleClass = value;
136     }
137
138     public int doStartTag() throws JspException {
139         text = null;
140         return EVAL_BODY_BUFFERED;
141     }
142
143     public int doAfterBody() throws JspException {
144         if(bodyContent != null) {
145             String JavaDoc value = bodyContent.getString().trim();
146             if(value.length() > 0) {
147                 text = value;
148             }
149         }
150         return SKIP_BODY;
151     }
152
153     public int doEndTag() throws JspException {
154         boolean hasParams = false;
155         Locale currLocale = null;
156
157         HttpSession session = pageContext.getSession();
158         if(session != null) {
159             currLocale = (Locale) session.getAttribute(Constants.LOCALE_KEY);
160         }
161
162         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("<a HREF=\"");
163         try {
164             buf.append(RequestUtils.computeURL(pageContext, forward, null, null, action, null, null, false));
165         } catch(MalformedURLException murle) {
166             buf.append(forward);
167         }
168         if(queryString != null) {
169             buf.append("?" + queryString);
170             hasParams = true;
171         }
172         if(paramName != null && paramValue != null) {
173             buf.append((hasParams ? "&" : "?") + paramName + "=" + paramValue);
174             hasParams = true;
175         }
176         if(caller != null) {
177             buf.append((hasParams ? "&" : "?") + "caller=" + caller);
178             hasParams = true;
179         }
180         if(targetAction != null) {
181             buf.append((hasParams ? "&" : "?") + "action=" + targetAction);
182             hasParams = true;
183         }
184         buf.append("\"");
185         if(target != null) {
186             buf.append(" target=\"" + target + "\"");
187         }
188         if(titleKey != null) {
189             buf.append(" title=\"" + ITrackerResources.getString(titleKey, currLocale, (arg0 == null ? "" : arg0)) + "\"");
190         }
191         if(styleClass != null) {
192             buf.append(" class=\"" + styleClass + "\"");
193         }
194         buf.append(">");
195         buf.append((text == null ? "" : text));
196         buf.append("</a>");
197         ResponseUtils.write(pageContext, buf.toString());
198         clearState();
199         return (EVAL_PAGE);
200     }
201
202     public void release() {
203         super.release();
204         clearState();
205     }
206
207     private void clearState() {
208         text = null;
209         action = null;
210         forward = null;
211         paramName = null;
212         paramValue = null;
213         titleKey = null;
214         arg0 = null;
215         caller = null;
216         target = null;
217         targetAction = null;
218         styleClass = null;
219         queryString = null;
220     }
221 }
222
Popular Tags