Class AbstractViewsRenderer<T,R>
java.lang.Object
io.micronaut.views.AbstractViewsRenderer<T,R>
- Type Parameters:
T- The model typeR- The request type
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, ViewsRenderer<T,R>
- Direct Known Subclasses:
FreemarkerViewsRenderer, HandlebarsViewsRenderer, JinjavaViewsRenderer, RockerViewsRenderer, VelocityViewsRenderer
@Internal
public abstract class AbstractViewsRenderer<T,R>
extends Object
implements ViewsRenderer<T,R>
Base class for view renderers backed by a
ViewsRendererConfiguration.
Provides the common template-name normalization and resource-location construction used by renderer implementations. The configured default extension is required when resolving a view. A resource loader is optional so renderers that cannot check for template resources can still use the name and location helpers.
-
Field Summary
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractViewsRenderer(@NonNull ViewsRendererConfiguration configuration, @NonNull ViewsConfiguration viewsConfiguration, @NonNull io.micronaut.core.io.ResourceLoader resourceLoader) Creates a renderer using the configured views folder and resource loader.protectedAbstractViewsRenderer(@NonNull ViewsRendererConfiguration configuration, @NonNull String folder) Creates a renderer that only uses the shared name and location helpers.protectedAbstractViewsRenderer(@NonNull ViewsRendererConfiguration configuration, @NonNull String folder, @Nullable io.micronaut.core.io.ResourceLoader resourceLoader) Creates a renderer using the supplied template folder and optional resource loader. -
Method Summary
Modifier and TypeMethodDescriptionprotected final @NonNull StringObtains the configured default template extension.booleanDetermines whether a template resource for the given view name is available.protected @NonNull StringgetTemplate(@NonNull String viewName, @NonNull Charset charset) Loads the template identified by the view name from the configured resource loader.protected final @NonNull StringviewLocationWithExtension(@NonNull String name) Resolves a view name relative to the configured template folder with its default extension.protected final @NonNull StringviewLocationWithoutExtension(@NonNull String name) Resolves a view name relative to the configured template folder without its extension.protected final @NonNull StringviewNameWithExtension(@NonNull String name) Normalizes a view name and appends the configured default extension.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.core.order.Ordered
getOrderMethods inherited from interface ViewsRenderer
render
-
Constructor Details
-
AbstractViewsRenderer
protected AbstractViewsRenderer(@NonNull ViewsRendererConfiguration configuration, @NonNull ViewsConfiguration viewsConfiguration, @NonNull io.micronaut.core.io.ResourceLoader resourceLoader) Creates a renderer using the configured views folder and resource loader.- Parameters:
configuration- The renderer configuration, including the default template extensionviewsConfiguration- The shared views configurationresourceLoader- The resource loader used to locate templates
-
AbstractViewsRenderer
protected AbstractViewsRenderer(@NonNull ViewsRendererConfiguration configuration, @NonNull String folder) Creates a renderer that only uses the shared name and location helpers.- Parameters:
configuration- The renderer configuration, including the default template extensionfolder- The template folder prefix
-
AbstractViewsRenderer
protected AbstractViewsRenderer(@NonNull ViewsRendererConfiguration configuration, @NonNull String folder, @Nullable io.micronaut.core.io.ResourceLoader resourceLoader) Creates a renderer using the supplied template folder and optional resource loader.- Parameters:
configuration- The renderer configuration, including the default template extensionfolder- The template folder prefixresourceLoader- The resource loader used to locate templates, if supported by the renderer
-
-
Method Details
-
defaultExtension
Obtains the configured default template extension.- Returns:
- The configured default extension
- Throws:
NullPointerException- If no default extension is configured
-
getTemplate
Loads the template identified by the view name from the configured resource loader.- Parameters:
viewName- The requested view name, with or without the configured extensioncharset- The character set used to decode the template- Returns:
- The template text
- Throws:
ViewRenderingException- If the template cannot be loadedNullPointerException- If this renderer has no resource loader
-
viewNameWithExtension
Normalizes a view name and appends the configured default extension.The supplied name may already include the configured extension. The configured extension may include a leading
.; the returned name always contains exactly one separator.- Parameters:
name- The requested view name- Returns:
- The template name
-
viewLocationWithoutExtension
-
viewLocationWithExtension
-
exists
Determines whether a template resource for the given view name is available.Returns
falsewhen this renderer was created without a resource loader.- Specified by:
existsin interfaceViewsRenderer<T,R> - Parameters:
viewName- The requested view name, with or without the configured extension- Returns:
- Whether the corresponding template resource exists
-