View Javadoc
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 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              // buf.append(RequestUtils.computeURL(pageContext, null, null, page, null, null, null, false));
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         // ResponseUtils.write(pageContext, buf.toString());
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         // ResponseUtils.write(pageContext, results.toString());
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 }