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