1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.taglib;
20
21 import java.net.MalformedURLException;
22
23 import javax.servlet.jsp.JspException;
24 import javax.servlet.jsp.tagext.BodyTagSupport;
25
26 import org.apache.struts.taglib.TagUtils;
27
28 public final class FormatPaginationLinkTag extends BodyTagSupport {
29
30
31
32 private static final long serialVersionUID = 1L;
33
34 private String text = null;
35
36 private String order = null;
37 private String page = null;
38 private Integer projectId = null;
39 private int start = 0;
40 private String styleClass = null;
41
42 public String getOrder() {
43 return order;
44 }
45
46 public void setOrder(String value) {
47 order = value;
48 }
49
50 public String getPage() {
51 return page;
52 }
53
54 public void setPage(String value) {
55 page = value;
56 }
57
58 public Integer getProjectId() {
59 return projectId;
60 }
61
62 public void setProjectId(Integer value) {
63 projectId = value;
64 }
65
66 public int getStart() {
67 return start;
68 }
69
70 public void setStart(int value) {
71 start = value;
72 }
73
74 public String getStyleClass() {
75 return styleClass;
76 }
77
78 public void setStyleClass(String value) {
79 styleClass = value;
80 }
81
82 public int doStartTag() throws JspException {
83 StringBuffer buf = new StringBuffer("<a href=\"");
84 try {
85
86 buf.append(TagUtils.getInstance().computeURL(pageContext, null, null, page, null, null, null, null, false));
87 } catch(MalformedURLException murle) {
88 buf.append(page);
89 }
90 buf.append("?start=" + start);
91 if(projectId != null) {
92 buf.append("&projectId=" + projectId);
93 }
94 if(order != null && order.trim().length() > 0) {
95 buf.append("&order=" + order);
96 }
97 buf.append("\"");
98 if(styleClass != null) {
99 buf.append("class=\"" + styleClass + "\"");
100 }
101 buf.append(">");
102
103 TagUtils.getInstance().write(pageContext, buf.toString());
104 text = null;
105 return (EVAL_BODY_BUFFERED);
106 }
107
108 public int doAfterBody() throws JspException {
109 if (bodyContent != null) {
110 String value = bodyContent.getString().trim();
111 if (value.length() > 0) {
112 text = value;
113 }
114 }
115 return (SKIP_BODY);
116 }
117
118 public int doEndTag() throws JspException {
119 StringBuffer results = new StringBuffer();
120 if (text != null) {
121 results.append(text);
122 }
123 results.append("</a>");
124
125 TagUtils.getInstance().write(pageContext, results.toString());
126 clearState();
127 return (EVAL_PAGE);
128 }
129
130 public void release() {
131 super.release();
132 clearState();
133 }
134
135 private void clearState() {
136 text = null;
137 order = null;
138 page = null;
139 projectId = null;
140 start = 0;
141 styleClass = null;
142 }
143 }