Class AbstractTemplateProcessor<T>
java.lang.Object
org.glassfish.jersey.server.mvc.spi.AbstractTemplateProcessor<T>
- All Implemented Interfaces:
TemplateProcessor<T>
Default implementation of
template processor that can be used to
implement support for custom templating engines. The class currently recognizes following properties:
If any of the properties are not supported by particular template processor then this fact should be mentioned in documentation
of the template processor.- Author:
- Michal Gajdos
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractTemplateProcessor(Configuration config, jakarta.servlet.ServletContext servletContext, String propertySuffix, String... supportedExtensions) Create an instance of the processor with injectedconfigand (optional)servlet context. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturn base path for current template processor.protected CharsetGet the output encoding.protected jakarta.servlet.ServletContextReturn current servlet context, if present.protected <F> FgetTemplateObjectFactory(Function<Class<?>, ?> createInstance, Class<F> type, Value<F> defaultValue) Retrieve a template object factory.Resolve a template name to a template reference.protected abstract TResolve given template path and/or reader to a template reference object.protected CharsetsetContentType(MediaType mediaType, MultivaluedMap<String, Object> httpHeaders) Set theHttpHeaders.CONTENT_TYPEheader to thehttpHeadersbased onmediaTypeanddefault encodingdefined in this processor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.glassfish.jersey.server.mvc.spi.TemplateProcessor
writeTo
-
Constructor Details
-
AbstractTemplateProcessor
public AbstractTemplateProcessor(Configuration config, jakarta.servlet.ServletContext servletContext, String propertySuffix, String... supportedExtensions) Create an instance of the processor with injectedconfigand (optional)servlet context.- Parameters:
config- configuration to configure this processor from.servletContext- (optional) servlet context to obtain template resources from.propertySuffix- suffix to distinguish properties for current template processor.supportedExtensions- supported template file extensions.
-
-
Method Details
-
getBasePath
Return base path for current template processor.- Returns:
- base path or an empty string.
-
getServletContext
protected jakarta.servlet.ServletContext getServletContext()Return current servlet context, if present.- Returns:
- servlet context instance or
null.
-
resolve
Description copied from interface:TemplateProcessorResolve a template name to a template reference.- Specified by:
resolvein interfaceTemplateProcessor<T>- Parameters:
name- the template name.mediaType- requested media type of the template.- Returns:
- the template reference, otherwise
nullif the template name cannot be resolved.
-
resolve
Resolve given template path and/or reader to a template reference object.- Parameters:
templatePath- resolved template path (incl. base path and suffix).reader- reader containing template character stream.- Returns:
- non-
nulltemplate reference object. - Throws:
Exception- if an exception occurred during resolving.
-
getTemplateObjectFactory
protected <F> F getTemplateObjectFactory(Function<Class<?>, ?> createInstance, Class<F> type, Value<F> defaultValue) Retrieve a template object factory. The factory is, at first, looked for inconfigurationand if not found, given default value is used.- Type Parameters:
F- type of requested template object factory.- Parameters:
createInstance- function that delegates a creation and an initialization to injection manager.type- type of requested template object factory.defaultValue- default value to be used if no factory reference is present in configuration.- Returns:
- non-
nulltemplate object factory.
-
setContentType
Set theHttpHeaders.CONTENT_TYPEheader to thehttpHeadersbased onmediaTypeanddefault encodingdefined in this processor. IfmediaTypedefines encoding then this encoding will be used otherwise the default processor encoding is used. The chosen encoding is returned from the method.- Parameters:
mediaType- Media type of the entity.httpHeaders- Http headers.- Returns:
- Selected encoding.
-
getEncoding
Get the output encoding.- Returns:
- Not-
nullencoding.
-