You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by po...@apache.org on 2005/01/17 23:09:29 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/xml/src/test/org/apache/commons/jelly/tags/xml suite.jelly
polx 2005/01/17 14:09:29
Modified: jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml
SetTag.java
jelly/jelly-tags/xml/src/test/org/apache/commons/jelly/tags/xml
suite.jelly
Log:
Adding an "asString" attribute to <x:set> so that the result can be used,
right away in such things as String manipulations.
paul
Revision Changes Path
1.12 +22 -2 jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
Index: SetTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SetTag.java 9 Sep 2004 15:18:54 -0000 1.11
+++ SetTag.java 17 Jan 2005 22:09:28 -0000 1.12
@@ -24,6 +24,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.dom4j.Node;
+
import org.jaxen.XPath;
import org.jaxen.JaxenException;
@@ -54,7 +56,9 @@
/** Xpath comparator for sorting */
private XPathComparator xpCmp = null;
- private Boolean single=null;
+ private Boolean single = null;
+
+ private Boolean asString = null;
public SetTag() {
@@ -98,6 +102,8 @@
else
value=l.get(0);
}
+ if(asString!=null && asString.booleanValue() && value instanceof Node)
+ value = ((Node) value).getStringValue();
} else { // single == false
if(! (value instanceof List) ) {
List l = null;
@@ -140,6 +146,20 @@
*/
public void setSingle(boolean single) {
this.single = new Boolean(single);
+ }
+
+ /** If set to true, will ensure that the (XPath) text-value
+ * of the selected node is taken instead of the node
+ * itself.
+ * This ensures that, thereafter, string manipulations
+ * can be performed on the result.
+ * Setting this attribute to true will also set the single
+ * attribute to true.
+ */
+ public void setAsString(boolean asString) {
+ if(asString)
+ this.single = new Boolean(asString);
+ this.asString = new Boolean(asString);
}
1.13 +10 -6 jakarta-commons/jelly/jelly-tags/xml/src/test/org/apache/commons/jelly/tags/xml/suite.jelly
Index: suite.jelly
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/xml/src/test/org/apache/commons/jelly/tags/xml/suite.jelly,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- suite.jelly 8 Sep 2004 22:26:33 -0000 1.12
+++ suite.jelly 17 Jan 2005 22:09:28 -0000 1.13
@@ -283,12 +283,12 @@
</test:case>
- <test:case name="testSetSingleNode">
+ <test:case name="testSetSingleNodeAndAsString">
<x:parse var="blopElements">
<root>
<blop>blop1</blop>
- <blip/>
- <blop>blop0</blop></root>
+ <blip/>
+ <blop id="bla">blop0</blop></root>
</x:parse>
<x:set var="blopSingle" select="$blopElements/root/blop" single="true"/>
<!-- should return the second -->
@@ -296,10 +296,14 @@
<test:assert test="${eltClass.isAssignableFrom(blopSingle.getClass())}"/>
<j:set var="blopSingleText"><x:expr select="$blopSingle/text()"/></j:set>
<test:assertEquals actual="${blopSingleText}" expected="blop1"/>
- <!-- check if selecting root/blip returns a list -->
- <x:set var="blip" select="$blopElements/root/blip" single="false"/>
+ <!-- check if selecting root/blip returns a list -->
+ <x:set var="blip" select="$blopElements/root/blip" single="false"/>
<j:invokeStatic var="listClass" className="java.lang.Class" method="forName"><j:arg value="java.util.List"/></j:invokeStatic>
- <test:assert test="${listClass.isAssignableFrom(blip.getClass())}"/>
+ <test:assert test="${listClass.isAssignableFrom(blip.getClass())}"/>
+ <!-- check if selecting blop/@id asString returns a string -->
+ <x:set var="blopId" select="$blopElements/root/blop/@id" asString="true"/>
+ <j:invokeStatic var="stringClass" className="java.lang.Class" method="forName"><j:arg value="java.lang.String"/></j:invokeStatic>
+ <test:assert test="${stringClass.isAssignableFrom(blopId.getClass())}"/>
</test:case>
<test:case name="testEntities">
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org