Class AbstractTemplateProcessor<T>

    • Constructor Detail

      • AbstractTemplateProcessor

        public AbstractTemplateProcessor​(jakarta.ws.rs.core.Configuration config,
                                         jakarta.servlet.ServletContext servletContext,
                                         String propertySuffix,
                                         String... supportedExtensions)
        Create an instance of the processor with injected config and (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 Detail

      • getBasePath

        protected String 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

        public T resolve​(String name,
                         jakarta.ws.rs.core.MediaType mediaType)
        Description copied from interface: TemplateProcessor
        Resolve a template name to a template reference.
        Specified by:
        resolve in interface TemplateProcessor<T>
        Parameters:
        name - the template name.
        mediaType - requested media type of the template.
        Returns:
        the template reference, otherwise null if the template name cannot be resolved.
      • resolve

        protected abstract T resolve​(String templatePath,
                                     Reader reader)
                              throws Exception
        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-null template reference object.
        Throws:
        Exception - if an exception occurred during resolving.
      • getTemplateObjectFactory

        protected <F> F getTemplateObjectFactory​(Function<Class<?>,​?> createInstance,
                                                 Class<F> type,
                                                 org.glassfish.jersey.internal.util.collection.Value<F> defaultValue)
        Retrieve a template object factory. The factory is, at first, looked for in configuration and 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-null template object factory.
      • setContentType

        protected Charset setContentType​(jakarta.ws.rs.core.MediaType mediaType,
                                         jakarta.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. 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.
        Parameters:
        mediaType - Media type of the entity.
        httpHeaders - Http headers.
        Returns:
        Selected encoding.
      • getEncoding

        protected Charset getEncoding()
        Get the output encoding.
        Returns:
        Not-null encoding.