1 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 ; 34 import javax.servlet.jsp.tagext.SimpleTag ; 35 import javax.servlet.jsp.tagext.Tag ; 36 import javax.servlet.jsp.tagext.TagAdapter ; 37 import javax.servlet.jsp.tagext.TagSupport ; 38 39 public class IteratorLoopSupportTag extends TagSupport 40 implements LoopTag, LoopTagStatus { 41 private JspTag _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 private Object _current; 51 private boolean _hasNext; 52 53 56 public void setParent(JspTag parent) 57 { 58 _parent = parent; 59 } 60 61 64 public void setParent(Tag parent) 65 { 66 _parent = parent; 67 } 68 69 72 public Tag getParent() 73 { 74 if (_parent == null || _parent instanceof Tag) 75 return (Tag) _parent; 76 else 77 return new TagAdapter ((SimpleTag ) _parent); 78 } 79 80 83 public void init(int begin, int end, int step) 84 { 85 _begin = begin; 86 _end = end; 87 _step = step; 88 _count = 0; 89 _index = _begin - _step; 90 } 91 92 95 public void setCurrent(Object current, boolean hasNext) 96 { 97 _index += _step; 98 99 _current = current; 100 _hasNext = hasNext; 101 102 _count++; 103 } 104 105 108 public Object getCurrent() 109 { 110 return _current; 111 } 112 113 116 public LoopTagStatus getLoopStatus() 117 { 118 return this; 119 } 120 121 public int getIndex() 122 { 123 return _index; 124 } 125 126 public int getCount() 127 { 128 return _count; 129 } 130 131 public boolean isFirst() 132 { 133 return _count == 1; 134 } 135 136 public boolean isLast() 137 { 138 return _end < _index + _step || ! _hasNext; 139 } 140 141 public Integer getBegin() 142 { 143 return new Integer (_begin); 144 } 145 146 public Integer getEnd() 147 { 148 return new Integer (_end); 149 } 150 151 public Integer getStep() 152 { 153 return new Integer (_step); 154 } 155 } 156 | Popular Tags |