|
From: David K. <dav...@al...> - 2003-10-09 15:52:59
|
Hi people,
When mucking around with Velocity templates for sending mails
to various people depending on the results of pipeline stages,
I found it much easier to work with template files stored in
the filesystem, in and below the current working directory, in
which my Babeldoc configuration lives.
In a stage config, you can then do:
<foo>.smtpMessage=#parse("templates/mailtemplate.vm")
and have the body of mailtemplate.vm evaluated in the context
of the pipeline stage, while being included from the filesystem
in the templates directory, right next to your pipeline dir, or
even in it, for that matter.
Due to Velocity's template reloading (and caching) you can even
update the template(s) and have Velocity reload them without
having to restart Babeldoc.
Patch (to VariableProcessor only) as follows:
Index: com/babeldoc/core/VariableProcessor.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/VariableProcessor.java,v
retrieving revision 1.8
diff -u -r1.8 VariableProcessor.java
--- com/babeldoc/core/VariableProcessor.java 7 Aug 2003 21:12:25 -0000 1.8
+++ com/babeldoc/core/VariableProcessor.java 9 Oct 2003 15:43:23 -0000
@@ -97,9 +97,12 @@
/**
* Setup up the velocity upfront
*/
- Velocity.setProperty("resource.loader", "classpath");
+ Velocity.setProperty("resource.loader", "file,classpath");
Velocity.setProperty("classpath.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+ Velocity.setProperty("file.resource.loader.class",
+ "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
+ Velocity.setProperty("file.resource.loader.path", ".");
Velocity.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
"org.apache.velocity.runtime.log.SimpleLog4JLogSystem" );
Velocity.setProperty("runtime.log.logsystem.log4j.category", "babeldoc");
Note that the FileResourceLoader is used in conjunction with the
original ClasspathResourceLoader, which enables you to:
1. Use Babeldoc exactly as before, with templates in the core
.jar-files.
2. Use filesystem-based templates at will.
3. Override Babeldoc's internal templates with templates in the
filesystem, as long as their path-names are equal. Neat?
Comments?
One thing that strikes me right now is that perhaps the path for
the FileResourceLoader should not be ".", but rather connected to
the BABELDOC_USER directory, or similar. Is that guaranteed to be
present in a property by itself?
/David
|
|
From: David K. <dav...@al...> - 2003-10-10 08:57:23
Attachments:
velocity_loader.patch
|
Ok, I have reworked the patch slightly, as follows.
Purpose: Allow Velocity templates to be loaded from
the filesystem in addition to the classpath.
Changes (to VariableProcessor only):
- Add the FileResourceLoader to be used before the
default ClasspathResourceLoader
- Load templates from the filesystem using the set
of search paths provided by the EnvironmentLoader
(Path for Velocity constructed as CSV, using the
imported StringUtils.join method)
- Enable caching of loaded templates with a check
for modifications every two seconds
Consequences:
- Templates for use within Babeldoc can now be placed
and managed in the filesystem external to any jar-files
- Templates in the filesystem override templates in
Babeldoc .jar-files having the same name
- It is now very easy to use large, complex templates
in pipeline stages, since all that's needed is:
<stage-name>.<whatever>=#parse("path/to/template.vm")
where the template.vm is evaluated in context of the
pipeline stage and it's document just as an inline
template directly specified in the property would be
Note: it is also possible to do this:
<stage-name>.<whatever>=#include("path/to/something")
which includes something verbatim but does NOT cause
Velocity to actually evaluate it as a template, at
least according to the Velocity docs
- The #parse and #include statements should also be
possible to use inline (#parse recursively) inside
template bodies in general, but I have not tested
this yet (should work, though, since the default
parse-depth of Velocity is set to 10)
- It is now possible to edit a template file and have
the new version of it used without restarting Babeldoc,
due to the reloading mechanism of Velocity
I have tested these changes in my setup with no ill
effects that I have been able to see, in pipelines
that use template files and pipelines that do not,
but please test it further, since it's a change in
the very core of Babeldoc, which makes me nervous.
Patch attached, for your consideration.
Regards,
David Kinnvall
|
|
From: Michael A. <mic...@ze...> - 2003-10-10 15:52:54
Attachments:
mailscanner.diff
|
Bruce, Here's the updated MailboxScanner. Dejan, that filter stuff in ScannerWorker works a treat, and makes the MailboxScanner code much more elegant. The only thing I added was some protected access to the filters (by name only, not to the Hashtable). Cheers... MikeA |
|
From: Dejan K. <dej...@nb...> - 2003-10-13 08:21:36
|
Applied. Thanks Mike! Btw, I noticed you are on the developer list now. So, you have CVS commit right and you can work with CVS directly. No need to send patches - we believe you now! ;) Dejan ----- Original Message ----- From: "Michael Ansley" <mic...@ze...> To: <bab...@li...> Sent: Friday, October 10, 2003 5:52 PM Subject: [Babeldoc-devel] Mailbox scanner and some misc ScannerWorker stuff > Bruce, > > Here's the updated MailboxScanner. Dejan, that filter stuff in > ScannerWorker works a treat, and makes the MailboxScanner code much more > elegant. The only thing I added was some protected access to the > filters (by name only, not to the Hashtable). > > Cheers... > > > MikeA > > > |
|
From: Michael A. <mic...@ze...> - 2003-10-13 17:51:10
|
Cheers, Dejan. I'm not sure whether that's a good or bad thing, for me or the project... On Mon, 2003-10-13 at 09:20, Dejan Krsmanovic wrote: > Applied. Thanks Mike! > Btw, I noticed you are on the developer list now. So, you have CVS commit > right and you can work with CVS directly. No need to send patches - we > believe you now! ;) > > Dejan > > ----- Original Message ----- > From: "Michael Ansley" <mic...@ze...> > To: <bab...@li...> > Sent: Friday, October 10, 2003 5:52 PM > Subject: [Babeldoc-devel] Mailbox scanner and some misc ScannerWorker stuff > > > > Bruce, > > > > Here's the updated MailboxScanner. Dejan, that filter stuff in > > ScannerWorker works a treat, and makes the MailboxScanner code much more > > elegant. The only thing I added was some protected access to the > > filters (by name only, not to the Hashtable). > > > > Cheers... > > > > > > MikeA > > > > > > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > SourceForge.net hosts over 70,000 Open Source Projects. > See the people who have HELPED US provide better services: > Click here: http://sourceforge.net/supporters.php > _______________________________________________ > Babeldoc-devel mailing list > Bab...@li... > https://lists.sourceforge.net/lists/listinfo/babeldoc-devel |