You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/08/11 13:44:36 UTC
cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core WhenTag.java OtherwiseTag.java ChooseTag.java
jstrachan 2002/08/11 04:44:36
Modified: jelly/src/java/org/apache/commons/jelly/tags/core
WhenTag.java OtherwiseTag.java ChooseTag.java
Log:
Patched the <choose> tag to work properly with the new Tag-local-per-thread and Script shareable-across-threads model.
Revision Changes Path
1.7 +12 -18 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/WhenTag.java
Index: WhenTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/WhenTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WhenTag.java 26 Jun 2002 09:24:35 -0000 1.6
+++ WhenTag.java 11 Aug 2002 11:44:36 -0000 1.7
@@ -65,6 +65,7 @@
import java.io.Writer;
import org.apache.commons.jelly.JellyContext;
+import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -80,19 +81,19 @@
/** The expression to evaluate. */
private Expression test;
- /** whether this tag evaluated its body after calling run() */
- private boolean value;
-
public WhenTag() {
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
- value = false;
- if ( test != null ) {
+ ChooseTag tag = (ChooseTag) findAncestorWithClass( ChooseTag.class );
+ if ( tag == null ) {
+ throw new JellyException( "This tag must be enclosed inside a <choose> tag" );
+ }
+ if ( ! tag.isBlockEvaluated() && test != null ) {
if ( test.evaluateAsBoolean( context ) ) {
- value = true;
+ tag.setBlockEvaluated(true);
invokeBody(output);
}
}
@@ -106,11 +107,4 @@
this.test = test;
}
- /**
- * @return the last evaluation of this tag. This method is used
- * by the choose tag to determine if this tag evaluated anything.
- */
- public boolean getValue() {
- return value;
- }
}
1.7 +14 -6 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/OtherwiseTag.java
Index: OtherwiseTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/OtherwiseTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- OtherwiseTag.java 26 Jun 2002 09:24:35 -0000 1.6
+++ OtherwiseTag.java 11 Aug 2002 11:44:36 -0000 1.7
@@ -65,6 +65,7 @@
import java.io.Writer;
import org.apache.commons.jelly.JellyContext;
+import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -83,6 +84,13 @@
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
- invokeBody(output);
+ ChooseTag tag = (ChooseTag) findAncestorWithClass( ChooseTag.class );
+ if ( tag == null ) {
+ throw new JellyException( "This tag must be enclosed inside a <choose> tag" );
+ }
+ if ( ! tag.isBlockEvaluated() ) {
+ tag.setBlockEvaluated(true);
+ invokeBody(output);
+ }
}
}
1.6 +17 -60 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ChooseTag.java
Index: ChooseTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ChooseTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ChooseTag.java 17 May 2002 15:18:08 -0000 1.5
+++ ChooseTag.java 11 Aug 2002 11:44:36 -0000 1.6
@@ -67,7 +67,6 @@
import java.util.Iterator;
import java.util.List;
-import org.apache.commons.jelly.CompilableTag;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.Tag;
@@ -82,67 +81,25 @@
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
-public class ChooseTag extends TagSupport implements CompilableTag {
+public class ChooseTag extends TagSupport {
- private TagScript[] whenTags;
- private TagScript otherwiseTag;
+ private boolean blockEvaluated;
public ChooseTag() {
}
- // CompilableTag interface
- //-------------------------------------------------------------------------
- public void compile() throws Exception {
- // extract the When tags and the Other tag script
- // XXX: iterate through the body....
- List whenTagList = new ArrayList();
- otherwiseTag = null;
- Script body = getBody();
- if (body instanceof ScriptBlock) {
- ScriptBlock block = (ScriptBlock) body;
- for (Iterator iter = block.getScriptList().iterator(); iter.hasNext();) {
- Script script = (Script) iter.next();
- if (script instanceof TagScript) {
- TagScript tagScript = (TagScript) script;
- Tag tag = tagScript.getTag();
- if (tag instanceof WhenTag) {
- whenTagList.add(tagScript);
- }
- else if (tag instanceof OtherwiseTag) {
- otherwiseTag = tagScript;
- break;
- }
- }
- }
- }
- else if (body instanceof TagScript) {
- // if only one child tag
- TagScript tagScript = (TagScript) body;
- Tag tag = tagScript.getTag();
- if (tag instanceof WhenTag) {
- whenTagList.add(tagScript);
- }
- else if (tag instanceof OtherwiseTag) {
- otherwiseTag = tagScript;
- }
- }
- whenTags = new TagScript[whenTagList.size()];
- whenTagList.toArray(whenTags);
- }
-
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
- for (int i = 0, size = whenTags.length; i < size; i++) {
- TagScript script = whenTags[i];
- script.run(context, output);
- WhenTag tag = (WhenTag) script.getTag();
- if (tag.getValue()) {
- return;
- }
- }
- if (otherwiseTag != null) {
- otherwiseTag.run(context, output);
- }
+ setBlockEvaluated(false);
+ invokeBody(output);
+ }
+
+ protected boolean isBlockEvaluated() {
+ return blockEvaluated;
+ }
+
+ protected void setBlockEvaluated(boolean blockEvaluated) {
+ this.blockEvaluated = blockEvaluated;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>