Class WebApplicationTemplateResource
- java.lang.Object
-
- org.thymeleaf.templateresource.WebApplicationTemplateResource
-
- All Implemented Interfaces:
ITemplateResource
public final class WebApplicationTemplateResource extends java.lang.Object implements ITemplateResource
Implementation of
ITemplateResourceaccessible from the context of a web application. The paths of these resources start at the web application file root which, for instance, in servlet-based applications is/WEB-INF.Objects of this class are usually created by
WebApplicationTemplateResolver.- Since:
- 3.1.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringcharacterEncodingprivate java.lang.Stringpathprivate IWebApplicationwebApplication
-
Constructor Summary
Constructors Constructor Description WebApplicationTemplateResource(IWebApplication webApplication, java.lang.String path, java.lang.String characterEncoding)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexists()Determines whether the resource represented by this object really exists or not.java.lang.StringgetBaseName()Returns the base name of a resource.java.lang.StringgetDescription()Returns aStringdescribing the resource.java.io.Readerreader()Returns aReaderthat can be used for consuming the template contents.ITemplateResourcerelative(java.lang.String relativeLocation)Creates anotherITemplateResource, usually of the same implementation class, for a resource living in a location relative to the current object's.
-
-
-
Field Detail
-
webApplication
private final IWebApplication webApplication
-
path
private final java.lang.String path
-
characterEncoding
private final java.lang.String characterEncoding
-
-
Constructor Detail
-
WebApplicationTemplateResource
public WebApplicationTemplateResource(IWebApplication webApplication, java.lang.String path, java.lang.String characterEncoding)
-
-
Method Detail
-
getDescription
public java.lang.String getDescription()
Description copied from interface:ITemplateResourceReturns a
Stringdescribing the resource.Note this should not be taken for a valid resource name, as depending on the implementation it could be too verbose/descriptive or not unique enough to be used for identification purposes.
- Specified by:
getDescriptionin interfaceITemplateResource- Returns:
- the resource description. Should never return
null.
-
getBaseName
public java.lang.String getBaseName()
Description copied from interface:ITemplateResourceReturns the base name of a resource.
The base name is aimed at creating derivative names from the name of the resource, usually from the deepest level of the resource path.
For example, a file resource located at
/home/user/template/main.htmlshould returnmainas its base name, so that names likemain.properties,main.th.xmlor similar can be derived, and afterwards resolved usingITemplateResource.relative(String).- Specified by:
getBaseNamein interfaceITemplateResource- Returns:
- the base name, or
nullif it cannot be computed for the specific type of resource.
-
reader
public java.io.Reader reader() throws java.io.IOExceptionDescription copied from interface:ITemplateResourceReturns a
Readerthat can be used for consuming the template contents.Most implementations of this interface will require specifying a character encoding during construction, so that this readers are correctly able to decode their underlying input streams.
Note this readers should be closed after being fully consumed, just like any other resources.
- Specified by:
readerin interfaceITemplateResource- Returns:
- a
Readeron the template contents. Should never returnnull. - Throws:
java.io.IOException- if an input/output exception happens or if the resource does not exist (e.g.FileNotFoundException).
-
relative
public ITemplateResource relative(java.lang.String relativeLocation)
Description copied from interface:ITemplateResourceCreates another
ITemplateResource, usually of the same implementation class, for a resource living in a location relative to the current object's.Note some
ITemplateResourceimplementations might not support this feature.- Specified by:
relativein interfaceITemplateResource- Parameters:
relativeLocation- the location of the resource we want to obtain, relative to the current one. Required.- Returns:
- the relative resource. Should never return
null.
-
exists
public boolean exists()
Description copied from interface:ITemplateResourceDetermines whether the resource represented by this object really exists or not.
Note that, depending on the implementation, this might mean actually access the resource, and such operation could have a cost in performance in some scenarios (e.g. a resource representing a remote URL).
This mechanism will be used by Template Resolvers extending from
AbstractTemplateResolverfor checking real resource existence if theAbstractTemplateResolver.setCheckExistence(boolean)flag is set totrue.- Specified by:
existsin interfaceITemplateResource- Returns:
trueif the resource exists,falseif not.
-
-