1
2
3
4
5
6
7
8
9
10
11 package psiprobe.jsp;
12
13 import java.io.IOException;
14 import java.io.UnsupportedEncodingException;
15 import java.net.URLEncoder;
16 import java.util.Collections;
17
18 import javax.servlet.jsp.JspException;
19 import javax.servlet.jsp.tagext.TagSupport;
20
21 import org.springframework.web.bind.ServletRequestUtils;
22
23
24
25
26 public class ParamToggleTag extends TagSupport {
27
28
29 private static final long serialVersionUID = 1L;
30
31
32 private String param = "size";
33
34 @Override
35 public int doStartTag() throws JspException {
36 boolean getSize =
37 ServletRequestUtils.getBooleanParameter(pageContext.getRequest(), param, false);
38 StringBuilder query = new StringBuilder();
39
40 String encoding = pageContext.getResponse().getCharacterEncoding();
41 for (String name : Collections.list(pageContext.getRequest().getParameterNames())) {
42 if (!param.equals(name)) {
43 try {
44 String value = ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, "");
45 String encodedValue = URLEncoder.encode(value, encoding);
46 if (query.length() > 0) {
47 query.append('&');
48 }
49 query.append(name).append('=').append(encodedValue);
50 } catch (UnsupportedEncodingException e) {
51 throw new JspException(e);
52 }
53 }
54 }
55
56 if (query.length() > 0) {
57 query.append('&');
58 }
59
60 query.append(param).append('=').append(!getSize);
61
62 try {
63 pageContext.getOut().print(query);
64 } catch (IOException e) {
65 throw new JspException("Exception printing query string to JspWriter", e);
66 }
67 return EVAL_BODY_INCLUDE;
68 }
69
70
71
72
73
74
75 public String getParam() {
76 return param;
77 }
78
79
80
81
82
83
84 public void setParam(String param) {
85 this.param = param;
86 }
87
88 }