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 import javax.servlet.jsp.tagext.TagSupport ; 29 30 import org.apache.struts.taglib.TagUtils; 31 32 import com.sslexplorer.core.CoreUtil; 33 import com.sslexplorer.core.tags.FormTag; 34 import com.sslexplorer.table.Pager; 35 36 public class PageSizeTag extends TagSupport { 37 protected String pagerProperty = null; 38 protected String pagerName = null; 39 protected String action = null; 40 protected String styleId = null; 41 protected String styleClass = null; 42 protected String style = null; 43 protected String forward; 44 protected String attributesName; 45 protected String attributesProperties; 46 protected String subForm = null; 47 48 public final static String [] PAGE_SIZES = { "10", "20", "50", "100", "*" }; 49 50 public String getPagerName() { 51 return (this.pagerName); 52 } 53 54 public void setAction(String action) { 55 this.action = action; 56 } 57 58 public String getAction() { 59 return action; 60 } 61 62 public String getForward() { 63 return forward; 64 } 65 66 public void setForward(String forward) { 67 this.forward = forward; 68 } 69 70 public void setPagerName(String pagerName) { 71 this.pagerName = pagerName; 72 } 73 74 public void setSubForm(String subForm) { 75 this.subForm = subForm; 76 } 77 78 public String getSubForm() { 79 return subForm; 80 } 81 public String getPagerProperty() { 82 return (this.pagerProperty); 83 } 84 85 public void setPagerProperty(String pagerProperty) { 86 this.pagerProperty = pagerProperty; 87 } 88 89 public void setStyle(String style) { 90 this.style = style; 91 } 92 93 public String getStyle() { 94 return style; 95 } 96 97 public void setStyleClass(String styleClass) { 98 this.styleClass = styleClass; 99 } 100 101 public String getStyleClass() { 102 return styleClass; 103 } 104 105 public void setStyleId(String styleId) { 106 this.styleId = styleId; 107 } 108 109 public String getStyleId() { 110 return styleId; 111 } 112 113 public void release() { 114 super.release(); 115 pagerName = null; 116 pagerProperty = null; 117 action = null; 118 styleId = null; 119 styleClass = null; 120 style = null; 121 forward = null; 122 attributesName = null; 123 attributesProperties = null; 124 subForm = null; 125 126 } 127 128 public void setAttributesName(String attributesName) { 129 this.attributesName = attributesName; 130 } 131 132 public void setAttributesProperties(String attributesProperties) { 133 this.attributesProperties = attributesProperties; 134 } 135 136 public int doEndTag() throws JspException { 137 StringBuffer results = new StringBuffer (); 138 Pager pager = (Pager) TagUtils.getInstance().lookup(pageContext, pagerName, pagerProperty, null); 139 if (pager != null && pager.getModel().getRowCount() >= Integer.parseInt(PAGE_SIZES[0])) { 140 141 results.append("<ul>"); 143 for (int i = 0; i < PAGE_SIZES.length; i++) { 144 if(PAGE_SIZES[i].equals("*") || pager.getModel().getRowCount() >= Integer.parseInt(PAGE_SIZES[i])) { 145 results.append("<li><a HREF=\""); 146 results.append(getPageLink(PAGE_SIZES[i].equals("*") ? 0 : Integer.parseInt(PAGE_SIZES[i]), pager)); 147 results.append("\""); 148 results.append(makeStyles(false)); 149 results.append("><div class=\"pageSize\">"); 150 results.append(PAGE_SIZES[i]); 151 results.append("</div></a></li>"); 152 } 153 } 154 results.append("</ul>"); 155 } 156 else { 157 results.append(" "); 158 } 159 160 TagUtils.getInstance().write(pageContext, results.toString()); 161 return (EVAL_PAGE); 162 163 } 164 165 protected String getPageLink(int pageSize, Pager pager) { 166 String url = null; 167 try { 168 Map params = new HashMap (); 169 params.put("pageSize", String.valueOf(pageSize)); 170 params.put("sortName", pager.getSortName()); 171 params.put("sortReverse", String.valueOf(pager.getSortReverse())); 172 if(subForm!=null) 173 params.put("subForm", subForm); 174 if (pageSize == 0 || pageSize > pager.getFilteredRowCount()) { 175 params.put("startRow", "0"); 176 } 177 else { 178 params.put("startRow", String.valueOf(pager.getStartRow())); 179 } 180 if(attributesName != null) { 181 StringTokenizer t = new StringTokenizer (attributesProperties, ","); 182 while (t.hasMoreTokens()) { 183 String attr = t.nextToken(); 184 try { 185 params.put(attr, TagUtils.getInstance().lookup(pageContext, attributesName, attr, null).toString()); 186 } catch (Exception e) { 187 } 188 } 189 } 190 url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, null, "", action, null, params, null, 191 false, false); 192 } catch (MalformedURLException e) { 193 } 194 return (url); 195 } 196 197 protected String makeStyles(boolean disabled) throws JspException { 198 StringBuffer results = new StringBuffer (); 199 String s = getStyleClass(); 200 if (s != null) { 201 results.append(" class=\""); 202 results.append(s); 203 results.append("\""); 204 } 205 s = getStyle(); 206 if (s != null) { 207 results.append(" style=\""); 208 results.append(s); 209 results.append("\""); 210 } 211 s = getStyleId(); 212 if (s != null) { 213 results.append(" id=\""); 214 results.append(s); 215 results.append("\""); 216 } 217 return results.toString(); 218 } 219 220 225 public int doStartTag() throws JspException { 226 FormTag formTag = (FormTag) CoreUtil.getParentTagOfClass(FormTag.class, this); 228 if (formTag != null) { 229 subForm = formTag.getSubFormName(); 230 } 231 else { 232 subForm = null; 233 } 234 return SKIP_BODY; 235 } 236 237 } 238 | Popular Tags |