@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.ResourceNotFoundException
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException
IOException
public 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
IOException
public void addContext(Map objectMap)
Publisher
addContext
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
Publisher
publish
in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>
outputPath
- as String output pathIOException
public void publish(Writer writer) throws IOException
Publisher
Writer
publish
in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>
writer
- as Writer
IOException
public 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.ResourceNotFoundException
org.apache.velocity.exception.ParseErrorException
org.apache.velocity.exception.MethodInvocationException
IOException
public org.apache.velocity.VelocityContext getContext()
public void setContext(org.apache.velocity.VelocityContext context)
Publisher
setContext
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.ApplicationContextAware
org.springframework.beans.BeansException
public void clearContext()
Publisher
this#addContext(Map)
clearContext
in interface Publisher<org.apache.velocity.Template,org.apache.velocity.VelocityContext>
Copyright © 2018. All rights reserved.