|
From: <tr...@us...> - 2003-10-10 23:10:37
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core In directory sc8-pr-cvs1:/tmp/cvs-serv1689 Modified Files: VariableProcessor.java Log Message: Changes from david kinnvall to make the velocity be able to access scripts on the file system Index: VariableProcessor.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/VariableProcessor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** VariableProcessor.java 7 Aug 2003 21:12:25 -0000 1.8 --- VariableProcessor.java 10 Oct 2003 23:10:31 -0000 1.9 *************** *** 70,73 **** --- 70,74 ---- import org.apache.velocity.app.Velocity; import org.apache.velocity.context.Context; + import org.apache.commons.lang.StringUtils; import java.io.*; *************** *** 83,86 **** --- 84,134 ---- * </p> * + * <p> + * <strong>Changes from David Kinnvall</strong> + * <ul> + * <li>Add the FileResourceLoader to be used before the + * default ClasspathResourceLoader</li> + * <li>Load templates from the filesystem using the set + * of search paths provided by the EnvironmentLoader </li> + * (Path for Velocity constructed as CSV, using the + * imported StringUtils.join method) + * <li> Enable caching of loaded templates with a check + * for modifications every two seconds</li> + * </ul> + * + * <strong>Consequences:</strong> + * <ul> + * <li>Templates for use within Babeldoc can now be placed + * and managed in the filesystem external to any jar-files</li> + * <li>Templates in the filesystem override templates in + * Babeldoc .jar-files having the same name</li> + * <li>It is now very easy to use large, complex templates + * in pipeline stages, since all that's needed is: + * + * <pre> <stage-name>.<whatever>=#parse("path/to/template.vm")</pre> + * + * 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<br/> + * + * Note: it is also possible to do this: + * + *<pre><stage-name>.<whatever>=#include("path/to/something")</pre> + * + * which includes something verbatim but does NOT cause + * Velocity to actually evaluate it as a template, at + * least according to the Velocity docs.<br/> + * + * <li>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)</li> + * + * <li>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</li> + * </ul> + * * @author Bmcdonald * @version 1.0 *************** *** 96,109 **** try { /** ! * Setup up the velocity upfront */ ! Velocity.setProperty("resource.loader", "classpath"); Velocity.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Velocity.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" ); Velocity.setProperty("runtime.log.logsystem.log4j.category", "babeldoc"); ! Velocity.setProperty("velocimacro.library", ! "core/VM_global_library.vm"); Velocity.init(); --- 144,176 ---- try { /** ! * Setup Velocity upfront */ ! // Search the filesystem before the classpath (allows override) ! Velocity.setProperty("resource.loader", "file,classpath"); ! ! // The ClasspathResourceLoader config Velocity.setProperty("classpath.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); + + // The FileResourceLoader config + Velocity.setProperty("file.resource.loader.class", + "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); + // Set the path to use (multi-value as CSV) + Velocity.setProperty("file.resource.loader.path", + StringUtils.join(EnvironmentLoader.getSearchPaths().iterator(), ",")); + // Cache found templates, but... + Velocity.setProperty("file.resource.loader.cache", "true"); + // ...check for modifications every two seconds + Velocity.setProperty("file.resource.loader.modificationCheckInterval", "2"); + + // Integrate Velocity logging into Babeldoc Velocity.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" ); Velocity.setProperty("runtime.log.logsystem.log4j.category", "babeldoc"); ! ! // Load centrally defined useful macros ! Velocity.setProperty("velocimacro.library", "core/VM_global_library.vm"); ! ! // Done - start the Velocity engine Velocity.init(); |