KickJava   Java API By Example, From Geeks To Geeks.

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


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 PrevTag extends BodyTagSupport JavaDoc {
25
26     private boolean disp = false;
27
28     private String JavaDoc name = null;
29
30     private String JavaDoc text = null;
31     
32     public String JavaDoc getName() {
33         return name;
34     }
35
36     public void setName(String JavaDoc name) {
37         this.name = name;
38     }
39
40     public int doStartTag() throws JspException JavaDoc {
41
42         String JavaDoc dispStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.DISP);
43         if ((dispStrs != null) && (!dispStrs.equals(""))) {
44             if (dispStrs.equals("on"))
45                 disp = true;
46             else if (dispStrs.equals("off"))
47                 disp = false;
48         }
49
50         String JavaDoc startStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.START);
51         int start = Integer.parseInt(startStrs);
52         String JavaDoc url = (String JavaDoc) pageContext.getAttribute(MPageTag.URLNAME);
53         String JavaDoc countStrs = (String JavaDoc) pageContext.getAttribute(MPageTag.COUNT);
54         int count = Integer.parseInt(countStrs);
55
56         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(100);
57         // Print out a left arrow if necessary
58
if (start > 0) {
59
60             buf.append("<a HREF=\"");
61             buf.append(url);
62             buf.append("&start=");
63             buf.append((start - count));
64             buf.append("\" >");
65             if (name != null)
66                 buf.append(name);
67         } else
68             buf.append("");
69
70         output(buf.toString());
71
72         return (EVAL_BODY_INCLUDE);
73
74     }
75
76     /**
77      * Render the end of the hyperlink.
78      *
79      * @exception JspException
80      * if a JSP exception has occurred
81      */

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