public abstract class AbstractTemplateProcessor<T> extends Object implements TemplateProcessor<T>
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.Constructor and Description |
---|
AbstractTemplateProcessor(javax.ws.rs.core.Configuration config,
javax.servlet.ServletContext servletContext,
String propertySuffix,
String... supportedExtensions)
Create an instance of the processor with injected
config and
(optional) servlet context . |
Modifier and Type | Method and Description |
---|---|
protected String |
getBasePath()
Return base path for current template processor.
|
protected Charset |
getEncoding()
Get the output encoding.
|
protected javax.servlet.ServletContext |
getServletContext()
Return current servlet context, if present.
|
protected <F> F |
getTemplateObjectFactory(org.glassfish.hk2.api.ServiceLocator serviceLocator,
Class<F> type,
org.glassfish.jersey.internal.util.collection.Value<F> defaultValue)
Retrieve a template object factory.
|
T |
resolve(String name,
javax.ws.rs.core.MediaType mediaType)
Resolve a template name to a template reference.
|
protected abstract T |
resolve(String templatePath,
Reader reader)
Resolve given template path and/or reader to a template reference object.
|
protected Charset |
setContentType(javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
Set the
HttpHeaders.CONTENT_TYPE header to the httpHeaders based on mediaType and
default encoding defined in this processor. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
writeTo
public AbstractTemplateProcessor(javax.ws.rs.core.Configuration config, javax.servlet.ServletContext servletContext, String propertySuffix, String... supportedExtensions)
config
and
(optional) servlet context
.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.protected String getBasePath()
protected javax.servlet.ServletContext getServletContext()
null
.public T resolve(String name, javax.ws.rs.core.MediaType mediaType)
TemplateProcessor
resolve
in interface TemplateProcessor<T>
name
- the template name.mediaType
- requested media type of the template.null
if the template name cannot be resolved.protected abstract T resolve(String templatePath, Reader reader) throws Exception
templatePath
- resolved template path (incl. base path and suffix).reader
- reader containing template character stream.null
template reference object.Exception
- if an exception occurred during resolving.protected <F> F getTemplateObjectFactory(org.glassfish.hk2.api.ServiceLocator serviceLocator, Class<F> type, org.glassfish.jersey.internal.util.collection.Value<F> defaultValue)
configuration
and if not found, given default value is used.F
- type of requested template object factory.serviceLocator
- HK2 service locator to initialize factory if configured as class or class-name.type
- type of requested template object factory.defaultValue
- default value to be used if no factory reference is present in configuration.null
template object factory.protected Charset setContentType(javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders)
HttpHeaders.CONTENT_TYPE
header to the httpHeaders
based on mediaType
and
default encoding
defined in this processor. If mediaType
defines encoding
then this encoding will be used otherwise the default processor encoding is used. The chosen encoding
is returned from the method.mediaType
- Media type of the entity.httpHeaders
- Http headers.protected Charset getEncoding()
null
encoding.Copyright © 2007-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.