You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Olle Hallin <ol...@hit.se> on 2002/04/17 19:56:20 UTC

Has anyone used Velocity for generating RTF documents?

Hello,

I'm currently building a product configurator.

The configurator lets the user specify a product by selecting mandatory and optional components, properties, discounts
and so on.

The configurator shall then calculate the price and generate an agreement document.

Since we have very little time we plan to reuse as much as possible from todays solution which is a Word macro package plus a set
of Word templates.

My idea is to keep the boiler plate parts of the Word templates and generate the agreement body in form of an RTF file which is inserted
into the Word template at the proper position by a tiny VBA procedure.

Now to the question: is it feasible to use Velocity for generating RTF?

Or to be more precise: are there any clashes between VTL and RTF?
I mean, usage of '#', '$' an so on.

Regards,
Olle Hallin






--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Has anyone used Velocity for generating RTF documents?

Posted by Simon Christian <si...@cpd.co.uk>.
>
> Sven, Simon :
>
> Can we get an example doc and some notes to include with the code?
>

Without wanting to step on Sven's toes, I'll be happy to make up an example
app, doc and notes for it, and take a look at the configuration issues.

- simon


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Has anyone used Velocity for generating RTF documents?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/19/02 6:10 AM, "Simon Christian" <si...@cpd.co.uk> wrote:

> Sorry something of an oversight there: the problem detailed below only
> occurs when the #set( $a = "foo" ) line is included as the document title -
> something Word will do automatically if you don't set an alternative.
> 
> To get around it, just ensure the document summary (in File -> Properties)
> does not include any quotes.

Sven, Simon : 

Can we get an example doc and some notes to include with the code?


> 
> - simon
> 
>> 
>> 
>> Nice one Sven that's a great tool.
>> 
>> One thing to note: it does require Velocity 1.3 or a minor modification to
>> run, specifically because it's using
>> org.apache.velocity.runtime.log.SimpleLog4JLogSystem as the
>> RUNTIME_LOG_LOGSYSTEM_CLASS.
>> 
>> It seems to work very nicely for basic data-merge functions, but
>> as soon as
>> I try to do much testing the parser fails. For instance if I have the
>> following in my input.rtf file:
>> 
>> 
>> #set( $a = "foo" )
>> #set( $b = "bar" )
>> 
>> #if( $a == $b ) foo is bar #else foo is not bar #end
>> 
>> I get the following error when attempting to merge it:
>> 
>> Exception in thread "main"
>> org.apache.velocity.exception.ParseErrorException: Lexical error:
>> org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1,
>> column 1518.  Encountered: "\'" (39), after : "\\"
>> 
>> 
>> This is certainly because of the conversions Word makes when
>> saving out the
>> .rtf file, e.g.
>> 
>> #set( $a = "foo" )
>> 
>> becomes
>> 
>> #set( $a = \'93foo\'94
>> 
>> And putting the contents of the .rtf file onto a single line confirms that
>> column 1518 is the first instance of \'93 in the stream.
>> 
>> It seems a shame that it isn't more capable because of a silly thing like
>> that - I'll try to find time myself to tackle that issue, if you have no
>> objections?
>> 
>> - simon
>> 
>>> -----Original Message-----
>>> From: Sven Meier [mailto:sven@meiers.net]
>>> Sent: 18 April 2002 21:02
>>> To: Velocity Users List
>>> Subject: Re: Has anyone used Velocity for generating RTF documents?
>>> 
>>> 
>>> Hi,
>>> 
>>> here's my class RTFTemplate. I hope you can use it:
>>> 
>>> 
>>> Comments appreciated
>>> 
>>> Sven
>>> 
>>> ----- Original Message -----
>>> From: Geir Magnusson Jr. <ge...@optonline.net>
>>> To: <ve...@jakarta.apache.org>
>>> Sent: Wednesday, April 17, 2002 10:56 PM
>>> Subject: Re: Has anyone used Velocity for generating RTF documents?
>>> 
>>> 
>>>> On 4/17/02 4:42 PM, "Sven Meier" <sv...@meiers.net> wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> I'm using velocity with RTF-templates and it works great.
>>>>> 
>>>>> There are some problems, but they can be solved:
>>>>> - you cannot use explicit notation with braces { }
>>>>> - you have to filter new lines \r\n from the template, because they
>>> appear
>>>>> arbitrarily in RTF without meaning but can disturb velocity, e.g.
>>>>> $\r\n\product.name
>>>>> 
>>>>> I you want I will send you the source of my java class. It
>>> additionally
>>>>> solves:
>>>>> - trimming of repeated whitespace after the template is merged
>>>>> - translating new lines \n that are inserted during merge
>> to their RTF
>>>>> representation \\line.
>>>>> - setting NULL values to the context
>>>> 
>>>> That would make a great contribution if you are interested in
>>> contributing
>>>> that class and and example on how to use it.  We would put it in the
>>> contrib
>>>> section and make sure people could find it from the website.
>>>> 
>>>> If you are interested, please be sure that you are able to
>>> contribute the
>>>> code freely w/o any problems from employer, etc, place a copy of the
>>> Apache
>>>> Software License at the top of the code, and submit to the list.
>>>> 
>>>> If you don't wish to, that is ok as well.
>>>> 
>>>> Geir
>>>> 
>>>> --
>>>> Geir Magnusson Jr.
>>> geirm@optonline.net
>>>> System and Software Consulting
>>>> Be a giant.  Take giant steps.  Do giant things...
>>>> 
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>> <ma...@jakarta.apache.org>
>>>> For additional commands, e-mail:
>>> <ma...@jakarta.apache.org>
>>>> 
>>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                       geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Has anyone used Velocity for generating RTF documents?

Posted by Simon Christian <si...@cpd.co.uk>.
Sorry something of an oversight there: the problem detailed below only
occurs when the #set( $a = "foo" ) line is included as the document title -
something Word will do automatically if you don't set an alternative.

To get around it, just ensure the document summary (in File -> Properties)
does not include any quotes.

- simon

>
>
> Nice one Sven that's a great tool.
>
> One thing to note: it does require Velocity 1.3 or a minor modification to
> run, specifically because it's using
> org.apache.velocity.runtime.log.SimpleLog4JLogSystem as the
> RUNTIME_LOG_LOGSYSTEM_CLASS.
>
> It seems to work very nicely for basic data-merge functions, but
> as soon as
> I try to do much testing the parser fails. For instance if I have the
> following in my input.rtf file:
>
>
> #set( $a = "foo" )
> #set( $b = "bar" )
>
> #if( $a == $b ) foo is bar #else foo is not bar #end
>
> I get the following error when attempting to merge it:
>
> Exception in thread "main"
> org.apache.velocity.exception.ParseErrorException: Lexical error:
> org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1,
> column 1518.  Encountered: "\'" (39), after : "\\"
>
>
> This is certainly because of the conversions Word makes when
> saving out the
> .rtf file, e.g.
>
> 	#set( $a = "foo" )
>
> becomes
>
> 	#set( $a = \'93foo\'94
>
> And putting the contents of the .rtf file onto a single line confirms that
> column 1518 is the first instance of \'93 in the stream.
>
> It seems a shame that it isn't more capable because of a silly thing like
> that - I'll try to find time myself to tackle that issue, if you have no
> objections?
>
> - simon
>
> > -----Original Message-----
> > From: Sven Meier [mailto:sven@meiers.net]
> > Sent: 18 April 2002 21:02
> > To: Velocity Users List
> > Subject: Re: Has anyone used Velocity for generating RTF documents?
> >
> >
> > Hi,
> >
> > here's my class RTFTemplate. I hope you can use it:
> >
> >
> > Comments appreciated
> >
> > Sven
> >
> > ----- Original Message -----
> > From: Geir Magnusson Jr. <ge...@optonline.net>
> > To: <ve...@jakarta.apache.org>
> > Sent: Wednesday, April 17, 2002 10:56 PM
> > Subject: Re: Has anyone used Velocity for generating RTF documents?
> >
> >
> > > On 4/17/02 4:42 PM, "Sven Meier" <sv...@meiers.net> wrote:
> > >
> > > > Hi,
> > > >
> > > > I'm using velocity with RTF-templates and it works great.
> > > >
> > > > There are some problems, but they can be solved:
> > > > - you cannot use explicit notation with braces { }
> > > > - you have to filter new lines \r\n from the template, because they
> > appear
> > > > arbitrarily in RTF without meaning but can disturb velocity, e.g.
> > > > $\r\n\product.name
> > > >
> > > > I you want I will send you the source of my java class. It
> > additionally
> > > > solves:
> > > > - trimming of repeated whitespace after the template is merged
> > > > - translating new lines \n that are inserted during merge
> to their RTF
> > > > representation \\line.
> > > > - setting NULL values to the context
> > >
> > > That would make a great contribution if you are interested in
> > contributing
> > > that class and and example on how to use it.  We would put it in the
> > contrib
> > > section and make sure people could find it from the website.
> > >
> > > If you are interested, please be sure that you are able to
> > contribute the
> > > code freely w/o any problems from employer, etc, place a copy of the
> > Apache
> > > Software License at the top of the code, and submit to the list.
> > >
> > > If you don't wish to, that is ok as well.
> > >
> > > Geir
> > >
> > > --
> > > Geir Magnusson Jr.
> > geirm@optonline.net
> > > System and Software Consulting
> > > Be a giant.  Take giant steps.  Do giant things...
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Has anyone used Velocity for generating RTF documents?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/19/02 6:04 AM, "Simon Christian" <si...@cpd.co.uk> wrote:

> Nice one Sven that's a great tool.
> 
> One thing to note: it does require Velocity 1.3 or a minor modification to
> run, specifically because it's using
> org.apache.velocity.runtime.log.SimpleLog4JLogSystem as the
> RUNTIME_LOG_LOGSYSTEM_CLASS.

That is a nice tool - maybe Sven (or someone) could make the vel
configuration configurable?

> 
> It seems to work very nicely for basic data-merge functions, but as soon as
> I try to do much testing the parser fails. For instance if I have the
> following in my input.rtf file:
> 
> 
> #set( $a = "foo" )
> #set( $b = "bar" )
> 
> #if( $a == $b ) foo is bar #else foo is not bar #end
> 
> I get the following error when attempting to merge it:
> 
> Exception in thread "main"
> org.apache.velocity.exception.ParseErrorException: Lexical error:
> org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1,
> column 1518.  Encountered: "\'" (39), after : "\\"
> 
> 
> This is certainly because of the conversions Word makes when saving out the
> .rtf file, e.g.
> 
> #set( $a = "foo" )
> 
> becomes
> 
> #set( $a = \'93foo\'94
> 
> And putting the contents of the .rtf file onto a single line confirms that
> column 1518 is the first instance of \'93 in the stream.

And sorry, we aren't going to accept that in the parser :)
 
> It seems a shame that it isn't more capable because of a silly thing like
> that - I'll try to find time myself to tackle that issue, if you have no
> objections?
> 
> - simon
> 
>> -----Original Message-----
>> From: Sven Meier [mailto:sven@meiers.net]
>> Sent: 18 April 2002 21:02
>> To: Velocity Users List
>> Subject: Re: Has anyone used Velocity for generating RTF documents?
>> 
>> 
>> Hi,
>> 
>> here's my class RTFTemplate. I hope you can use it:
>> 
>> 
>> Comments appreciated
>> 
>> Sven
>> 
>> ----- Original Message -----
>> From: Geir Magnusson Jr. <ge...@optonline.net>
>> To: <ve...@jakarta.apache.org>
>> Sent: Wednesday, April 17, 2002 10:56 PM
>> Subject: Re: Has anyone used Velocity for generating RTF documents?
>> 
>> 
>>> On 4/17/02 4:42 PM, "Sven Meier" <sv...@meiers.net> wrote:
>>> 
>>>> Hi,
>>>> 
>>>> I'm using velocity with RTF-templates and it works great.
>>>> 
>>>> There are some problems, but they can be solved:
>>>> - you cannot use explicit notation with braces { }
>>>> - you have to filter new lines \r\n from the template, because they
>> appear
>>>> arbitrarily in RTF without meaning but can disturb velocity, e.g.
>>>> $\r\n\product.name
>>>> 
>>>> I you want I will send you the source of my java class. It
>> additionally
>>>> solves:
>>>> - trimming of repeated whitespace after the template is merged
>>>> - translating new lines \n that are inserted during merge to their RTF
>>>> representation \\line.
>>>> - setting NULL values to the context
>>> 
>>> That would make a great contribution if you are interested in
>> contributing
>>> that class and and example on how to use it.  We would put it in the
>> contrib
>>> section and make sure people could find it from the website.
>>> 
>>> If you are interested, please be sure that you are able to
>> contribute the
>>> code freely w/o any problems from employer, etc, place a copy of the
>> Apache
>>> Software License at the top of the code, and submit to the list.
>>> 
>>> If you don't wish to, that is ok as well.
>>> 
>>> Geir
>>> 
>>> --
>>> Geir Magnusson Jr.
>> geirm@optonline.net
>>> System and Software Consulting
>>> Be a giant.  Take giant steps.  Do giant things...
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>> 
>> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Be a giant.  Take giant steps.  Do giant things...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Has anyone used Velocity for generating RTF documents?

Posted by Simon Christian <si...@cpd.co.uk>.
Nice one Sven that's a great tool.

One thing to note: it does require Velocity 1.3 or a minor modification to
run, specifically because it's using
org.apache.velocity.runtime.log.SimpleLog4JLogSystem as the
RUNTIME_LOG_LOGSYSTEM_CLASS.

It seems to work very nicely for basic data-merge functions, but as soon as
I try to do much testing the parser fails. For instance if I have the
following in my input.rtf file:


#set( $a = "foo" )
#set( $b = "bar" )

#if( $a == $b ) foo is bar #else foo is not bar #end

I get the following error when attempting to merge it:

Exception in thread "main"
org.apache.velocity.exception.ParseErrorException: Lexical error:
org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1,
column 1518.  Encountered: "\'" (39), after : "\\"


This is certainly because of the conversions Word makes when saving out the
.rtf file, e.g.

	#set( $a = "foo" )

becomes

	#set( $a = \'93foo\'94

And putting the contents of the .rtf file onto a single line confirms that
column 1518 is the first instance of \'93 in the stream.

It seems a shame that it isn't more capable because of a silly thing like
that - I'll try to find time myself to tackle that issue, if you have no
objections?

- simon

> -----Original Message-----
> From: Sven Meier [mailto:sven@meiers.net]
> Sent: 18 April 2002 21:02
> To: Velocity Users List
> Subject: Re: Has anyone used Velocity for generating RTF documents?
>
>
> Hi,
>
> here's my class RTFTemplate. I hope you can use it:
>
>
> Comments appreciated
>
> Sven
>
> ----- Original Message -----
> From: Geir Magnusson Jr. <ge...@optonline.net>
> To: <ve...@jakarta.apache.org>
> Sent: Wednesday, April 17, 2002 10:56 PM
> Subject: Re: Has anyone used Velocity for generating RTF documents?
>
>
> > On 4/17/02 4:42 PM, "Sven Meier" <sv...@meiers.net> wrote:
> >
> > > Hi,
> > >
> > > I'm using velocity with RTF-templates and it works great.
> > >
> > > There are some problems, but they can be solved:
> > > - you cannot use explicit notation with braces { }
> > > - you have to filter new lines \r\n from the template, because they
> appear
> > > arbitrarily in RTF without meaning but can disturb velocity, e.g.
> > > $\r\n\product.name
> > >
> > > I you want I will send you the source of my java class. It
> additionally
> > > solves:
> > > - trimming of repeated whitespace after the template is merged
> > > - translating new lines \n that are inserted during merge to their RTF
> > > representation \\line.
> > > - setting NULL values to the context
> >
> > That would make a great contribution if you are interested in
> contributing
> > that class and and example on how to use it.  We would put it in the
> contrib
> > section and make sure people could find it from the website.
> >
> > If you are interested, please be sure that you are able to
> contribute the
> > code freely w/o any problems from employer, etc, place a copy of the
> Apache
> > Software License at the top of the code, and submit to the list.
> >
> > If you don't wish to, that is ok as well.
> >
> > Geir
> >
> > --
> > Geir Magnusson Jr.
> geirm@optonline.net
> > System and Software Consulting
> > Be a giant.  Take giant steps.  Do giant things...
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Has anyone used Velocity for generating RTF documents?

Posted by Sven Meier <sv...@meiers.net>.
Hi,

here's my class RTFTemplate. I hope you can use it:


Comments appreciated

Sven

----- Original Message -----
From: Geir Magnusson Jr. <ge...@optonline.net>
To: <ve...@jakarta.apache.org>
Sent: Wednesday, April 17, 2002 10:56 PM
Subject: Re: Has anyone used Velocity for generating RTF documents?


> On 4/17/02 4:42 PM, "Sven Meier" <sv...@meiers.net> wrote:
>
> > Hi,
> >
> > I'm using velocity with RTF-templates and it works great.
> >
> > There are some problems, but they can be solved:
> > - you cannot use explicit notation with braces { }
> > - you have to filter new lines \r\n from the template, because they
appear
> > arbitrarily in RTF without meaning but can disturb velocity, e.g.
> > $\r\n\product.name
> >
> > I you want I will send you the source of my java class. It additionally
> > solves:
> > - trimming of repeated whitespace after the template is merged
> > - translating new lines \n that are inserted during merge to their RTF
> > representation \\line.
> > - setting NULL values to the context
>
> That would make a great contribution if you are interested in contributing
> that class and and example on how to use it.  We would put it in the
contrib
> section and make sure people could find it from the website.
>
> If you are interested, please be sure that you are able to contribute the
> code freely w/o any problems from employer, etc, place a copy of the
Apache
> Software License at the top of the code, and submit to the list.
>
> If you don't wish to, that is ok as well.
>
> Geir
>
> --
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> Be a giant.  Take giant steps.  Do giant things...
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

Re: Has anyone used Velocity for generating RTF documents?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/17/02 4:42 PM, "Sven Meier" <sv...@meiers.net> wrote:

> Hi,
> 
> I'm using velocity with RTF-templates and it works great.
> 
> There are some problems, but they can be solved:
> - you cannot use explicit notation with braces { }
> - you have to filter new lines \r\n from the template, because they appear
> arbitrarily in RTF without meaning but can disturb velocity, e.g.
> $\r\n\product.name
> 
> I you want I will send you the source of my java class. It additionally
> solves:
> - trimming of repeated whitespace after the template is merged
> - translating new lines \n that are inserted during merge to their RTF
> representation \\line.
> - setting NULL values to the context

That would make a great contribution if you are interested in contributing
that class and and example on how to use it.  We would put it in the contrib
section and make sure people could find it from the website.

If you are interested, please be sure that you are able to contribute the
code freely w/o any problems from employer, etc, place a copy of the Apache
Software License at the top of the code, and submit to the list.

If you don't wish to, that is ok as well.

Geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Be a giant.  Take giant steps.  Do giant things...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Has anyone used Velocity for generating RTF documents?

Posted by Sven Meier <sv...@meiers.net>.
Hi,

I'm using velocity with RTF-templates and it works great.

There are some problems, but they can be solved:
- you cannot use explicit notation with braces { }
- you have to filter new lines \r\n from the template, because they appear
arbitrarily in RTF without meaning but can disturb velocity, e.g.
$\r\n\product.name

I you want I will send you the source of my java class. It additionally
solves:
- trimming of repeated whitespace after the template is merged
- translating new lines \n that are inserted during merge to their RTF
representation \\line.
- setting NULL values to the context

Sven

----- Original Message -----
From: Olle Hallin <ol...@hit.se>
To: Velocity User <ve...@jakarta.apache.org>
Sent: Wednesday, April 17, 2002 7:56 PM
Subject: Has anyone used Velocity for generating RTF documents?


Hello,

I'm currently building a product configurator.

The configurator lets the user specify a product by selecting mandatory and
optional components, properties, discounts
and so on.

The configurator shall then calculate the price and generate an agreement
document.

Since we have very little time we plan to reuse as much as possible from
todays solution which is a Word macro package plus a set
of Word templates.

My idea is to keep the boiler plate parts of the Word templates and generate
the agreement body in form of an RTF file which is inserted
into the Word template at the proper position by a tiny VBA procedure.

Now to the question: is it feasible to use Velocity for generating RTF?

Or to be more precise: are there any clashes between VTL and RTF?
I mean, usage of '#', '$' an so on.

Regards,
Olle Hallin






--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>