1 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 text = null; 37 38 private String action = null; 39 private String forward = null; 40 private String paramName = null; 41 private String paramValue = null; 42 private String titleKey = null; 43 private String arg0 = null; 44 private String caller = null; 45 private String targetAction = null; 46 private String target = null; 47 private String styleClass = null; 48 private String queryString = null; 49 50 public String getAction() { 51 return action; 52 } 53 54 public void setAction(String value) { 55 action = value; 56 } 57 58 public String getForward() { 59 return forward; 60 } 61 62 public void setForward(String value) { 63 forward = value; 64 } 65 66 public String getParamName() { 67 return paramName; 68 } 69 70 public void setParamName(String value) { 71 paramName = value; 72 } 73 74 public Object getParamValue() { 75 return paramValue; 76 } 77 78 public void setParamValue(Object value) { 79 paramValue = (value != null ? value.toString() : null); 80 } 81 82 public String getQueryString() { 83 return queryString; 84 } 85 86 public void setQueryString(String value) { 87 queryString = value; 88 } 89 90 public String getTitleKey() { 91 return titleKey; 92 } 93 94 public void setTitleKey(String value) { 95 titleKey = value; 96 } 97 98 public Object getArg0() { 99 return arg0; 100 } 101 102 public void setArg0(Object value) { 103 arg0 = (value != null ? value.toString() : null); 104 } 105 106 public String getCaller() { 107 return caller; 108 } 109 110 public void setCaller(String value) { 111 caller = value; 112 } 113 114 public String getTargetAction() { 115 return targetAction; 116 } 117 118 public void setTargetAction(String value) { 119 targetAction = value; 120 } 121 122 public String getTarget() { 123 return target; 124 } 125 126 public void setTarget(String value) { 127 target = value; 128 } 129 130 public String getStyleClass() { 131 return styleClass; 132 } 133 134 public void setStyleClass(String 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 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 buf = new StringBuffer ("<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 |