[ https://issues.apache.org/activemq/browse/SM-489?page=all ]
Ramon Buckland updated SM-489: ------------------------------ Attachment: XalanComponent.patch > XalanComponent (XSLT Transform Component) > ----------------------------------------- > > Key: SM-489 > URL: https://issues.apache.org/activemq/browse/SM-489 > Project: ServiceMix > Issue Type: Improvement > Components: servicemix-components > Affects Versions: 3.0 > Reporter: Ramon Buckland > Priority: Minor > Fix For: 3.0-M3 > > Attachments: XalanComponent.patch > > > In the XalanComponent.setOutProperty (in xsl <jbi:setOutProperty />) > the Object that is set on the JBI as a property is always a String, > ref: > /servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XalanExtension.java:181 > however from XSLT (xpath expressions) we can have a > number() (which is a double) > boolean() (T / F) > string() (ye olde string) > To have a number (Object java.lang.Number) in the JBI property is handy when > we want to > "integrate" with, for eg: the SplitAggregator > which needs the "count" property but String's don't cut it there > as it does a direct "assumed" cast from message.getPropery(name) to Integer > org.apache.servicemix.eip.splitter.count > as an Integer > ref > /servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/SplitAggregator.java:194 > The patch proposes to allow a number to go in if the "xstl" make it a number. > One way this could now be achieved with this patch is via direct casting > using the > xpath function number() > <jbi:setOutProperty > name="org.apache.servicemix.eip.splitter.count" > select="number(123)"/> > -- Proposed Patch-- > Index: XalanExtension.java > =================================================================== > --- XalanExtension.java (revision 421260) > +++ XalanExtension.java (working copy) > @@ -15,6 +15,7 @@ > */ > package org.apache.servicemix.components.xslt; > +import org.apache.commons.lang.math.NumberUtils; > import org.apache.servicemix.components.util.ComponentSupport; > import org.apache.servicemix.components.util.CopyTransformer; > import org.apache.servicemix.components.util.MarshalerSupport; > @@ -179,7 +180,21 @@ > throw new IllegalArgumentException("Must specify a 'select' > attribute to set a property on the output message"); > } > XObject answer = > ExsltDynamic.evaluate(context.getTransformer().getXPathContext().getExpressionContext(), > > xpath); > - String value = answer.str(); > + Object value; > + try { > + if (answer.getType() == XObject.CLASS_NUMBER) { > + value = NumberUtils.createNumber(answer.str()); > + } else if (answer.getType() == XObject.CLASS_BOOLEAN) { > + value = new Boolean(answer.bool()); > + } else { > + // XObject guarantees we are never null. > + value = answer.str(); > + } > + } catch (TransformerException e) { > + value = answer.str(); > + } catch (NumberFormatException e) { > + value = answer.str(); > + } > out.setProperty(name, value); > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira