public class PackageTextTemplate extends TextTemplate
String
resource that can be appended to.Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CONTENT_TYPE
The content type used if not provided in the constructor
|
static String |
DEFAULT_ENCODING
The encoding used if not provided in the constructor
|
Constructor and Description |
---|
PackageTextTemplate(Class<?> clazz,
String fileName)
Constructor.
|
PackageTextTemplate(Class<?> clazz,
String fileName,
String contentType)
Constructor.
|
PackageTextTemplate(Class<?> clazz,
String fileName,
String contentType,
String encoding)
Constructor.
|
PackageTextTemplate(Class<?> clazz,
String fileName,
String style,
String variation,
Locale locale,
String contentType,
String encoding)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
getString()
Retrieves the
String resource. |
TextTemplate |
interpolate(Map<String,?> variables)
Interpolates a
Map of variables with the content and replaces the content with
the result. |
void |
setEncoding(String encoding) |
void |
setLocale(Locale locale)
This method shouldn't be used from the outside.
|
void |
setStyle(String style)
This method shouldn't be used from the outside.
|
void |
setVariation(String variation)
This method shouldn't be used from the outside.
|
asString, asString
close, getCharset, getContentType, getInputStream, lastModifiedTime, length, setCharset, setLastModified
getLocale, getStyle, getVariation
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getLocale, getStyle, getVariation
public static final String DEFAULT_CONTENT_TYPE
public static final String DEFAULT_ENCODING
public PackageTextTemplate(Class<?> clazz, String fileName)
clazz
- the Class
to be used for retrieving the classloader for loading the
PackagedTextTemplate
fileName
- the name of the file, relative to the clazz
positionpublic PackageTextTemplate(Class<?> clazz, String fileName, String contentType)
clazz
- the Class
to be used for retrieving the classloader for loading the
PackagedTextTemplate
fileName
- the name of the file, relative to the clazz
positioncontentType
- the mime type of this resource, such as "image/jpeg
" or "
text/html
"public PackageTextTemplate(Class<?> clazz, String fileName, String contentType, String encoding)
clazz
- the Class
to be used for retrieving the classloader for loading the
PackagedTextTemplate
fileName
- the name of the file, relative to the clazz
positioncontentType
- the mime type of this resource, such as "image/jpeg
" or "
text/html
"encoding
- the file's encoding, for example, "UTF-8
"public PackageTextTemplate(Class<?> clazz, String fileName, String style, String variation, Locale locale, String contentType, String encoding)
clazz
- the Class
to be used for retrieving the classloader for loading the
PackagedTextTemplate
fileName
- the name of the file, relative to the clazz
positionstyle
- Any resource style, such as a skin style (see Session
)variation
- The template's variation (of the style)locale
- The locale of the resource to loadcontentType
- the mime type of this resource, such as "image/jpeg
" or "
text/html
"encoding
- the file's encoding, for example, "UTF-8
"public void setStyle(String style)
IResourceStream
setStyle
in interface IResourceStream
setStyle
in class AbstractResourceStream
style
- The style where this stream did resolve to.public void setLocale(Locale locale)
IResourceStream
setLocale
in interface IResourceStream
setLocale
in class AbstractResourceStream
locale
- The Locale where this stream did resolve to.public void setVariation(String variation)
IResourceStream
setVariation
in interface IResourceStream
setVariation
in class AbstractResourceStream
variation
- The Variation where this stream did resolve to.public void setEncoding(String encoding)
public String getString()
TextTemplate
String
resource.getString
in class TextTemplate
String
resourceAbstractStringResourceStream.getString()
public final TextTemplate interpolate(Map<String,?> variables)
Map
of variables with the content and replaces the content with
the result. Variables are denoted in the String
by the
syntax ${variableName}
. The contents will be altered by replacing each variable
of the form ${variableName}
with the value returned by
variables.getValue("variableName")
.
WARNING: there is no going back to the original contents after the interpolation is done. If
you need to do different interpolations on the same original contents, use the method
TextTemplate.asString(Map)
instead.
interpolate
in class TextTemplate
variables
- a Map
of variables to interpolateCopyright © 2006–2022 Apache Software Foundation. All rights reserved.