Return-Path:
Delivered-To: apmail-jakarta-commons-dev-archive@apache.org
Received: (qmail 9535 invoked from network); 6 Jun 2002 07:13:52 -0000
Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131)
by daedalus.apache.org with SMTP; 6 Jun 2002 07:13:52 -0000
Received: (qmail 7041 invoked by uid 97); 6 Jun 2002 07:14:00 -0000
Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org
Received: (qmail 6984 invoked by uid 97); 6 Jun 2002 07:13:59 -0000
Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe:
List-Subscribe:
List-Help:
List-Post:
List-Id: "Jakarta Commons Developers List"
Reply-To: "Jakarta Commons Developers List"
Delivered-To: mailing list commons-dev@jakarta.apache.org
Received: (qmail 6970 invoked by uid 97); 6 Jun 2002 07:13:58 -0000
X-Antivirus: nagoya (v4198 created Apr 24 2002)
Date: 6 Jun 2002 07:13:41 -0000
Message-ID: <20020606071341.50386.qmail@icarus.apache.org>
From: jstrachan@apache.org
To: jakarta-commons-sandbox-cvs@apache.org
Subject: cvs commit: jakarta-commons-sandbox/jelly build.xml
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
jstrachan 2002/06/06 00:13:41
Modified: jelly/src/java/org/apache/commons/jelly/parser
XMLParser.java
jelly/src/java/org/apache/commons/jelly TagLibrary.java
JellyContext.java
jelly/src/java/org/apache/commons/jelly/expression/jexl
JexlExpressionFactory.java
jelly build.xml
Added: jelly/src/test/org/apache/commons/jelly/expression
TestExpressions.java
jelly/src/java/org/apache/commons/jelly/expression
CompositeExpression.java
Log:
Added support for composite expressions in attribute values so that tags can be used as
Along with test cases to check this works. Ultimately it might makes sense to push this down into Jexl. Currently there's no support for $ escaping like Velocity, so $${foo} won't escape the $.
Revision Changes Path
1.20 +9 -9 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
Index: XMLParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- XMLParser.java 30 May 2002 14:27:07 -0000 1.19
+++ XMLParser.java 6 Jun 2002 07:13:41 -0000 1.20
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.19 2002/05/30 14:27:07 jstrachan Exp $
- * $Revision: 1.19 $
- * $Date: 2002/05/30 14:27:07 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.20 2002/06/06 07:13:41 jstrachan Exp $
+ * $Revision: 1.20 $
+ * $Date: 2002/06/06 07:13:41 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* .
*
- * $Id: XMLParser.java,v 1.19 2002/05/30 14:27:07 jstrachan Exp $
+ * $Id: XMLParser.java,v 1.20 2002/06/06 07:13:41 jstrachan Exp $
*/
package org.apache.commons.jelly.parser;
import java.io.File;
@@ -87,6 +87,7 @@
import org.apache.commons.jelly.impl.DynaTagScript;
import org.apache.commons.jelly.impl.TagScript;
import org.apache.commons.jelly.impl.TextScript;
+import org.apache.commons.jelly.expression.CompositeExpression;
import org.apache.commons.jelly.expression.ConstantExpression;
import org.apache.commons.jelly.expression.Expression;
import org.apache.commons.jelly.expression.ExpressionFactory;
@@ -109,7 +110,7 @@
* The SAXParser and XMLReader portions of this code come from Digester.
*
* @author James Strachan
- * @version $Revision: 1.19 $
+ * @version $Revision: 1.20 $
*/
public class XMLParser extends DefaultHandler {
@@ -985,10 +986,9 @@
for (int i = 0; i < size; i++) {
String attributeName = list.getLocalName(i);
String attributeValue = list.getValue(i);
- Expression expression = getExpressionFactory().createExpression(attributeValue);
- if (expression == null) {
- expression = createConstantExpression(localName, attributeName, attributeValue);
- }
+ Expression expression = CompositeExpression.parse(
+ attributeValue, getExpressionFactory()
+ );
script.addAttribute(attributeName, expression);
}
return script;
1.10 +11 -8 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java
Index: TagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TagLibrary.java 30 May 2002 08:11:55 -0000 1.9
+++ TagLibrary.java 6 Jun 2002 07:13:41 -0000 1.10
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v 1.9 2002/05/30 08:11:55 jstrachan Exp $
- * $Revision: 1.9 $
- * $Date: 2002/05/30 08:11:55 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v 1.10 2002/06/06 07:13:41 jstrachan Exp $
+ * $Revision: 1.10 $
+ * $Date: 2002/06/06 07:13:41 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* .
*
- * $Id: TagLibrary.java,v 1.9 2002/05/30 08:11:55 jstrachan Exp $
+ * $Id: TagLibrary.java,v 1.10 2002/06/06 07:13:41 jstrachan Exp $
*/
package org.apache.commons.jelly;
@@ -65,6 +65,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.jelly.expression.CompositeExpression;
+import org.apache.commons.jelly.expression.ConstantExpression;
import org.apache.commons.jelly.expression.Expression;
import org.apache.commons.jelly.expression.ExpressionFactory;
import org.apache.commons.jelly.impl.TagScript;
@@ -74,7 +76,7 @@
/** Taglib
represents the metadata for a Jelly custom tag library.
*
* @author James Strachan
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public abstract class TagLibrary {
@@ -111,10 +113,11 @@
myFactory = factory;
}
if (myFactory != null) {
- return myFactory.createExpression(attributeValue);
+ return CompositeExpression.parse(attributeValue, myFactory);
}
- // will use the default expression instead
- return null;
+
+ // will use a constant expression instead
+ return new ConstantExpression(attributeValue);;
}
1.10 +3 -1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
Index: JellyContext.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- JellyContext.java 5 Jun 2002 07:00:58 -0000 1.9
+++ JellyContext.java 6 Jun 2002 07:13:41 -0000 1.10
@@ -560,7 +560,9 @@
else {
urlText = rootURL.toString() + relativeURI;
}
- log.info("Attempting to open url: " + urlText);
+ if ( log.isDebugEnabled() ) {
+ log.debug("Attempting to open url: " + urlText);
+ }
return new URL(urlText);
}
1.5 +8 -22 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpressionFactory.java
Index: JexlExpressionFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpressionFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JexlExpressionFactory.java 17 May 2002 15:18:14 -0000 1.4
+++ JexlExpressionFactory.java 6 Jun 2002 07:13:41 -0000 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpressionFactory.java,v 1.4 2002/05/17 15:18:14 jstrachan Exp $
- * $Revision: 1.4 $
- * $Date: 2002/05/17 15:18:14 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpressionFactory.java,v 1.5 2002/06/06 07:13:41 jstrachan Exp $
+ * $Revision: 1.5 $
+ * $Date: 2002/06/06 07:13:41 $
*
* ====================================================================
*
@@ -57,13 +57,12 @@
* information on the Apache Software Foundation, please see
* .
*
- * $Id: JexlExpressionFactory.java,v 1.4 2002/05/17 15:18:14 jstrachan Exp $
+ * $Id: JexlExpressionFactory.java,v 1.5 2002/06/06 07:13:41 jstrachan Exp $
*/
package org.apache.commons.jelly.expression.jexl;
import org.apache.commons.jelly.expression.Expression;
-
import org.apache.commons.jelly.expression.ExpressionFactory;
/**
@@ -71,30 +70,17 @@
* expression which fully supports the Expression Language in JSTL and JSP.
*
* @author James Strachan
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class JexlExpressionFactory implements ExpressionFactory {
// ExpressionFactory interface
-
//-------------------------------------------------------------------------
-
public Expression createExpression(String text) throws Exception {
-
- int length = text.length();
-
- if (length > 3 && text.startsWith("${") && text.charAt(length - 1) == '}') {
-
- text = text.substring(2, length - 1);
-
- return new JexlExpression(
- org.apache.commons.jexl.ExpressionFactory.createExpression(text));
-
- }
-
- return null;
-
+ return new JexlExpression(
+ org.apache.commons.jexl.ExpressionFactory.createExpression(text)
+ );
}
}
1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/expression/TestExpressions.java
Index: TestExpressions.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestCoreTags.java,v 1.8 2002/05/28 07:20:06 jstrachan Exp $
* $Revision: 1.8 $
* $Date: 2002/05/28 07:20: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 apache@apache.org.
*
* 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
* .
*
* $Id: TestCoreTags.java,v 1.8 2002/05/28 07:20:06 jstrachan Exp $
*/
package org.apache.commons.jelly.expression;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Tests the use of Expression parsing
*
* @author James Strachan
* @version $Revision: 1.8 $
*/
public class TestExpressions extends TestCase {
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(TestExpressions.class);
protected JellyContext context = new JellyContext();
protected ExpressionFactory factory = new JexlExpressionFactory();
public static void main(String[] args) {
TestRunner.run(suite());
}
public static Test suite() {
return new TestSuite(TestExpressions.class);
}
public TestExpressions(String testName) {
super(testName);
}
public void testExpresssions() throws Exception {
context.setVariable("topping", "cheese");
context.setVariable("type", "deepPan");
assertExpression("foo", "foo");
assertExpression("${topping}", "cheese");
assertExpression("some${topping}", "somecheese");
assertExpression("${topping}y", "cheesey");
assertExpression("A ${topping} ${type} pizza", "A cheese deepPan pizza");
assertExpression("${topping}-${type}", "cheese-deepPan");
}
protected void assertExpression(String expressionText, Object expectedValue) throws Exception {
Expression expression = CompositeExpression.parse(expressionText, factory);
assertTrue( "Created a valid expression for: " + expressionText, expression != null );
Object value = expression.evaluate(context);
//assertEquals( "Expression for: " + expressionText + " is: " + expression, expectedValue, value );
assertEquals( "Wrong result for expression: " + expressionText, expectedValue, value );
}
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/CompositeExpression.java
Index: CompositeExpression.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ConstantExpression.java,v 1.4 2002/05/17 15:18:15 jstrachan Exp $
* $Revision: 1.4 $
* $Date: 2002/05/17 15:18:15 $
*
* ====================================================================
*
* 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 apache@apache.org.
*
* 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
* .
*
* $Id: ConstantExpression.java,v 1.4 2002/05/17 15:18:15 jstrachan Exp $
*/
package org.apache.commons.jelly.expression;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.SingletonIterator;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyException;
/**
* CompositeExpression
is a Composite expression made up of several
* Expression objects which are concatenated into a single String.
*
* @author James Strachan
* @version $Revision: 1.4 $
*/
public class CompositeExpression extends ExpressionSupport {
/** The expressions */
private List expressions;
public CompositeExpression() {
this.expressions = new ArrayList();
}
public CompositeExpression(List expressions) {
this.expressions = expressions;
}
public String toString() {
return super.toString() + "[expressions=" + expressions +"]";
}
/**
* Parses the given String to be either a ConstantExpresssion, an Expression denoted as
* "${foo}" or some String with embedded expresssions such as "abc${something}def${else}xyz"
* which results in a CompositeExpression being returned.
*
* @param text is the String to parse into expressions
* @param factory is the Factory of Expression objects used to create expresssions for the contents
* of the String "foo" inside expressions such as "${foo}"
*
* @return the Expresssion for the given String.
* @throws JellyException if the text is invalid (such as missing '}' character).
* @throws Exception if there was some problem creating the underlying Expression object
* from the ExpressionFactory
*/
public static Expression parse(String text, ExpressionFactory factory) throws Exception {
int length = text.length();
int startIndex = text.indexOf( "${" );
if (startIndex < 0 ) {
return new ConstantExpression(text);
}
int endIndex = text.indexOf( "}", startIndex+2 );
if ( endIndex < 0 ) {
throw new JellyException( "Missing '}' character at the end of expression: " + text );
}
if ( startIndex == 0 && endIndex == length - 1 ) {
return factory.createExpression(text.substring(2, endIndex));
}
else {
CompositeExpression answer = new CompositeExpression();
if ( startIndex > 0 ) {
String prefix = text.substring(0, startIndex);
answer.addTextExpression(prefix);
}
String middle = text.substring(startIndex+2, endIndex);
answer.addExpression(factory.createExpression(middle));
// now lets iterate through the rest of the string.
while (++endIndex < length) {
startIndex = text.indexOf( "${", endIndex );
if ( startIndex < 0 ) {
String postfix = text.substring(endIndex);
answer.addTextExpression(postfix);
break;
}
// add text in between expresssions
if (startIndex > endIndex ) {
answer.addTextExpression(text.substring(endIndex, startIndex));
}
endIndex = text.indexOf( "}", startIndex+2 );
if ( endIndex < 0 ) {
throw new JellyException( "Missing '}' character at the end of expression: " + text );
}
middle = text.substring(startIndex+2, endIndex);
answer.addExpression(factory.createExpression(middle));
}
return answer;
}
}
// Properties
//-------------------------------------------------------------------------
/**
* @return the Expression objects that make up this
* composite expression
*/
public List getExpressions() {
return expressions;
}
/**
* Sets the Expression objects that make up this
* composite expression
*/
public void setExpressions(List expressions) {
this.expressions = expressions;
}
/**
* Adds a new expression to the end of the expression list
*/
public void addExpression(Expression expression) {
expressions.add(expression);
}
/**
* A helper method to add a new constant text expression
*/
public void addTextExpression(String text) {
addExpression(new ConstantExpression(text));
}
// Expression interface
//-------------------------------------------------------------------------
// inherit javadoc from interface
public Object evaluate(JellyContext context) {
return evaluateAsString(context);
}
// inherit javadoc from interface
public String evaluateAsString(JellyContext context) {
StringBuffer buffer = new StringBuffer();
for (Iterator iter = expressions.iterator(); iter.hasNext(); ) {
Expression expression = (Expression) iter.next();
String value = expression.evaluateAsString(context);
if ( value != null ) {
buffer.append( value );
}
}
return buffer.toString();
}
// inherit javadoc from interface
public Iterator evaluateAsIterator(JellyContext context) {
String value = evaluateAsString(context);
if ( value == null ) {
return Collections.EMPTY_LIST.iterator();
}
else {
return new SingletonIterator( value );
}
}
}
1.36 +10 -0 jakarta-commons-sandbox/jelly/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- build.xml 4 Jun 2002 18:34:33 -0000 1.35
+++ build.xml 6 Jun 2002 07:13:41 -0000 1.36
@@ -202,7 +202,17 @@
+
+
+
+
+
+
+
+
+
--
To unsubscribe, e-mail:
For additional commands, e-mail: