You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by javamonkey79 <ja...@gmail.com> on 2013/07/23 16:45:14 UTC

padded text and\or static classes in velocity template of velocity component

I am trying to pad some text in a velocity template in the camel component.
To do this, I'd like to use the StringUtils class of apache commons. Per
suggestions from other sources, I've tried this:

public class StringUtilsHelper {
	public void addStringUtilsToExchange( final Exchange exchange ) {
		exchange.setProperty( "StringUtils", new StringUtils() );
		exchange.getIn().setHeader( "StringUtils", new StringUtils() );
	}
}

and in my template:
${exchange.StringUtils.leftPad("foo", 10)}
${in.StringUtils.leftPad("foo", 10)}
I've also tried:
$exchange.StringUtils.leftPad("foo", 10)
$in.StringUtils.leftPad("foo", 10)

When I call this template by calling velocity without camel it works,
something like this:
		Velocity.getTemplate( "string-padding-test.vm" ).merge( new
VelocityContext() {
			{
				put( "StringUtils", StringUtils.class );
			}
		}, stringWriter );

My route is pretty simple, and when I add: $body to the template the objects
in the body do render, so I'm at a loss.

		<route id="my-route">
			<from uri="timer://my-timer?period=24h" />
			<bean ref="dataAcquisition" />
			<bean ref="stringUtilsHelper" />
			<split>
				<simple>${body}</simple>
				<to uri="velocity:template.vm" />
				<to id="sftpOut" uri="ref:sftp-out" />
			</split>
		</route>

I'm willing to use other things, but I'd prefer not to have to write extra
macros in to my template for padding and other formatting, if it came to
that I'd build a decorator class to wrap my objects to be rendered.

Does anyone have any idea why this is not working?



--
View this message in context: http://camel.465427.n5.nabble.com/padded-text-and-or-static-classes-in-velocity-template-of-velocity-component-tp5736136.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: padded text and\or static classes in velocity template of velocity component

Posted by javamonkey79 <ja...@gmail.com>.
This post helped me get it:

http://camel.465427.n5.nabble.com/How-to-use-escape-tool-esc-xml-somestrwithspclchars-in-camel-velocity-template-td5505668.html

This works for me:

in template:
$headers.StringUtils.leftPad("foo", 10)

java:
public class StringUtilsHelper {
	public void addStringUtilsToExchange( final Exchange exchange ) {
		exchange.getIn().setHeader( "StringUtils", new StringUtils() );
	}
}

Spring xml, application context:
<bean ref="stringUtilsHelper" />

<spring:bean id="stringUtilsHelper"
class="mypackagenamehere.StringUtilsHelper" />



--
View this message in context: http://camel.465427.n5.nabble.com/padded-text-and-or-static-classes-in-velocity-template-of-velocity-component-tp5736136p5736147.html
Sent from the Camel - Users mailing list archive at Nabble.com.