KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jsp > IntegerLoopSupportTag


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jsp;
30
31 import javax.servlet.jsp.jstl.core.LoopTag;
32 import javax.servlet.jsp.jstl.core.LoopTagStatus;
33 import javax.servlet.jsp.tagext.JspTag JavaDoc;
34 import javax.servlet.jsp.tagext.SimpleTag JavaDoc;
35 import javax.servlet.jsp.tagext.Tag JavaDoc;
36 import javax.servlet.jsp.tagext.TagAdapter JavaDoc;
37 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
38
39 public class IntegerLoopSupportTag extends TagSupport JavaDoc
40   implements LoopTag, LoopTagStatus {
41   private JspTag JavaDoc _parent;
42   
43   private int _begin;
44   private int _end;
45   private int _step;
46   
47   private int _index;
48   private int _count;
49
50   /**
51    * Sets the parent as a JspTag
52    */

53   public void setParent(JspTag JavaDoc parent)
54   {
55     _parent = parent;
56   }
57
58   /**
59    * Sets the parent as a JspTag
60    */

61   public void setParent(Tag parent)
62   {
63     _parent = parent;
64   }
65
66   /**
67    * Returns the parent.
68    */

69   public Tag getParent()
70   {
71     if (_parent == null || _parent instanceof Tag)
72       return (Tag) _parent;
73     else
74       return new TagAdapter JavaDoc((SimpleTag JavaDoc) _parent);
75   }
76   
77   /**
78    * Sets the initial values.
79    */

80   public void init(int begin, int end, int step)
81   {
82     _begin = begin;
83     _end = end;
84     _step = step;
85     _count = 0;
86   }
87   
88   /**
89    * Sets the current value.
90    */

91   public void setCurrent(int current)
92   {
93     _index = current;
94     _count++;
95   }
96   
97   /**
98    * Returns the current value.
99    */

100   public Object JavaDoc getCurrent()
101   {
102     return new Integer JavaDoc(_index);
103   }
104   
105   /**
106    * Returns the loop status
107    */

108   public LoopTagStatus getLoopStatus()
109   {
110     return this;
111   }
112
113   public int getIndex()
114   {
115     return _index;
116   }
117   
118   public int getCount()
119   {
120     return _count;
121   }
122   
123   public boolean isFirst()
124   {
125     return _count == 1;
126   }
127   
128   public boolean isLast()
129   {
130     return _end < _index + _step;
131   }
132   
133   public Integer JavaDoc getBegin()
134   {
135     return new Integer JavaDoc(_begin);
136   }
137   
138   public Integer JavaDoc getEnd()
139   {
140     return new Integer JavaDoc(_end);
141   }
142   
143   public Integer JavaDoc getStep()
144   {
145     return new Integer JavaDoc(_step);
146   }
147 }
148
Popular Tags