You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Derrick Koes <de...@hotmail.com> on 2005/06/13 18:42:25 UTC
extra space at beginning of new line
I am using velocity to build a template of an iCalendar entry. Everything
works great except for the spacing. Velocity.evaluate adds a space at the
beginning of lines which have a carriage return. Can someone tell me how to
avoid this? It's a huge problem for iCalendar aware software.
Template:
#macro(cr
$string)**${formatter.newLine($string)}#end#cr("BEGIN:VCALENDAR")#cr("PRODID:-//SkillSoft
Corporation//EN")#cr("VERSION:2.0")#cr("CALSCALE:GREGORIAN")#cr("METHOD:PUBLISH")#foreach
($sched in
$session.schedule)#cr("BEGIN:VEVENT")#cr("STATUS:CONFIRMED")#set($start =
$date.format("yyyyMMdd''T''HHmmss''Z''",
$sched.startDateUTC))#cr("DTSTART:$start")#set($end =
$date.format("yyyyMMdd''T''HHmmss''Z''",
$sched.endDateUTC))#cr("DTEND:$end")#cr("TRANSP:OPAQUE")#cr("UID:$session.course.number$session.number")#set($stamp
=
$date.get("yyyyMMdd''T''HHmmss''Z''"))#cr("DTSTAMP:$stamp")#cr("LOCATION:#if($session.facility.name)$session.facility.name#end#if($session.classroom.name),
$session.classroom.name#end")#cr("CATEGORIES:APPOINTMENT,EDUCATION")#cr("DESCRIPTION:$session.course.description")#cr("SUMMARY:Session
Number - $session.number
$session.course.name")#cr("PRIORITY:5")#cr("CLASS:PUBLIC")#cr("BEGIN:VALARM")#cr("TRIGGER:-PT15M")#cr("ACTION:DISPLAY")#cr("DESCRIPTION:Reminder")#cr("END:VALARM")#cr("END:VEVENT")#end**END:VCALENDAR
Macro code:
public String newLine(String string) {
StringBuffer output = new StringBuffer(string.trim());
output.append(System.getProperty("line.separator", "\n"));
//output.append('\n');
return output.toString();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
RE: extra space at beginning of new line
Posted by Derrick Koes <de...@hotmail.com>.
This bit
#macro(cr $string)**${formatter.newLine($string)}
should have been
#macro(cr $string) ${formatter.newLine($string)}
and hence the problem solved by removing the space
#macro(cr $string)${formatter.newLine($string)}
>From: "Derrick Koes" <de...@hotmail.com>
>Reply-To: "Velocity Users List" <ve...@jakarta.apache.org>
>To: velocity-user@jakarta.apache.org
>Subject: extra space at beginning of new line
>Date: Mon, 13 Jun 2005 12:42:25 -0400
>
>I am using velocity to build a template of an iCalendar entry. Everything
>works great except for the spacing. Velocity.evaluate adds a space at the
>beginning of lines which have a carriage return. Can someone tell me how
>to avoid this? It's a huge problem for iCalendar aware software.
>
>Template:
>
>#macro(cr
>$string)**${formatter.newLine($string)}#end#cr("BEGIN:VCALENDAR")#cr("PRODID:-//SkillSoft
>Corporation//EN")#cr("VERSION:2.0")#cr("CALSCALE:GREGORIAN")#cr("METHOD:PUBLISH")#foreach
>($sched in
>$session.schedule)#cr("BEGIN:VEVENT")#cr("STATUS:CONFIRMED")#set($start =
>$date.format("yyyyMMdd''T''HHmmss''Z''",
>$sched.startDateUTC))#cr("DTSTART:$start")#set($end =
>$date.format("yyyyMMdd''T''HHmmss''Z''",
>$sched.endDateUTC))#cr("DTEND:$end")#cr("TRANSP:OPAQUE")#cr("UID:$session.course.number$session.number")#set($stamp
>=
>$date.get("yyyyMMdd''T''HHmmss''Z''"))#cr("DTSTAMP:$stamp")#cr("LOCATION:#if($session.facility.name)$session.facility.name#end#if($session.classroom.name),
>$session.classroom.name#end")#cr("CATEGORIES:APPOINTMENT,EDUCATION")#cr("DESCRIPTION:$session.course.description")#cr("SUMMARY:Session
>Number - $session.number
>$session.course.name")#cr("PRIORITY:5")#cr("CLASS:PUBLIC")#cr("BEGIN:VALARM")#cr("TRIGGER:-PT15M")#cr("ACTION:DISPLAY")#cr("DESCRIPTION:Reminder")#cr("END:VALARM")#cr("END:VEVENT")#end**END:VCALENDAR
>
>Macro code:
>
>public String newLine(String string) {
> StringBuffer output = new StringBuffer(string.trim());
> output.append(System.getProperty("line.separator", "\n"));
> //output.append('\n');
> return output.toString();
> }
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org