| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
package net.smartlab.web.page; |
| 24 |
|
|
| 25 |
|
import java.io.IOException; |
| 26 |
|
import java.util.Collection; |
| 27 |
|
import javax.servlet.http.HttpServletRequest; |
| 28 |
|
import javax.servlet.jsp.JspException; |
| 29 |
|
import javax.servlet.jsp.JspTagException; |
| 30 |
|
import javax.servlet.jsp.PageContext; |
| 31 |
|
import org.apache.struts.taglib.TagUtils; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@author |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 86 (86) |
Complexity: 23 |
Complexity Density: 0,43 |
|
| 41 |
|
public class PaginateTag extends AbstractTag { |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
public final static String PARAMETER = "net.smartlab.web.page"; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
private Paginator paginator = null; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
private String name = null; |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
private String property = null; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
private String parameter; |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
private String href = ""; |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
private String form = null; |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
private int size = Paginator.UNLIMITED_ITEMS; |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
private int pages = Paginator.UNLIMITED_PAGES; |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
@see |
| 94 |
|
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 9 |
Complexity Density: 0,31 |
|
| 95 |
0
|
public int doStartTag() throws JspException {... |
| 96 |
0
|
String index = ((HttpServletRequest)context.getRequest()).getParameter(parameter); |
| 97 |
0
|
Object attribute = TagUtils.getInstance().lookup(context, name, property, "request"); |
| 98 |
0
|
if (attribute instanceof Paginator) { |
| 99 |
0
|
this.paginator = (Paginator)attribute; |
| 100 |
0
|
} else if (attribute instanceof Collection) { |
| 101 |
0
|
this.paginator = new CollectionPaginator((Collection)attribute); |
| 102 |
0
|
String attributeName = name; |
| 103 |
0
|
if (property != null) { |
| 104 |
0
|
attributeName = property; |
| 105 |
|
} |
| 106 |
0
|
context.setAttribute(attributeName, this.paginator, PageContext.PAGE_SCOPE); |
| 107 |
|
} |
| 108 |
0
|
context.setAttribute("paginator", this.paginator, PageContext.PAGE_SCOPE); |
| 109 |
0
|
if (size == Paginator.UNLIMITED_ITEMS) { |
| 110 |
0
|
paginator.setPageSize(paginator.getCount()); |
| 111 |
|
} else { |
| 112 |
0
|
paginator.setPageSize(size); |
| 113 |
|
} |
| 114 |
0
|
paginator.setPages(pages); |
| 115 |
0
|
if (index != null && index.length() > 0) { |
| 116 |
0
|
paginator.setPage(Integer.parseInt(index)); |
| 117 |
|
} else { |
| 118 |
0
|
paginator.setPage(1); |
| 119 |
|
} |
| 120 |
0
|
if (form != null) { |
| 121 |
0
|
try { |
| 122 |
0
|
context.getOut().println("<input type='hidden' name='" + parameter + "'/>"); |
| 123 |
0
|
context.getOut().println("<script>"); |
| 124 |
0
|
context.getOut().println(" function paginate(page) {"); |
| 125 |
0
|
context.getOut().println(" document.forms['" + form + "'].elements['" + parameter + "'].value = page;"); |
| 126 |
0
|
context.getOut().println(" document.forms['" + form + "'].action = '';"); |
| 127 |
0
|
context.getOut().println(" document.forms['" + form + "'].submit();"); |
| 128 |
0
|
context.getOut().println(" }"); |
| 129 |
0
|
context.getOut().println("</script>"); |
| 130 |
|
} catch (IOException ioe) { |
| 131 |
|
throw new JspTagException(ioe); |
| 132 |
|
} |
| 133 |
|
} |
| 134 |
0
|
return EVAL_BODY_INCLUDE; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
@param |
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 145 |
0
|
public void setName(String name) {... |
| 146 |
0
|
this.name = name; |
| 147 |
0
|
this.parameter = PARAMETER + '.' + name; |
| 148 |
|
} |
| 149 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
| 150 |
0
|
public void setProperty(String property) {... |
| 151 |
0
|
this.property = property; |
| 152 |
0
|
if (property != null) { |
| 153 |
0
|
this.parameter = PARAMETER + '.' + name + "." + property; |
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
@return |
| 161 |
|
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0,36 |
|
| 162 |
0
|
protected String getHref() {... |
| 163 |
0
|
if (form == null) { |
| 164 |
0
|
String query = ((HttpServletRequest)context.getRequest()).getQueryString(); |
| 165 |
0
|
if (query != null) { |
| 166 |
0
|
int start = query.indexOf(parameter + '='); |
| 167 |
0
|
int end = query.length(); |
| 168 |
0
|
if (start > -1) { |
| 169 |
0
|
end = query.indexOf("&", start); |
| 170 |
0
|
if (end > -1) { |
| 171 |
0
|
query = query.substring(0, start) + query.substring(end + 1) + '&' + parameter + '='; |
| 172 |
|
} else { |
| 173 |
0
|
query = query.substring(0, start + parameter.length() + 1); |
| 174 |
|
} |
| 175 |
|
} else { |
| 176 |
0
|
query = query + '&' + parameter + '='; |
| 177 |
|
} |
| 178 |
|
} else { |
| 179 |
0
|
query = parameter + '='; |
| 180 |
|
} |
| 181 |
0
|
return href + '?' + query; |
| 182 |
|
} else { |
| 183 |
0
|
return href.substring(1); |
| 184 |
|
} |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
@param |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 196 |
0
|
public void setHref(String href) {... |
| 197 |
0
|
this.href = href; |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
@param |
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 208 |
0
|
public void setForm(String form) {... |
| 209 |
0
|
this.form = form; |
| 210 |
|
} |
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
@param |
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 219 |
0
|
public void setSize(int size) {... |
| 220 |
0
|
this.size = size; |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
@param |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 230 |
0
|
public void setPages(int pages) {... |
| 231 |
0
|
this.pages = pages; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
|
@see |
| 236 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 237 |
0
|
protected Paginator getPaginator() {... |
| 238 |
0
|
return paginator; |
| 239 |
|
} |
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
|
| 244 |
|
|
| 245 |
|
|
| 246 |
|
@return |
| 247 |
|
|
| 248 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 249 |
0
|
protected boolean isForm() {... |
| 250 |
0
|
return form != null; |
| 251 |
|
} |
| 252 |
|
} |