KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > strutsutil > taglib > NextTag


1 /**
2  * Copyright 2003-2006 the original author or authors. Licensed under the Apache
3  * License, Version 2.0 (the "License"); you may not use this file except in
4  * compliance with the License. You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11  * License for the specific language governing permissions and limitations under
12  * the License.
13  */

14
15 package com.jdon.strutsutil.taglib;
16
17 import java.io.IOException JavaDoc;
18
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.JspWriter JavaDoc;
22 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
23
24 public class NextTag extends BodyTagSupport JavaDoc {
25
26     private boolean disp = false;
27
28     private String JavaDoc name = null;
29
30     public String JavaDoc getName() {
31         return name;
32     }
33
34     public void setName(String JavaDoc name) {
35         this.name = name;
36     }
37
38     public int doStartTag() throws JspException JavaDoc {
39
40         String JavaDoc dispStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.DISP);
41         if ((dispStrs != null) && (!dispStrs.equals(""))) {
42             if (dispStrs.equals("on"))
43                 disp = true;
44             else if (dispStrs.equals("off"))
45                 disp = false;
46         }
47
48         String JavaDoc startStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.START);
49         int start = Integer.parseInt(startStrs);
50
51         String JavaDoc url = (String JavaDoc) pageContext.getAttribute(MPageTag.URLNAME);
52
53         String JavaDoc countStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.COUNT);
54         int count = Integer.parseInt(countStrs);
55
56         String JavaDoc allCountStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.ALLCOUNT);
57         int allCount = Integer.parseInt(allCountStrs);
58       
59
60         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(100);
61
62         if ((allCount > (start + count)) ) {
63             buf.append("<a HREF=\"");
64             buf.append(url);
65             buf.append("&start=");
66             buf.append((start + count));
67             buf.append("\" >");
68             if (name != null)
69                 buf.append(name);
70         } else
71             buf.append("");
72
73         output(buf.toString());
74
75         return (EVAL_BODY_INCLUDE);
76
77     }
78
79     /**
80      * Render the end of the hyperlink.
81      *
82      * @exception JspException
83      * if a JSP exception has occurred
84      */

85     public int doEndTag() throws JspException JavaDoc {
86         output("</a>");
87         return (EVAL_PAGE);
88
89     }
90
91     private void output(String JavaDoc s) throws JspException JavaDoc {
92         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc) pageContext.getResponse();
93         JspWriter JavaDoc writer = pageContext.getOut();
94         try {
95             if (disp)
96                 writer.print(s);
97         } catch (IOException JavaDoc e) {
98             throw new JspException JavaDoc("NextTag error");
99         }
100
101     }
102
103     
104     public void release() {
105         super.release();
106         disp = false;
107         name = null;
108
109     }
110
111   
112
113 }
114
Popular Tags