Just did it with spring and speed:
I am having trouble getting speed to pick up an event handler, at the end, specifying it in the servlet xml file:
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> <property name="resourceLoaderPath" value="WEB-INF/templates"/> <property name="velocityPropertiesMap"> <map> <entry key="eventhandler.include.class"><value>com.velocity.events.OptionalIncludeEventHandler</value></entry> </map> </property> </bean>
It just does not agree that I put it in the properties file - it will create an instance of the class, but not register it as an event listener. very upset.
The class itself is simple, a rather egregious break with the existing speed class "org.apache.velocity.app.event.implementIncludeNotFound". The existing speed implementation checks for the existence of the file, and if not, returns a custom alternative (default: notfound.vm).
The mine is exactly the same, except that it returns null if the file does not exist, forcing the analyzer to skip this include / parse directive:
public class OptionalIncludeEventHandler implements IncludeEventHandler, RuntimeServicesAware { private RuntimeServices rs; @Override public void setRuntimeServices(RuntimeServices rs) { this.rs = rs; } @Override public String includeEvent(String includeResourcePath, String currentResourcePath, String directiveName) { return rs.getLoaderNameForResource(includeResourcePath) != null ? includeResourcePath : null; } }
It works like a charm.
Hope this is helpful.
source share