You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Stratton, Jason" <Ja...@us.ing.com> on 2003/09/09 19:16:19 UTC
Merging Velocity Output w/ Existing File
Hi All,
I have been using Velocity to generate files and it has been working quite well for me. Thank you.
Now I have been asked to look at the ability to merge the output from Velocity with the existing files. To clarify, when my tool is run once and the files have been generated, the user will potentially change the files and we do not want to lose the changes when Velocity is run again. Right now the Velocity output overwrites the files. It is understood that only the static content in the files can possibly be preserved.
My questions are:
- Is this possible/practical with Velocity?
- If not, is there another technology that I should investigate?
Thank you very much.
Jason
Re: Merging Velocity Output w/ Existing File
Posted by Dave Newton <da...@solaraccess.com>.
On Tue, 2003-09-09 at 13:16, Stratton, Jason wrote:
> Now I have been asked to look at the ability to merge the output
> from Velocity with the existing files. To clarify, when my tool
> is run once and the files have been generated, the user will
> potentially change the files and we do not want to lose the changes
> when Velocity is run again. Right now the Velocity output overwrites
> the files. It is understood that only the static content in the files
> can possibly be preserved.
I'm not sure what you mean.
If there are chunks in the output file that a user can change and then
you want to run velocity but not lose those changes then maybe you
should consider a two-step velocity process so that the velocity chunks
are inserted into a different template; the one the user can change.
I use this technique in a few places, for instance, I create a dynamic
email which is then merged with the mailing list (so the first velocity
run is actually creating a velocity template that is used in the
mailmerge)
Dave
Re: Merging Velocity Output w/ Existing File
Posted by Mike Kienenberger <mk...@alaska.net>.
"Stratton, Jason" <Ja...@us.ing.com> wrote:
> Hi All,
>
> I have been using Velocity to generate files and it has been working quite
well for me. Thank you.
>
> Now I have been asked to look at the ability to merge the output from
Velocity with the existing files. To clarify, when my tool is run once and
the files have been generated, the user will potentially change the files
and we do not want to lose the changes when Velocity is run again. Right now
the Velocity output overwrites the files. It is understood that only the
static content in the files can possibly be preserved.
>
> My questions are:
> - Is this possible/practical with Velocity?
> - If not, is there another technology that I should investigate?
>
> Thank you very much.
> Jason
It depends on the details.
If you're generating java code, you can generate things in a "Gap
Generation" design patern
public class GENERATED_SUPERCLASS // generated by Velocity every time.
{
}
public class MY_CLASS extends GENERATED_SUPERCLASS // generated by Velocity
only if it doesn't exist
{
}
Other possiblities including using #include to include the static content.
Idealistically, your users should be changing the templates, not the
generated files....
Of course, it may not be possible in your environment, but if that's the
case, no template engine will probably be any better.
-Mike