cmlenz 2002/08/01 04:49:06
Modified: src/taglib/jstl/org/apache/slide/taglib/tag/jstl
ForEachLockTag.java ForEachMemberTag.java
src/taglib/struts/org/apache/slide/taglib/tag/struts
IterateMembersTag.java IterateLocksTag.java
Log:
- Use the new iteration stuff in org.apache.slide.taglib.util
- Implement doEndTag() and a default ctor to enable tag reuse (not tested)
Revision Changes Path
1.3 +46 -6
jakarta-slide/src/taglib/jstl/org/apache/slide/taglib/tag/jstl/ForEachLockTag.java
Index: ForEachLockTag.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/jstl/org/apache/slide/taglib/tag/jstl/ForEachLockTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ForEachLockTag.java 31 Jul 2002 13:40:00 -0000 1.2
+++ ForEachLockTag.java 1 Aug 2002 11:49:05 -0000 1.3
@@ -65,10 +65,12 @@
import java.util.Iterator;
+import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.LoopTagSupport;
import org.apache.slide.taglib.bean.NodeBean;
+import org.apache.slide.taglib.util.Iterators;
/**
* Tag class that extends the JSTL loop tag to provide recursive iteration over
@@ -94,7 +96,19 @@
/**
* Iterator over the list of locks.
*/
- protected Iterator locks;
+ protected Iterator iterator;
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Default constructor.
+ */
+ public ForEachLockTag() {
+
+ init();
+ }
// ------------------------------------------ LoopTagSupport Implementation
@@ -127,7 +141,7 @@
}
}
- locks = node.getLocks(depthValue).iterator();
+ iterator = Iterators.locksIterator(node, depthValue);
}
@@ -137,7 +151,7 @@
protected boolean hasNext()
throws JspTagException {
- return locks.hasNext();
+ return iterator.hasNext();
}
@@ -147,7 +161,21 @@
protected Object next()
throws JspTagException {
- return locks.next();
+ return iterator.next();
+ }
+
+
+ /**
+ * Called by the JSP Engine when closing this tag.
+ *
+ * @throws JspException not thrown
+ */
+ public int doEndTag()
+ throws JspException {
+
+ init();
+
+ return super.doEndTag();
}
@@ -157,8 +185,7 @@
public void release() {
super.release();
- depth = null;
- locks = null;
+ init();
}
@@ -184,6 +211,19 @@
public void setDepth(String depth) {
this.depth = depth;
+ }
+
+
+ // -------------------------------------------------------- Private Methods
+
+
+ /**
+ * Initialize state for tag reuse.
+ */
+ private void init() {
+
+ depth = null;
+ iterator = null;
}
1.2 +60 -57
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ForEachMemberTag.java 31 Jul 2002 13:34:15 -0000 1.1
+++ ForEachMemberTag.java 1 Aug 2002 11:49:05 -0000 1.2
@@ -63,14 +63,18 @@
package org.apache.slide.taglib.tag.jstl;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import java.util.StringTokenizer;
-import java.util.Vector;
+import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.jstl.core.LoopTagSupport;
import org.apache.slide.taglib.bean.NodeBean;
+import org.apache.slide.taglib.util.Iterators;
/**
* Tag class that extends the JSTL loop tag to provide iteration over the
@@ -120,10 +124,22 @@
/**
* Iterator over the list of members.
*/
- protected Iterator members;
+ protected Iterator iterator;
- // ------------------------------------------------------------ Tag Methods
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Default constructor.
+ */
+ public ForEachMemberTag() {
+
+ init();
+ }
+
+
+ // ------------------------------------------ LoopTagSupport Implementation
/**
@@ -156,48 +172,11 @@
}
}
- Vector members = node.getMembers(depthValue);
-
- // evaluate the includes/excludes, which can be comma separated lists
- Vector includeRolesVector = tokenizeString(includeRoles);
- Vector excludeRolesVector = tokenizeString(excludeRoles);
- Vector includeTypesVector = tokenizeString(includeTypes);
- Vector excludeTypesVector = tokenizeString(excludeTypes);
-
- Iterator i = members.iterator();
- membersIteration: while (i.hasNext()) {
- NodeBean member = (NodeBean)i.next();
-
- String nodeType = member.getType();
- if (excludeTypesVector.contains(nodeType) ||
- (!includeTypesVector.isEmpty() &&
- !includeTypesVector.contains(nodeType))) {
- i.remove();
- continue membersIteration;
- }
-
- Vector nodeRoles = member.getRoles();
- for (int j = 0; j < nodeRoles.size(); j++) {
- String nodeRole = (String)nodeRoles.elementAt(j);
- if (excludeRolesVector.contains(nodeRole)) {
- i.remove();
- continue membersIteration;
- }
- if (!includeRolesVector.isEmpty() &&
- includeRolesVector.contains(nodeRole)) {
- continue membersIteration;
- }
- }
-
- // if this point is reached, none of the member's roles has been
- // included, so we remove it from the list
- if (!includeRolesVector.isEmpty()) {
- i.remove();
- continue membersIteration;
- }
- }
-
- this.members = members.iterator();
+ this.iterator = Iterators.membersIterator(node, depthValue,
+ tokenizeString(excludeRoles),
+ tokenizeString(includeRoles),
+ tokenizeString(excludeTypes),
+ tokenizeString(includeTypes));
}
@@ -211,7 +190,7 @@
protected boolean hasNext()
throws JspTagException {
- return members.hasNext();
+ return iterator.hasNext();
}
@@ -224,7 +203,21 @@
protected Object next()
throws JspTagException {
- return members.next();
+ return iterator.next();
+ }
+
+
+ /**
+ * Called by the JSP Engine when closing this tag.
+ *
+ * @throws JspException not thrown
+ */
+ public int doEndTag()
+ throws JspException {
+
+ init();
+
+ return super.doEndTag();
}
@@ -234,11 +227,7 @@
public void release() {
super.release();
- depth = null;
- includeRoles = null;
- excludeRoles = null;
- includeTypes = null;
- excludeTypes = null;
+ init();
}
@@ -315,20 +304,34 @@
/**
+ * Initialize state for tag reuse.
+ */
+ private void init() {
+
+ depth = null;
+ includeRoles = null;
+ excludeRoles = null;
+ includeTypes = null;
+ excludeTypes = null;
+ iterator = null;
+ }
+
+
+ /**
* Splits the given string into its tokens, separated by commata, and
- * returns the tokens in a new Vector.
+ * returns the tokens in a immutable Set.
*/
- private static Vector tokenizeString(String values) {
+ private static Set tokenizeString(String values) {
- Vector v = new Vector();
+ Set set = new HashSet();
if (values != null) {
StringTokenizer st = new StringTokenizer(values, ",");
while (st.hasMoreElements()) {
- v.addElement(((String)st.nextElement()).trim());
+ set.add(((String)st.nextElement()).trim());
}
}
- return v;
+ return Collections.unmodifiableSet(set);
}
1.6 +58 -57
jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/IterateMembersTag.java
Index: IterateMembersTag.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/IterateMembersTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IterateMembersTag.java 31 Jul 2002 13:21:16 -0000 1.5
+++ IterateMembersTag.java 1 Aug 2002 11:49:06 -0000 1.6
@@ -63,13 +63,15 @@
package org.apache.slide.taglib.tag.struts;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import java.util.StringTokenizer;
-import java.util.Vector;
import javax.servlet.jsp.JspException;
import org.apache.slide.taglib.bean.NodeBean;
+import org.apache.slide.taglib.util.Iterators;
import org.apache.struts.taglib.logic.IterateTag;
/**
@@ -117,6 +119,18 @@
protected String excludeTypes;
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Default constructor.
+ */
+ public IterateMembersTag() {
+
+ init();
+ }
+
+
// ------------------------------------------------------------ Tag Methods
@@ -149,50 +163,27 @@
}
}
- Vector members = node.getMembers(depthValue);
+ setCollection(Iterators.membersIterator(node, depthValue,
+ tokenizeString(excludeRoles),
+ tokenizeString(includeRoles),
+ tokenizeString(excludeTypes),
+ tokenizeString(includeTypes)));
- // evaluate the includes/excludes, which can be comma separated lists
- Vector includeRolesVector = tokenizeString(includeRoles);
- Vector excludeRolesVector = tokenizeString(excludeRoles);
- Vector includeTypesVector = tokenizeString(includeTypes);
- Vector excludeTypesVector = tokenizeString(excludeTypes);
-
- Iterator i = members.iterator();
- membersIteration: while (i.hasNext()) {
- NodeBean member = (NodeBean)i.next();
-
- String nodeType = member.getType();
- if (excludeTypesVector.contains(nodeType) ||
- (!includeTypesVector.isEmpty() &&
- !includeTypesVector.contains(nodeType))) {
- i.remove();
- continue membersIteration;
- }
-
- Vector nodeRoles = member.getRoles();
- for (int j = 0; j < nodeRoles.size(); j++) {
- String nodeRole = (String)nodeRoles.elementAt(j);
- if (excludeRolesVector.contains(nodeRole)) {
- i.remove();
- continue membersIteration;
- }
- if (!includeRolesVector.isEmpty() &&
- includeRolesVector.contains(nodeRole)) {
- continue membersIteration;
- }
- }
-
- // if this point is reached, none of the member's roles has been
- // included, so we remove it from the list
- if (!includeRolesVector.isEmpty()) {
- i.remove();
- continue membersIteration;
- }
- }
+ return super.doStartTag();
+ }
+
+
+ /**
+ * Called by the JSP Engine when closing this tag.
+ *
+ * @throws JspException not thrown
+ */
+ public int doEndTag()
+ throws JspException {
- setCollection(members);
+ init();
- return super.doStartTag();
+ return super.doEndTag();
}
@@ -202,11 +193,7 @@
public void release() {
super.release();
- depth = null;
- includeRoles = null;
- excludeRoles = null;
- includeTypes = null;
- excludeTypes = null;
+ init();
}
@@ -283,20 +270,34 @@
/**
+ * Initialize state for tag reuse.
+ */
+ private void init() {
+
+ depth = null;
+ includeRoles = null;
+ excludeRoles = null;
+ includeTypes = null;
+ excludeTypes = null;
+ iterator = null;
+ }
+
+
+ /**
* Splits the given string into its tokens, separated by commata, and
- * returns the tokens in a new Vector.
+ * returns the tokens in a immutable Set.
*/
- private static Vector tokenizeString(String values) {
+ private static Set tokenizeString(String values) {
- Vector v = new Vector();
+ Set set = new HashSet();
if (values != null) {
StringTokenizer st = new StringTokenizer(values, ",");
while (st.hasMoreElements()) {
- v.addElement(((String)st.nextElement()).trim());
+ set.add(((String)st.nextElement()).trim());
}
}
- return v;
+ return Collections.unmodifiableSet(set);
}
1.8 +45 -7
jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/IterateLocksTag.java
Index: IterateLocksTag.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/taglib/struts/org/apache/slide/taglib/tag/struts/IterateLocksTag.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- IterateLocksTag.java 31 Jul 2002 13:40:00 -0000 1.7
+++ IterateLocksTag.java 1 Aug 2002 11:49:06 -0000 1.8
@@ -68,6 +68,7 @@
import javax.servlet.jsp.JspException;
import org.apache.slide.taglib.bean.NodeBean;
+import org.apache.slide.taglib.util.Iterators;
import org.apache.struts.taglib.logic.IterateTag;
/**
@@ -91,6 +92,18 @@
protected String depth;
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Default constructor.
+ */
+ public IterateLocksTag() {
+
+ init();
+ }
+
+
// ------------------------------------------------------------ Tag Methods
@@ -123,20 +136,33 @@
}
}
- Vector locks = node.getLocks(depthValue);
- setCollection(locks);
+ setCollection(Iterators.locksIterator(node, depthValue));
return super.doStartTag();
}
/**
+ * Called by the JSP Engine when closing this tag.
+ *
+ * @throws JspException not thrown
+ */
+ public int doEndTag()
+ throws JspException {
+
+ init();
+
+ return super.doEndTag();
+ }
+
+
+ /**
* Releases any resources we may have (or inherit).
*/
public void release() {
super.release();
- depth = null;
+ init();
}
@@ -162,6 +188,18 @@
public void setDepth(String depth) {
this.depth = depth;
+ }
+
+
+ // -------------------------------------------------------- Private Methods
+
+
+ /**
+ * Initialize state for tag reuse.
+ */
+ private void init() {
+
+ depth = null;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>