KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > taglib > FormatPaginationLinkTag


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

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