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/05/20 18:39:11 UTC
cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/sql testSql.jelly example2.jelly
jstrachan 02/05/20 09:39:11
Modified: jelly/src/java/org/apache/commons/jelly/impl
BeanTagScript.java
jelly/src/java/org/apache/commons/jelly/tags/core
ForEachTag.java
jelly .cvsignore build.xml
jelly/src/test/org/apache/commons/jelly/sql example2.jelly
Added: jelly/src/test/org/apache/commons/jelly/sql testSql.jelly
Log:
Pached a few errors in the SQL taglibs and ensured that any incorrectly typed attribute name results in an error.
Revision Changes Path
1.5 +21 -5 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java
Index: BeanTagScript.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BeanTagScript.java 17 May 2002 15:18:11 -0000 1.4
+++ BeanTagScript.java 20 May 2002 16:39:11 -0000 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v 1.4 2002/05/17 15:18:11 jstrachan Exp $
- * $Revision: 1.4 $
- * $Date: 2002/05/17 15:18:11 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v 1.5 2002/05/20 16:39:11 jstrachan Exp $
+ * $Revision: 1.5 $
+ * $Date: 2002/05/20 16:39:11 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * $Id: BeanTagScript.java,v 1.4 2002/05/17 15:18:11 jstrachan Exp $
+ * $Id: BeanTagScript.java,v 1.5 2002/05/20 16:39:11 jstrachan Exp $
*/
package org.apache.commons.jelly.impl;
@@ -69,23 +69,29 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.beanutils.ConvertUtils;
+
import org.apache.commons.jelly.CompilableTag;
import org.apache.commons.jelly.JellyContext;
+import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.expression.Expression;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** <p><code>TagScript</code> evaluates a custom tag.</p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class BeanTagScript extends TagScript {
@@ -127,12 +133,14 @@
List expressionList = new ArrayList();
BeanInfo info = Introspector.getBeanInfo(tag.getClass());
PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
+ Set attributeSet = new HashSet();
if (descriptors != null) {
for (int i = 0, size = descriptors.length; i < size; i++) {
PropertyDescriptor descriptor = descriptors[i];
String name = descriptor.getName();
Expression expression = (Expression) attributes.get(name);
if (expression != null) {
+ attributeSet.add( name );
Method writeMethod = descriptor.getWriteMethod();
if (writeMethod != null) {
Class type = descriptor.getPropertyType();
@@ -165,6 +173,14 @@
// compile body
tag.setBody(tag.getBody().compile());
+
+ // now lets check for any attributes that are not used
+ for ( Iterator iter = attributes.keySet().iterator(); iter.hasNext(); ) {
+ String name = (String) iter.next();
+ if ( ! attributeSet.contains( name ) ) {
+ throw new JellyException( "This tag does not understand the attribute '" + name + "'" );
+ }
+ }
return this;
}
1.9 +11 -5 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ForEachTag.java
Index: ForEachTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ForEachTag.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ForEachTag.java 20 May 2002 10:09:28 -0000 1.8
+++ ForEachTag.java 20 May 2002 16:39:11 -0000 1.9
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ForEachTag.java,v 1.8 2002/05/20 10:09:28 jstrachan Exp $
- * $Revision: 1.8 $
- * $Date: 2002/05/20 10:09:28 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ForEachTag.java,v 1.9 2002/05/20 16:39:11 jstrachan Exp $
+ * $Revision: 1.9 $
+ * $Date: 2002/05/20 16:39:11 $
*
* ====================================================================
*
@@ -57,7 +57,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
- * $Id: ForEachTag.java,v 1.8 2002/05/20 10:09:28 jstrachan Exp $
+ * $Id: ForEachTag.java,v 1.9 2002/05/20 16:39:11 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.core;
@@ -68,6 +68,7 @@
import java.util.List;
import org.apache.commons.jelly.JellyContext;
+import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -79,7 +80,7 @@
/** A tag which performs an iteration over the results of an XPath expression
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
public class ForEachTag extends TagSupport {
@@ -140,6 +141,11 @@
context.setVariable(indexVar, new Integer(index));
}
getBody().run(context, output);
+ }
+ }
+ else {
+ if ( end == Integer.MAX_VALUE && begin == 0 ) {
+ throw new MissingAttributeException( "items" );
}
}
}
1.2 +1 -0 jakarta-commons-sandbox/jelly/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- .cvsignore 11 Feb 2002 00:27:40 -0000 1.1
+++ .cvsignore 20 May 2002 16:39:11 -0000 1.2
@@ -1,2 +1,3 @@
build.properties
dist
+target
1.20 +2 -1 jakarta-commons-sandbox/jelly/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- build.xml 20 May 2002 12:43:15 -0000 1.19
+++ build.xml 20 May 2002 16:39:11 -0000 1.20
@@ -2,7 +2,7 @@
<!--
"Jelly" component of the Jakarta Commons Subproject
- $Id: build.xml,v 1.19 2002/05/20 12:43:15 jstrachan Exp $
+ $Id: build.xml,v 1.20 2002/05/20 16:39:11 jstrachan Exp $
-->
<!-- ========== Initialize Properties ===================================== -->
@@ -489,5 +489,6 @@
<jelly file="src/test/org/apache/commons/jelly/sql/example.jelly" output="${build.home}/sqloutput.xml"/>
<jelly file="src/test/org/apache/commons/jelly/sql/example2.jelly" output="${build.home}/sqloutput2.xml"/>
+ <jelly file="src/test/org/apache/commons/jelly/sql/testSql.jelly" output="${build.home}/sqloutput3.xml"/>
</target>
</project>
1.2 +2 -0 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/sql/example2.jelly
Index: example2.jelly
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/sql/example2.jelly,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- example2.jelly 15 May 2002 06:25:50 -0000 1.1
+++ example2.jelly 20 May 2002 16:39:11 -0000 1.2
@@ -8,6 +8,7 @@
<dataSet>
+
<j:forEach var="columnName" items="${results.columnNames}" indexVar="i">
<column><j:expr value="${columnName}"/></column>
</j:forEach>
@@ -18,6 +19,7 @@
</j:forEach>
</row>
</j:forEach>
+
</dataSet>
1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/sql/testSql.jelly
Index: testSql.jelly
===================================================================
<?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns:sql="jelly:sql">
<sql:setDataSource var="db" url="${databaseUrl}" driver="${databaseDriver}" user="${databaseUser}"/>
<sql:query var="results" dataSource="${db}">
select * from <j:expr value="${databaseTable}"/>
</sql:query>
<dataSet>
<size><j:expr value="${results.rowCount}"/></size>
</dataSet>
</j:jelly>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>