1 package org.tinyjee.maven.dim.sources;
2
3 import org.apache.velocity.app.VelocityEngine;
4 import org.apache.velocity.context.Context;
5 import org.apache.velocity.tools.config.EasyFactoryConfiguration;
6 import org.tinyjee.maven.dim.spi.Globals;
7 import org.tinyjee.maven.dim.spi.VelocityConfigurator;
8
9 import java.util.Map;
10
11 import static org.apache.velocity.runtime.RuntimeConstants.*;
12
13
14
15
16
17
18 public class DefaultVelocityConfigurator implements VelocityConfigurator {
19 public void configureEngine(VelocityEngine engine) {
20
21 engine.setProperty(RESOURCE_LOADER, "dim-resource");
22 engine.setProperty("dim-resource.resource.loader.class",
23 "org.tinyjee.maven.dim.sources.TemplateSource$UrlResourceLoader");
24
25
26 if (engine.getProperty(VM_PERM_ALLOW_INLINE) == null) engine.setProperty(VM_PERM_ALLOW_INLINE, true);
27
28
29 String existingLibrary = (String) engine.getProperty(VM_LIBRARY);
30 engine.setProperty(VM_LIBRARY, "classpath:/templates/dim/macro-library.vm," + VM_LIBRARY_DEFAULT +
31 (existingLibrary == null ? "" : ',' + existingLibrary));
32 }
33
34 public void configureTools(EasyFactoryConfiguration toolsConfiguration) {
35 toolsConfiguration.toolbox("application").
36 tool("org.apache.velocity.tools.generic.AlternatorTool").
37 tool("org.apache.velocity.tools.generic.ClassTool").
38 tool("org.apache.velocity.tools.generic.ComparisonDateTool").
39 tool("org.apache.velocity.tools.generic.ConversionTool").
40 tool("org.apache.velocity.tools.generic.DateTool").
41 tool("org.apache.velocity.tools.generic.DisplayTool").
42 tool("org.apache.velocity.tools.generic.EscapeTool").
43 tool("org.apache.velocity.tools.generic.FieldTool").
44 tool("org.apache.velocity.tools.generic.MathTool").
45 tool("org.apache.velocity.tools.generic.NumberTool").
46 tool("org.apache.velocity.tools.generic.RenderTool").
47 tool("org.apache.velocity.tools.generic.SortTool").
48 tool("org.apache.velocity.tools.generic.ListTool").
49 tool("org.apache.velocity.tools.generic.ResourceTool").
50 tool("org.apache.velocity.tools.generic.MarkupTool").
51 tool(VelocityHighlightingTool.class).
52 tool(VelocitySourceClassInvocationTool.class);
53 }
54
55 public void configureContext(Map<String, Object> parameters, Context templateContext) {
56
57
58 if (!templateContext.containsKey("globals")) templateContext.put("globals", Globals.getInstance());
59 if (!templateContext.containsKey("macroParameters")) templateContext.put("macroParameters", parameters);
60 if (!templateContext.containsKey("context")) templateContext.put("context", templateContext);
61
62
63
64 }
65 }