|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.stanbol.contenthub.web.processor.FreemarkerViewProcessor
@Singleton @Provider public class FreemarkerViewProcessor
Match a Viewable-named view with a Freemarker template. This class is based on the following original implementation: http://github.com/cwinters/jersey-freemarker/
You can configure the location of your templates with the context param 'freemarker.template.path'. If not
assigned we'll use a default of WEB-INF/templates. Note that this uses Freemarker's
WebappTemplateLoader to load/cache the templates, so check its docs (or crank up
the logging under the 'freemarker.cache' package) if your templates aren't getting loaded.
This will put your Viewable's model object in the template variable "it", unless the model is a Map. If so, the values will be assigned to the template assuming the map is of type Map<String,Object>.
There are a number of methods you can override to change the behavior, such as handling processing exceptions, changing the default template extension, or adding variables to be assigned to every template context.
| Field Summary | |
|---|---|
protected javax.servlet.ServletContext |
context
|
static java.lang.String |
FREEMARKER_TEMPLATE_PATH_INIT_PARAM
|
protected freemarker.template.Configuration |
freemarkerConfig
|
protected java.lang.String |
rootPath
|
| Constructor Summary | |
|---|---|
FreemarkerViewProcessor()
|
|
| Method Summary | |
|---|---|
protected void |
assignFreemarkerConfig(freemarker.template.Configuration config,
javax.servlet.ServletContext context)
Modify freemarker configuration after we've created it and applied any settings from 'freemarker.properties' on the classpath. |
protected freemarker.template.Configuration |
getConfig()
|
protected java.lang.String |
getDefaultExtension()
|
protected java.util.Map<java.lang.String,java.lang.Object> |
getVariablesForTemplate(java.util.Map<java.lang.String,java.lang.Object> viewableVariables)
Define additional variables to make available to the template. |
protected void |
onProcessException(java.lang.Throwable t,
freemarker.template.Template template,
java.util.Map<java.lang.String,java.lang.Object> templateContext,
java.io.OutputStream out)
Catch any exception generated during template processing. |
freemarker.template.Template |
resolve(java.lang.String path)
|
void |
writeTo(freemarker.template.Template template,
com.sun.jersey.api.view.Viewable viewable,
java.io.OutputStream out)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String FREEMARKER_TEMPLATE_PATH_INIT_PARAM
protected freemarker.template.Configuration freemarkerConfig
protected java.lang.String rootPath
@Context protected javax.servlet.ServletContext context
| Constructor Detail |
|---|
public FreemarkerViewProcessor()
| Method Detail |
|---|
protected java.lang.String getDefaultExtension()
protected java.util.Map<java.lang.String,java.lang.Object> getVariablesForTemplate(java.util.Map<java.lang.String,java.lang.Object> viewableVariables)
viewableVariables - variables provided by whomever generated the viewable object; these are provided for
reference only, there will be no effect if you modify this map
protected void onProcessException(java.lang.Throwable t,
freemarker.template.Template template,
java.util.Map<java.lang.String,java.lang.Object> templateContext,
java.io.OutputStream out)
throws java.io.IOException
t - throwable caughttemplatePath - path of template we're executingtemplateContext - context use when evaluating this templateout - output stream from servlet container
java.io.IOException - on any write errors, or if you want to rethrow
protected void assignFreemarkerConfig(freemarker.template.Configuration config,
javax.servlet.ServletContext context)
config - configuration we've created so farcontext - servlet context used to create the configurationprotected freemarker.template.Configuration getConfig()
public freemarker.template.Template resolve(java.lang.String path)
resolve in interface com.sun.jersey.spi.template.ViewProcessor<freemarker.template.Template>
public void writeTo(freemarker.template.Template template,
com.sun.jersey.api.view.Viewable viewable,
java.io.OutputStream out)
throws java.io.IOException
writeTo in interface com.sun.jersey.spi.template.ViewProcessor<freemarker.template.Template>java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||