MO
- The TemplateMarkupOutputModel
class this output format can deal with.public abstract class MarkupOutputFormat<MO extends TemplateMarkupOutputModel> extends OutputFormat
OutputFormat
-s that represent a "markup" format, which is any format where certain character
sequences have special meaning, and thus may need escaping. (Escaping is important for FreeMarker, as typically it
has to insert non-markup text from the data-model into the output markup. See also:
Configuration.setOutputFormat(OutputFormat)
.)
A MarkupOutputFormat
subclass always has a corresponding TemplateMarkupOutputModel
subclass pair
(like HTMLOutputFormat
has TemplateHTMLOutputModel
). The OutputFormat
implements the
operations related to TemplateMarkupOutputModel
objects of that kind, while the
TemplateMarkupOutputModel
only encapsulates the data (the actual markup or text).
To implement a custom output format, you may want to extend CommonMarkupOutputFormat
.
Modifier | Constructor and Description |
---|---|
protected |
MarkupOutputFormat() |
Modifier and Type | Method and Description |
---|---|
abstract MO |
concat(MO mo1,
MO mo2)
Returns a
TemplateMarkupOutputModel that contains the content of both TemplateMarkupOutputModel
objects concatenated. |
abstract java.lang.String |
escapePlainText(java.lang.String plainTextContent)
Should give the same result as
fromPlainTextByEscaping(String) and then
getMarkupString(TemplateMarkupOutputModel) , but the implementation may use a more efficient solution. |
abstract MO |
fromMarkup(java.lang.String markupText)
Wraps a
String that's already markup to TemplateMarkupOutputModel interface, to indicate its
format. |
abstract MO |
fromPlainTextByEscaping(java.lang.String textToEsc)
Converts a
String that's assumed to be plain text to TemplateMarkupOutputModel , by escaping any
special characters in the plain text. |
abstract java.lang.String |
getMarkupString(MO mo)
Returns the content as markup text; never
null . |
abstract java.lang.String |
getSourcePlainText(MO mo)
If this
TemplateMarkupOutputModel was created with fromPlainTextByEscaping(String) , it returns
the original plain text, otherwise it returns null . |
abstract boolean |
isAutoEscapedByDefault()
Tells if by default auto-escaping should be on for this format.
|
abstract boolean |
isEmpty(MO mo)
Returns if the markup is empty (0 length).
|
abstract boolean |
isLegacyBuiltInBypassed(java.lang.String builtInName)
Tells if a string built-in that can't handle a
TemplateMarkupOutputModel left hand operand can bypass
this object as is. |
abstract void |
output(MO mo,
java.io.Writer out)
Prints the parameter model to the output.
|
abstract void |
output(java.lang.String textToEsc,
java.io.Writer out)
Equivalent to calling
fromPlainTextByEscaping(String) and then
output(TemplateMarkupOutputModel, Writer) , but the implementation may use a more efficient solution. |
<MO2 extends TemplateMarkupOutputModel<MO2>> |
outputForeign(MO2 mo,
java.io.Writer out)
Outputs a value from a foreign output format; only used if
OutputFormat.isOutputFormatMixingAllowed() return
true . |
getMimeType, getName, isOutputFormatMixingAllowed, toString, toStringExtraProperties
public abstract MO fromPlainTextByEscaping(java.lang.String textToEsc) throws TemplateModelException
String
that's assumed to be plain text to TemplateMarkupOutputModel
, by escaping any
special characters in the plain text. This corresponds to ?esc
, or, to outputting with auto-escaping if
that wasn't using output(String, Writer)
as an optimization.public abstract MO fromMarkup(java.lang.String markupText) throws TemplateModelException
String
that's already markup to TemplateMarkupOutputModel
interface, to indicate its
format. This corresponds to ?noEsc
. (This methods is allowed to throw TemplateModelException
if
the parameter markup text is malformed, but it's unlikely that an implementation chooses to parse the parameter
until, and if ever, that becomes necessary.)TemplateModelException
getMarkupString(TemplateMarkupOutputModel)
public abstract void output(MO mo, java.io.Writer out) throws java.io.IOException, TemplateModelException
java.io.IOException
TemplateModelException
public abstract void output(java.lang.String textToEsc, java.io.Writer out) throws java.io.IOException, TemplateModelException
fromPlainTextByEscaping(String)
and then
output(TemplateMarkupOutputModel, Writer)
, but the implementation may use a more efficient solution.java.io.IOException
TemplateModelException
public <MO2 extends TemplateMarkupOutputModel<MO2>> void outputForeign(MO2 mo, java.io.Writer out) throws java.io.IOException, TemplateModelException
OutputFormat.isOutputFormatMixingAllowed()
return
true
. The default implementation in MarkupOutputFormat
will just let the other
OutputFormat
to output value, but it can be overridden to support more nuanced conversions, or to check if outputting without
conversion should be allowed.java.io.IOException
TemplateModelException
public abstract java.lang.String getSourcePlainText(MO mo) throws TemplateModelException
TemplateMarkupOutputModel
was created with fromPlainTextByEscaping(String)
, it returns
the original plain text, otherwise it returns null
. Useful for converting between different types
of markups, as if the source format can be converted to plain text without loss, then that just has to be
re-escaped with the target format to do the conversion.TemplateModelException
public abstract java.lang.String getMarkupString(MO mo) throws TemplateModelException
null
. If this TemplateMarkupOutputModel
was created
with fromMarkup(String)
, it might return the original markup text literally, but this is not required
as far as the returned markup means the same. If this TemplateMarkupOutputModel
wasn't created
with fromMarkup(String)
and it doesn't yet have the markup, it has to generate the markup now.TemplateModelException
public abstract MO concat(MO mo1, MO mo2) throws TemplateModelException
TemplateMarkupOutputModel
that contains the content of both TemplateMarkupOutputModel
objects concatenated.TemplateModelException
public abstract java.lang.String escapePlainText(java.lang.String plainTextContent) throws TemplateModelException
fromPlainTextByEscaping(String)
and then
getMarkupString(TemplateMarkupOutputModel)
, but the implementation may use a more efficient solution.TemplateModelException
public abstract boolean isEmpty(MO mo) throws TemplateModelException
?hasContent
.TemplateModelException
public abstract boolean isLegacyBuiltInBypassed(java.lang.String builtInName) throws TemplateModelException
TemplateMarkupOutputModel
left hand operand can bypass
this object as is. A typical such case would be when a TemplateHTMLOutputModel
of "HTML" format bypasses
?html
.TemplateModelException
public abstract boolean isAutoEscapedByDefault()
true
if you need to escape
on most of the places where you insert values.Configuration.setAutoEscapingPolicy(int)