1
2
3
4
5 package gboat2.base.plugin.struts.velocity;
6
7 import java.util.Properties;
8
9 import org.apache.struts2.StrutsConstants;
10 import org.apache.struts2.views.velocity.VelocityManager;
11 import org.apache.velocity.app.Velocity;
12
13 import com.opensymphony.xwork2.inject.Inject;
14
15
16
17
18
19
20
21
22
23
24
25 public class GboatVelocityManager extends VelocityManager {
26
27 private boolean devMode = false;
28
29 @Inject(StrutsConstants.STRUTS_DEVMODE)
30 public void setDevMode(String devMode) {
31 this.devMode = "true".equals(devMode);
32 }
33
34 private void debugIntercept(Properties velocityProperties) {
35 String resourceLoader = velocityProperties.getProperty(Velocity.RESOURCE_LOADER);
36 if (null == resourceLoader || -1 == resourceLoader.indexOf("debuggboat2")) {
37 velocityProperties.setProperty("debuggboat2.resource.loader.description", "debug velocity bundle loader");
38 velocityProperties.setProperty("debuggboat2.resource.loader.class", DebugVelocityResourceLoader.class.getName());
39 velocityProperties.setProperty("debuggboat2.resource.loader.cache", "false");
40 if (null == resourceLoader) {
41 velocityProperties.setProperty(Velocity.RESOURCE_LOADER, "debuggboat2,strutsfile,strutsclass,osgi");
42 } else {
43 velocityProperties.setProperty(Velocity.RESOURCE_LOADER, "debuggboat2," + resourceLoader);
44 }
45 } else {
46 if (resourceLoader.endsWith(",debuggboat2")
47 || resourceLoader.indexOf(",strutsfile,") != -1) {
48 resourceLoader = resourceLoader.replace(",debuggboat2", "");
49 velocityProperties.setProperty(Velocity.RESOURCE_LOADER, "debuggboat2," + resourceLoader);
50 }
51 }
52 }
53
54 @Override
55 public void setVelocityProperties(Properties velocityProperties) {
56 if (devMode) {
57 debugIntercept(velocityProperties);
58 }
59 super.setVelocityProperties(velocityProperties);
60 }
61 }