1 19 20 package com.sslexplorer.table.tags; 21 22 import java.net.MalformedURLException ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 import java.util.StringTokenizer ; 26 27 import javax.servlet.jsp.JspException ; 28 29 import org.apache.struts.taglib.TagUtils; 30 import org.apache.struts.taglib.html.LinkTag; 31 import org.apache.struts.taglib.logic.IterateTag; 32 33 import com.sslexplorer.core.CoreUtil; 34 import com.sslexplorer.core.tags.FormTag; 35 import com.sslexplorer.table.Pager; 36 37 public class ColumnHeaderTag extends LinkTag { 38 39 43 protected String pagerName = null; 44 45 protected String attributesName; 46 protected String attributesProperties; 47 48 public String getPagerName() { 49 return (this.pagerName); 50 } 51 52 public void setPagerName(String pagerName) { 53 this.pagerName = pagerName; 54 } 55 56 60 protected String pagerProperty = null; 61 62 public String getPagerProperty() { 63 return (this.pagerProperty); 64 } 65 66 public void setPagerProperty(String pagerProperty) { 67 this.pagerProperty = pagerProperty; 68 } 69 70 73 protected int columnIndex = 0; 74 75 public String getColumnIndex() { 76 return String.valueOf(this.columnIndex); 77 } 78 79 public void setColumnIndex(String columnIndex) { 80 this.columnIndex = Integer.parseInt(columnIndex); 81 } 82 83 85 124 public int doEndTag() throws JspException { 125 126 StringBuffer results = new StringBuffer (); 127 Pager pager = (Pager) TagUtils.getInstance().lookup(pageContext, pagerName, pagerProperty, scope); 128 if (text != null) { 129 results.append(text); 130 } 131 if (pager != null) { 132 String name = pager.getModel().getColumnName(columnIndex); 133 if (name.equals(pager.getSortName())) { 134 results.append(" <img border=\"0\" SRC=\""); 135 if (pager.getSortReverse()) { 136 results.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/actions/descending.gif"); 137 } else { 138 results.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/actions/ascending.gif"); 139 } 140 results.append("\"/>"); 141 } 142 } 143 results.append("</a>"); 144 145 TagUtils.getInstance().write(pageContext, results.toString()); 146 return (EVAL_PAGE); 147 148 } 149 150 156 protected String calculateURL() throws JspException { 157 158 Map params = TagUtils.getInstance().computeParameters(pageContext, paramId, paramName, paramProperty, paramScope, name, 160 property, scope, transaction); 161 162 if (indexed) { 165 166 IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class); 168 if (iterateTag == null) { 169 JspException e = new JspException (messages.getMessage("indexed.noEnclosingIterate")); 172 TagUtils.getInstance().saveException(pageContext, e); 173 throw e; 174 } 175 176 if (params == null) { 178 params = new HashMap (); } 180 if (indexId != null) { 181 params.put(indexId, Integer.toString(iterateTag.getIndex())); 182 } else { 183 params.put("index", Integer.toString(iterateTag.getIndex())); 184 } 185 186 } 187 188 Pager pager = (Pager) TagUtils.getInstance().lookup(pageContext, pagerName, pagerProperty, scope); 190 if (pager != null) { 191 if (params == null) { 192 params = new HashMap (); } 194 String name = pager.getModel().getId() + "." + pager.getModel().getColumnName(columnIndex); 195 196 params.put("pageSize", String.valueOf(pager.getPageSize())); 198 params.put("startRow", String.valueOf(pager.getStartRow())); 199 params.put("sortName", name); 200 params.put("sortReverse", name.equals(pager.getModel().getId() + "." + pager.getSortName()) ? String.valueOf(!pager.getSortReverse()) : "false"); 201 } 202 203 205 FormTag formTag = (FormTag)CoreUtil.getParentTagOfClass(FormTag.class, this); 206 if(formTag != null) { 207 if (params == null) { 208 params = new HashMap (); 209 } 210 params.put("subForm", formTag.getSubFormName()); 211 } 212 213 if(attributesName != null) { 214 StringTokenizer t = new StringTokenizer (attributesProperties, ","); 215 while (t.hasMoreTokens()) { 216 String attr = t.nextToken(); 217 try { 218 params.put(attr, TagUtils.getInstance().lookup(pageContext, attributesName, attr, scope).toString()); 219 } catch (Exception e) { 220 } 221 } 222 } 223 224 if(forward == null && page == null && action == null && href == null && 225 formTag != null) { 226 page = formTag.getAction(); 227 } 228 229 String url = null; 230 try { 231 url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href, page, action, module, params, 232 anchor, false, useLocalEncoding); 233 } catch (MalformedURLException e) { 234 TagUtils.getInstance().saveException(pageContext, e); 235 throw new JspException (messages.getMessage("rewrite.url", e.toString())); 236 } 237 return (url); 238 239 } 240 241 244 public void release() { 245 super.release(); 246 pagerName = null; 247 pagerProperty = null; 248 columnIndex = 0; 249 attributesName = null; 250 attributesProperties = null; 251 252 } 253 254 public void setAttributesName(String attributesName) { 255 this.attributesName = attributesName; 256 } 257 258 public void setAttributesProperties(String attributesProperties) { 259 this.attributesProperties = attributesProperties; 260 } 261 262 } 263 | Popular Tags |