jstrachan 02/02/15 10:25:07
Modified: jelly TODO.txt build.xml
jelly/src/java/org/apache/commons/jelly/impl TagScript.java
jelly/src/java/org/apache/commons/jelly/tags/core
CoreTagLibrary.java
jelly/src/test/org/apache/commons/jelly/beanshell
TestBeanShellEL.java
Added: jelly/src/java/org/apache/commons/jelly CompilableTag.java
filesystem.attributes
jelly/src/java/org/apache/commons/jelly/tags/core
ChooseTag.java IfTag.java OtherwiseTag.java
WhenTag.java
jelly/src/test/org/apache/commons/jelly example3.jelly
Log:
Added core conditional tags from JSTL with a little example
Revision Changes Path
1.4 +2 -0 jakarta-commons-sandbox/jelly/TODO.txt
Index: TODO.txt
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/TODO.txt,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TODO.txt 12 Feb 2002 21:34:33 -0000 1.3
+++ TODO.txt 15 Feb 2002 18:25:06 -0000 1.4
@@ -25,6 +25,8 @@
* make Ant task to run Jelly
+* add an adapter to run JSP tag libraries inside Jelly when Jelly is used in a
Servlet / JSP environment?
+
* document much more!
* add demo of tag which parses its body at compile time and modifies it.
1.5 +12 -1 jakarta-commons-sandbox/jelly/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- build.xml 13 Feb 2002 17:03:09 -0000 1.4
+++ build.xml 15 Feb 2002 18:25:06 -0000 1.5
@@ -3,7 +3,7 @@
<!--
"Digester" component of the Jakarta Commons Subproject
- $Id: build.xml,v 1.4 2002/02/13 17:03:09 jstrachan Exp $
+ $Id: build.xml,v 1.5 2002/02/15 18:25:06 jstrachan Exp $
-->
@@ -296,6 +296,17 @@
<java classname="org.apache.commons.jelly.Jelly" fork="yes">
<classpath refid="test.classpath"/>
<arg value="src/test/org/apache/commons/jelly/testing123.jelly"/>
+ <arg value="one"/>
+ <arg value="two"/>
+ <arg value="three"/>
+ </java>
+ </target>
+
+ <target name="demo.3" depends="compile"
+ description="Runs demo #3">
+ <java classname="org.apache.commons.jelly.Jelly" fork="yes">
+ <classpath refid="test.classpath"/>
+ <arg value="src/test/org/apache/commons/jelly/example3.jelly"/>
<arg value="one"/>
<arg value="two"/>
<arg value="three"/>
1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/CompilableTag.java
Index: CompilableTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/CompilableTag.java,v
1.1 2002/02/15 18:25:06 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: CompilableTag.java,v 1.1 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly;
import java.io.Writer;
/** <p><code>Compilable</code> represents a Tag that is compilable.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public interface CompilableTag {
/**
* Called by the parser to allow a more tag to create a more efficient
* format of the tag
*/
public void compile() throws Exception;
}
1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/filesystem.attributes
<<Binary file>>
1.4 +9 -5
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
Index: TagScript.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TagScript.java 13 Feb 2002 16:00:39 -0000 1.3
+++ TagScript.java 15 Feb 2002 18:25:06 -0000 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
1.3 2002/02/13 16:00:39 jstrachan Exp $
- * $Revision: 1.3 $
- * $Date: 2002/02/13 16:00:39 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
1.4 2002/02/15 18:25:06 jstrachan Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * $Id: TagScript.java,v 1.3 2002/02/13 16:00:39 jstrachan Exp $
+ * $Id: TagScript.java,v 1.4 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.impl;
@@ -74,6 +74,7 @@
import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.commons.jelly.CompilableTag;
import org.apache.commons.jelly.Context;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.Tag;
@@ -85,7 +86,7 @@
/** <p><code>TagScript</code> evaluates a custom tag.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class TagScript implements Script {
@@ -135,6 +136,9 @@
* Will only be called once by the parser
*/
public Script compile() throws Exception {
+ if ( tag instanceof CompilableTag ) {
+ ((CompilableTag) tag).compile();
+ }
List typeList = new ArrayList();
List methodList = new ArrayList();
List expressionList = new ArrayList();
1.3 +14 -6
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java
Index: CoreTagLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CoreTagLibrary.java 13 Feb 2002 17:03:09 -0000 1.2
+++ CoreTagLibrary.java 15 Feb 2002 18:25:06 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
1.2 2002/02/13 17:03:09 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/13 17:03:09 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
1.3 2002/02/15 18:25:06 jstrachan Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * $Id: CoreTagLibrary.java,v 1.2 2002/02/13 17:03:09 jstrachan Exp $
+ * $Id: CoreTagLibrary.java,v 1.3 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.core;
@@ -76,15 +76,23 @@
/** Describes the Taglib. This class could be generated by XDoclet
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class CoreTagLibrary extends TagLibrary {
public CoreTagLibrary() {
+ registerTag( "jelly", JellyTag.class );
+
+ // core tags
registerTag( "expr", ExprTag.class );
registerTag( "forEach", ForEachTag.class );
- registerTag( "jelly", JellyTag.class );
registerTag( "set", SetTag.class );
+
+ // conditional tags
+ registerTag( "if", IfTag.class );
+ registerTag( "choose", ChooseTag.class );
+ registerTag( "when", WhenTag.class );
+ registerTag( "otherwise", OtherwiseTag.class );
}
public Expression createExpression(ExpressionFactory factory, String tagName,
String attributeName, String attributeValue) throws Exception {
1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ChooseTag.java
Index: ChooseTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ChooseTag.java,v
1.1 2002/02/15 18:25:06 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: ChooseTag.java,v 1.1 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.core;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.jelly.CompilableTag;
import org.apache.commons.jelly.Context;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.impl.ScriptBlock;
import org.apache.commons.jelly.impl.TagScript;
import org.apache.commons.jelly.expression.Expression;
/** A tag which conditionally evaluates its body based on some condition
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class ChooseTag extends TagSupport implements CompilableTag {
private TagScript[] whenTags;
private TagScript otherwiseTag;
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 run(Context context, Writer writer) throws Exception {
for ( int i = 0, size = whenTags.length; i < size; i++ ) {
TagScript script = whenTags[i];
script.run( context, writer );
WhenTag tag = (WhenTag) script.getTag();
if ( tag.getValue() ) {
return;
}
}
if ( otherwiseTag != null ) {
otherwiseTag.run( context, writer );
}
}
}
1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java
Index: IfTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v
1.1 2002/02/15 18:25:06 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: IfTag.java,v 1.1 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.core;
import java.io.IOException;
import java.io.Writer;
import org.apache.commons.jelly.Context;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
/** A tag which conditionally evaluates its body based on some condition
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class IfTag extends TagSupport {
/** The expression to evaluate. */
private Expression test;
public IfTag() {
}
// Tag interface
//-------------------------------------------------------------------------
public void run(Context context, Writer writer) throws Exception {
if ( test != null ) {
if ( test.evaluateAsBoolean( context ) ) {
getBody().run( context, writer );
}
}
}
// Properties
//-------------------------------------------------------------------------
/** Sets the XPath expression to evaluate. */
public void setTest(Expression test) {
this.test = test;
}
}
1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/OtherwiseTag.java
Index: OtherwiseTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/OtherwiseTag.java,v
1.1 2002/02/15 18:25:06 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: OtherwiseTag.java,v 1.1 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.core;
import java.io.IOException;
import java.io.Writer;
import org.apache.commons.jelly.Context;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
/** The otherwise block of a choose/when/otherwise group of tags
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class OtherwiseTag extends TagSupport {
public OtherwiseTag() {
}
// Tag interface
//-------------------------------------------------------------------------
public void run(Context context, Writer writer) throws Exception {
getBody().run( context, writer );
}
}
1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/WhenTag.java
Index: WhenTag.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/WhenTag.java,v
1.1 2002/02/15 18:25:06 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: WhenTag.java,v 1.1 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.core;
import java.io.IOException;
import java.io.Writer;
import org.apache.commons.jelly.Context;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.expression.Expression;
/** A tag which conditionally evaluates its body based on some condition
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class WhenTag extends TagSupport {
/** 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 run(Context context, Writer writer) throws Exception {
value = false;
if ( test != null ) {
if ( test.evaluateAsBoolean( context ) ) {
value = true;
getBody().run( context, writer );
}
}
}
// Properties
//-------------------------------------------------------------------------
/** Sets the XPath expression to evaluate. */
public void setTest(Expression test) {
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.1
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example3.jelly
Index: example3.jelly
===================================================================
<?xml version="1.0"?>
<jelly xmlns="jelly:core">
<!-- a really silly way to do this but -->
<!-- this should test the choose/when/otherwise tags -->
<forEach var="iter" items="System.getProperties()">
<choose>
<when test='iter.key.equals( "java.home" )'>
Java Home = <expr value="iter.value"/>
</when>
<when test='iter.key.equals( "java.version" )'>
Java Version = <expr value="iter.value"/>
</when>
<otherwise>
<expr value="iter.key"/> = <expr value="iter.value"/>
</otherwise>
</choose>
</forEach>
</jelly>
1.3 +9 -5
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java
Index: TestBeanShellEL.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestBeanShellEL.java 13 Feb 2002 17:03:09 -0000 1.2
+++ TestBeanShellEL.java 15 Feb 2002 18:25:06 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v
1.2 2002/02/13 17:03:09 jstrachan Exp $
- * $Revision: 1.2 $
- * $Date: 2002/02/13 17:03:09 $
+ * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v
1.3 2002/02/15 18:25:06 jstrachan Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/02/15 18:25:06 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * $Id: TestBeanShellEL.java,v 1.2 2002/02/13 17:03:09 jstrachan Exp $
+ * $Id: TestBeanShellEL.java,v 1.3 2002/02/15 18:25:06 jstrachan Exp $
*/
package org.apache.commons.jelly.beanshell;
@@ -78,7 +78,7 @@
/** Tests the BeanShell EL
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class TestBeanShellEL extends TestCase {
@@ -114,6 +114,10 @@
public void testEL() throws Exception {
assertExpression( "foo", "abc" );
assertExpression( "bar * 2", new Integer( 246 ) );
+ assertExpression( "bar == 123", Boolean.TRUE );
+ assertExpression( "bar == 124", Boolean.FALSE );
+ assertExpression( "foo.equals( \"abc\" )", Boolean.TRUE );
+ assertExpression( "foo.equals( \"xyz\" )", Boolean.FALSE );
}
/** Evaluates the given expression text and tests it against the expected value
*/
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>