KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > renderer > BasicPagerRenderer


1 package fr.improve.struts.taglib.layout.renderer;
2
3 import javax.servlet.http.HttpServletResponse JavaDoc;
4 import javax.servlet.jsp.JspException JavaDoc;
5 import javax.servlet.jsp.PageContext JavaDoc;
6
7 import fr.improve.struts.taglib.layout.pager.PagerTag;
8 import fr.improve.struts.taglib.layout.skin.Skin;
9 import fr.improve.struts.taglib.layout.util.IPagerRenderer;
10 import fr.improve.struts.taglib.layout.util.LayoutUtils;
11
12 public class BasicPagerRenderer implements IPagerRenderer {
13     
14     
15     public void doStartPager(PagerTag in_tag, StringBuffer JavaDoc in_buffer) {
16         // Start
17
in_buffer.append("<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"");
18         if (in_tag.getWidth() != null) {
19             in_buffer.append(" width=\"");
20             in_buffer.append(in_tag.getWidth());
21             in_buffer.append("\"");
22         }
23         if (in_tag.getStyleClass() != null) {
24             in_buffer.append(" class=\"");
25             in_buffer.append(in_tag.getStyleClass());
26             in_buffer.append("\"");
27         }
28         in_buffer.append(" id=\"");
29         in_buffer.append(in_tag.getPagerId());
30         in_buffer.append("\"><tr>\n");
31     }
32
33     public void doPrintPrevious(PagerTag in_tag, StringBuffer JavaDoc in_buffer, int l_currentPage) {
34         // Prev section
35
in_buffer.append("<td");
36         if (in_tag.getAlign()==null) {
37             in_buffer.append(" width=\"50%\" style=\"text-align : right\"");
38         }
39         if (in_tag.getStyleClass() != null) {
40             in_buffer.append(" class='");
41             in_buffer.append(in_tag.getStyleClass());
42             in_buffer.append("'");
43         }
44         in_buffer.append(">");
45         if (l_currentPage >= 1) {
46             PageContext JavaDoc pg = in_tag.getPageContext();
47             in_buffer.append("<a HREF=\"");
48             in_buffer.append(((HttpServletResponse JavaDoc)pg.getResponse()).encodeURL(in_tag.getURL(l_currentPage-1)));
49             in_buffer.append("\">");
50     
51             String JavaDoc lc_previousImgPath = getSkin(pg).getProperty(in_tag.getPreviousImgKey());
52             String JavaDoc lc_previousLabel = getSkin(pg).getProperty(in_tag.getPreviousMsgKey());
53             if (lc_previousImgPath == null || lc_previousImgPath.length()==0) {
54                 in_buffer.append(lc_previousLabel);
55             } else {
56                 in_buffer.append("<img SRC='");
57                 in_buffer.append(getSkin(pg).getImageDirectory(pg.getRequest()));
58                 in_buffer.append("/");
59                 in_buffer.append(lc_previousImgPath);
60                 in_buffer.append("' border='0' alt='");
61                 in_buffer.append(lc_previousLabel);
62                 in_buffer.append("'>");
63             }
64             in_buffer.append("</a>");
65         }
66         in_buffer.append("</td>\n");
67     }
68     
69     
70     
71     private Skin getSkin(PageContext JavaDoc in_pg) {
72         return LayoutUtils.getSkin(in_pg.getSession());
73     }
74
75     public void doPrintMain(PagerTag in_tag, StringBuffer JavaDoc in_buffer, int l_maxPageItems, int l_currentPage) {
76         // Main section
77
in_buffer.append("<td ");
78             if (in_tag.getStyleClass() != null) {
79                 in_buffer.append(" class='");
80                 in_buffer.append(in_tag.getStyleClass());
81                 in_buffer.append("'");
82             }
83         in_buffer.append(">");
84         
85         // Get the maximum number of links to display.
86
int l_maxLinks = in_tag.computeMaxLinks();
87         
88         // Have we display a link previously ?
89
boolean lc_previousDisplayed = true;
90         
91         // Iteration index.
92
int i;
93         for (i = 0; in_tag.getSize() > l_maxPageItems * i ; i++) {
94             
95             if (in_tag.shouldDisplay(i, l_currentPage, in_tag.getNumberOfPage(), l_maxLinks)) {
96                 // Ok, this page number must appear in the pager.
97
if (i != l_currentPage) {
98                     in_buffer.append("<a HREF=\"");
99                     in_buffer.append(((HttpServletResponse JavaDoc)in_tag.getPageContext().getResponse()).encodeURL(in_tag.getURL(i)));
100                     if (in_tag.getStyleClass() != null) {
101                         in_buffer.append("\" class=\"");
102                         in_buffer.append(in_tag.getStyleClass());
103                     }
104                     in_buffer.append("\">");
105                 }
106                 in_buffer.append((i+1));
107                 if (i != l_currentPage) {
108                     in_buffer.append("</a>");
109                 }
110                 lc_previousDisplayed = true;
111                 in_buffer.append("&nbsp;");
112             } else {
113                 // There is too many pages, and we're not displaying a link to this page number.
114
if (lc_previousDisplayed) {
115                     in_buffer.append("...");
116                     in_buffer.append("&nbsp;");
117                 }
118                 lc_previousDisplayed = false;
119             }
120         }
121         in_buffer.append("</td>\n");
122 // /return i;
123
}
124
125     public void doPrintNext(PagerTag in_tag, StringBuffer JavaDoc in_buffer, int l_maxPageItems, int l_currentPage) {
126         // Next section
127
in_buffer.append("<td");
128         if (in_tag.getAlign()==null) {
129             in_buffer.append(" width=\"50%\" style=\"text-align : left\"");
130         }
131         if (in_tag.getStyleClass() != null) {
132             in_buffer.append(" class='");
133             in_buffer.append(in_tag.getStyleClass());
134             in_buffer.append("'");
135         }
136         in_buffer.append(">");
137         Skin lc_skin = getSkin(in_tag.getPageContext());
138         if ((l_currentPage+1) * l_maxPageItems < in_tag.getSize()) {
139             in_buffer.append("<a HREF=\"");
140             in_buffer.append(((HttpServletResponse JavaDoc)in_tag.getPageContext().getResponse()).encodeURL(in_tag.getURL(l_currentPage+1)));
141             in_buffer.append("\">");
142     
143             String JavaDoc lc_nextImgPath = lc_skin.getProperty(in_tag.getNextImgKey());
144             String JavaDoc lc_nextLabel = lc_skin.getProperty(in_tag.getNextMsgKey());
145             if (lc_nextImgPath == null || lc_nextImgPath.length()==0) {
146                 in_buffer.append(lc_nextLabel);
147             } else {
148                 in_buffer.append("<img SRC='");
149                 in_buffer.append(lc_skin.getImageDirectory(in_tag.getPageContext().getRequest()));
150                 in_buffer.append("/");
151                 in_buffer.append(lc_nextImgPath);
152                 in_buffer.append("' border='0' alt='");
153                 in_buffer.append(lc_nextLabel);
154                 in_buffer.append("'>");
155             }
156             in_buffer.append("</a>");
157         }
158         in_buffer.append("</td>\n");
159     }
160
161     public void doPrintDirect(PagerTag in_tag, StringBuffer JavaDoc in_buffer, int in_maxPageItems, int in_currentPage) throws JspException JavaDoc {
162         // Direct go section
163
in_buffer.append("<th");
164         if (in_tag.getStyleClass() != null) {
165             in_buffer.append(" class=\"");
166             in_buffer.append(in_tag.getStyleClass());
167             in_buffer.append("\"");
168         }
169         in_buffer.append(">");
170         in_buffer.append(LayoutUtils.getLabel(in_tag.getPageContext(), in_tag.getGotoProperty(), null));
171         in_buffer.append(" <input type=\"text\" value=\"\" size=\"4\" maxlength=\"4\" onkeypress=\"pagerGoto(this, event, '");
172         in_buffer.append(in_tag.getUrl());
173         in_buffer.append("','");
174         in_buffer.append(PagerTag.PAGE_NUMBER_KEY);
175         in_buffer.append("',");
176         in_buffer.append((int)Math.ceil((float)in_tag.getSize()/in_maxPageItems));
177         in_buffer.append(")\">");
178         
179         in_buffer.append("</th>");
180     }
181
182     public void doEndPager(PagerTag in_tag, StringBuffer JavaDoc in_buffer) {
183         in_buffer.append("</tr></table>");
184     }
185
186     
187     
188 }
189
Popular Tags