KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > tags > BlockOptionsTag


1 /*
2  * $$Id$$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on Oct 6, 2003
27  *
28  */

29 package org.jresearch.gossip.tags;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Enumeration JavaDoc;
33
34 import javax.servlet.ServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36 import javax.servlet.jsp.JspException JavaDoc;
37 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
38
39 import org.jresearch.gossip.IConst;
40 import org.jresearch.gossip.list.RecordsData;
41
42 /**
43  * DOCUMENT ME!
44  *
45  * @author Bel
46  */

47 public class BlockOptionsTag extends TagSupport JavaDoc {
48
49     private String JavaDoc id;
50
51     /**
52      * DOCUMENT ME!
53      *
54      * @return DOCUMENT ME!
55      *
56      * @throws JspException
57      * DOCUMENT ME!
58      */

59     public int doStartTag() throws JspException JavaDoc {
60         try {
61             if (pageContext.getAttribute(id) != null) {
62                 return (SKIP_BODY);
63             }
64             HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) pageContext
65                     .getResponse();
66             ServletRequest JavaDoc req = pageContext.getRequest();
67             Enumeration JavaDoc pnames = req.getParameterNames();
68             StringBuffer JavaDoc url = new StringBuffer JavaDoc((String JavaDoc) req
69                     .getAttribute(IConst.REQUEST.REQUEST_URI)
70                     + "?");
71
72             while (pnames.hasMoreElements()) {
73                 String JavaDoc name = (String JavaDoc) pnames.nextElement();
74
75                 if (!name.equals("block") && req.getParameter(name) != null
76                         && !req.getParameter(name).equals("")) {
77                     url.append(name);
78                     url.append("=");
79                     url.append(req.getParameter(name));
80
81                     if (pnames.hasMoreElements()) {
82                         url.append("&");
83                     }
84                 }
85             }
86
87             RecordsData recordsData = (RecordsData) req
88                     .getAttribute(IConst.REQUEST.RECORDS_DATA);
89             ArrayList JavaDoc options = new ArrayList JavaDoc();
90
91             int i = 0;
92
93             while (i < recordsData.getRecordsCount()) {
94                 int endRecord = ((i + recordsData.getBlockSize()) < recordsData
95                         .getRecordsCount()) ? (i + recordsData.getBlockSize())
96                         : recordsData.getRecordsCount();
97                 OptionBean ob = new OptionBean();
98
99                 ob.setProperty(response.encodeURL(url.toString() + "&block="
100                         + i));
101                 ob.setLabelProperty((i + 1) + "-" + endRecord);
102                 options.add(ob);
103
104                 if (i == recordsData.getCurrBlock()) {
105                     pageContext.setAttribute(IConst.PAGE.SELECTED_BLOCK, ob);
106                 }
107
108                 i = endRecord;
109             }
110
111             pageContext.setAttribute(id, options);
112         } catch (Exception JavaDoc ex) {
113             throw new JspException JavaDoc("error in BlockOptionsTag tag:", ex);
114         }
115
116         return (SKIP_BODY);
117     }
118
119     /**
120      * DOCUMENT ME!
121      *
122      * @return
123      */

124     public String JavaDoc getId() {
125         return id;
126     }
127
128     /**
129      * DOCUMENT ME!
130      *
131      * @param string
132      */

133     public void setId(String JavaDoc string) {
134         id = string;
135     }
136 }
Popular Tags