cmlenz 2002/08/19 00:09:50
Modified: src/taglib/jstl/org/apache/slide/taglib/tag/jstl
ForEachMemberTag.java
Log:
Export a custom LoopTagStatus object that has a 'depth' property
Revision Changes Path
1.5 +83 -0
jakarta-slide/src/taglib/jstl/org/apache/slide/taglib/tag/jstl/ForEachMemberTag.java
Index: ForEachMemberTag.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/jstl/org/apache/slide/taglib/tag/jstl/ForEachMemberTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ForEachMemberTag.java 1 Aug 2002 15:43:52 -0000 1.4
+++ ForEachMemberTag.java 19 Aug 2002 07:09:50 -0000 1.5
@@ -71,6 +71,7 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.jstl.core.LoopTagStatus;
import javax.servlet.jsp.jstl.core.LoopTagSupport;
import org.apache.slide.taglib.bean.NodeBean;
@@ -88,6 +89,67 @@
extends LoopTagSupport {
+ // ---------------------------------------------------------- Inner Classes
+
+
+ /**
+ * This class extends LoopTagStatus to provide an additional 'depth'
+ * property, which returns the current depth of the iteration.
+ */
+ public static class Status
+ implements LoopTagStatus {
+
+ public LoopTagStatus status;
+
+ public Integer getBegin() {
+ return status.getBegin();
+ }
+
+ public int getCount() {
+ return status.getCount();
+ }
+
+ public Object getCurrent() {
+ return status.getCurrent();
+ }
+
+ public Integer getEnd() {
+ return status.getEnd();
+ }
+
+ public int getIndex() {
+ return status.getIndex();
+ }
+
+ public Integer getStep() {
+ return status.getStep();
+ }
+
+ public boolean isFirst() {
+ return status.isFirst();
+ }
+
+ public boolean isLast() {
+ return status.isLast();
+ }
+
+ public Integer getDepth() {
+ NodeBean current = (NodeBean)getCurrent();
+ String uri = current.getUri();
+ int index = uri.indexOf('/');
+ int depth = 0;
+ while (index >= 0) {
+ uri = uri.substring(index + 1);
+ index = uri.indexOf('/');
+ depth++;
+ }
+
+ return new Integer(depth);
+ }
+
+ }
+
+
// ----------------------------------------------------- Instance Variables
@@ -134,6 +196,12 @@
protected Iterator iterator;
+ /**
+ * Instance of our custom LoopTagStatus.
+ */
+ private Status status;
+
+
// ----------------------------------------------------------- Constructors
@@ -353,6 +421,21 @@
return Collections.unmodifiableSet(set);
}
+
+
+ /**
+ * Overridden to provide our custom, depth-enabled status.
+ *
+ * @return an instance of ForEachMemberTag.Status
+ */
+ public LoopTagStatus getLoopStatus() {
+
+ if (status == null) {
+ status = new Status();
+ }
+ status.status = super.getLoopStatus();
+ return status;
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>