@Component(value="velocityContentPublisher") @Scope(value="prototype") @DependsOn(value="appSettings") public class VelocityContentPublisher extends Object implements Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>, org.springframework.context.ApplicationContextAware
Publisher that uses Velocity to publish HTML files.
AppSettings. To be safe ensure any Spring Bean definition either sets it explicitly or depends-on appSettings component
template and related settings are context dependent and hence not thread safe as a singleton.| Constructor and Description |
|---|
VelocityContentPublisher() |
VelocityContentPublisher(org.springframework.context.ApplicationContext springAppContext)
springAppContext Allows better
Resource resolution. |
VelocityContentPublisher(org.springframework.context.ApplicationContext springAppContext,
org.apache.velocity.app.VelocityEngine velocityEngine) |
VelocityContentPublisher(String path,
org.apache.velocity.app.VelocityEngine velocityEngine) |
VelocityContentPublisher(org.apache.velocity.Template template) |
VelocityContentPublisher(org.apache.velocity.app.VelocityEngine velocityEngine) |
| Modifier and Type | Method and Description |
|---|---|
void |
addContext(Map objectMap)
Add Context to the Publisher.
Note: This will replace any existing context map. |
void |
autoInitEngine() |
void |
clearContext()
Clear DataMap & Data Context added by
this#addContext(Map) |
org.apache.velocity.VelocityContext |
getContext() |
org.apache.velocity.Template |
getTemplate() |
void |
publish(String outputPath)
Publish to implementation specific Output and also send a copy back via Writer.
|
void |
publish(Writer writer)
Publish output to
Writer |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setContext(org.apache.velocity.VelocityContext context)
Supply a Context to the Publisher
Note: This will replace any existing context map. |
void |
setTemplate(String path)
Set path according to following rules of relative paths:
Path relative to what is set in velocity.xml resourceLoaderPath If path is an absolute resource like file: or classpath: ... |
void |
setTemplate(org.apache.velocity.Template template) |
public VelocityContentPublisher()
public VelocityContentPublisher(String path, org.apache.velocity.app.VelocityEngine velocityEngine) throws org.apache.velocity.exception.ResourceNotFoundException, org.apache.velocity.exception.ParseErrorException, org.apache.velocity.exception.MethodInvocationException, IOException
org.apache.velocity.exception.ResourceNotFoundExceptionorg.apache.velocity.exception.ParseErrorExceptionorg.apache.velocity.exception.MethodInvocationExceptionIOExceptionpublic VelocityContentPublisher(org.apache.velocity.Template template)
public VelocityContentPublisher(org.springframework.context.ApplicationContext springAppContext)
Resource resolution.springAppContext - public VelocityContentPublisher(org.springframework.context.ApplicationContext springAppContext,
org.apache.velocity.app.VelocityEngine velocityEngine)
public VelocityContentPublisher(org.apache.velocity.app.VelocityEngine velocityEngine)
@PostConstruct public void autoInitEngine() throws IOException
IOExceptionpublic void addContext(Map objectMap)
PublisheraddContext in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>objectMap - as Map of Name as String, corresponding Object to insert into Contextpublic void publish(String outputPath) throws IOException
Publisherpublish in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>outputPath - as String output pathIOExceptionpublic void publish(Writer writer) throws IOException
PublisherWriterpublish in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>writer - as WriterIOExceptionpublic void setTemplate(org.apache.velocity.Template template)
setTemplate in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>template - as Tpublic void setTemplate(String path) throws org.apache.velocity.exception.ResourceNotFoundException, org.apache.velocity.exception.ParseErrorException, org.apache.velocity.exception.MethodInvocationException, IOException
ResourceLoader.getResource(String) and derive fle path from the Resource using Resource.getFile()setTemplate in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>org.apache.velocity.exception.ResourceNotFoundExceptionorg.apache.velocity.exception.ParseErrorExceptionorg.apache.velocity.exception.MethodInvocationExceptionIOExceptionpublic org.apache.velocity.VelocityContext getContext()
public void setContext(org.apache.velocity.VelocityContext context)
PublishersetContext in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>public org.apache.velocity.Template getTemplate()
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic void clearContext()
Publisherthis#addContext(Map)clearContext in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>Copyright © 2018. All rights reserved.