public abstract class CommonMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel> extends MarkupOutputFormat<MO>
MarkupOutputFormat
-s that use a CommonTemplateMarkupOutputModel
subclass.Modifier | Constructor and Description |
---|---|
protected |
CommonMarkupOutputFormat() |
Modifier and Type | Method and Description |
---|---|
MO |
concat(MO mo1,
MO mo2)
Returns a
TemplateMarkupOutputModel that contains the content of both TemplateMarkupOutputModel
objects concatenated. |
MO |
fromMarkup(java.lang.String markupText)
Wraps a
String that's already markup to TemplateMarkupOutputModel interface, to indicate its
format. |
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. |
java.lang.String |
getMarkupString(MO mo)
Returns the content as markup text; never
null . |
java.lang.String |
getSourcePlainText(MO mo)
If this
TemplateMarkupOutputModel was created with MarkupOutputFormat.fromPlainTextByEscaping(String) , it returns
the original plain text, otherwise it returns null . |
boolean |
isAutoEscapedByDefault()
Tells if by default auto-escaping should be on for this format.
|
boolean |
isEmpty(MO mo)
Returns if the markup is empty (0 length).
|
boolean |
isOutputFormatMixingAllowed()
Tells if this output format allows inserting
TemplateMarkupOutputModel -s of another output formats into
it. |
protected abstract MO |
newTemplateMarkupOutputModel(java.lang.String plainTextContent,
java.lang.String markupContent)
Creates a new
CommonTemplateMarkupOutputModel that's bound to this OutputFormat instance. |
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
MarkupOutputFormat.fromPlainTextByEscaping(String) and then
MarkupOutputFormat.output(TemplateMarkupOutputModel, Writer) , but the implementation may use a more efficient solution. |
escapePlainText, isLegacyBuiltInBypassed, outputForeign
getMimeType, getName, toString, toStringExtraProperties
public final MO fromPlainTextByEscaping(java.lang.String textToEsc) throws TemplateModelException
MarkupOutputFormat
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 MarkupOutputFormat.output(String, Writer)
as an optimization.fromPlainTextByEscaping
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
TemplateModelException
MarkupOutputFormat.escapePlainText(String)
,
MarkupOutputFormat.getSourcePlainText(TemplateMarkupOutputModel)
public final MO fromMarkup(java.lang.String markupText) throws TemplateModelException
MarkupOutputFormat
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.)fromMarkup
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
TemplateModelException
MarkupOutputFormat.getMarkupString(TemplateMarkupOutputModel)
public final void output(MO mo, java.io.Writer out) throws java.io.IOException, TemplateModelException
MarkupOutputFormat
output
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
java.io.IOException
TemplateModelException
public abstract void output(java.lang.String textToEsc, java.io.Writer out) throws java.io.IOException, TemplateModelException
MarkupOutputFormat
MarkupOutputFormat.fromPlainTextByEscaping(String)
and then
MarkupOutputFormat.output(TemplateMarkupOutputModel, Writer)
, but the implementation may use a more efficient solution.output
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
java.io.IOException
TemplateModelException
public final java.lang.String getSourcePlainText(MO mo) throws TemplateModelException
MarkupOutputFormat
TemplateMarkupOutputModel
was created with MarkupOutputFormat.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.getSourcePlainText
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
TemplateModelException
public final java.lang.String getMarkupString(MO mo) throws TemplateModelException
MarkupOutputFormat
null
. If this TemplateMarkupOutputModel
was created
with MarkupOutputFormat.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 MarkupOutputFormat.fromMarkup(String)
and it doesn't yet have the markup, it has to generate the markup now.getMarkupString
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
TemplateModelException
public final MO concat(MO mo1, MO mo2) throws TemplateModelException
MarkupOutputFormat
TemplateMarkupOutputModel
that contains the content of both TemplateMarkupOutputModel
objects concatenated.concat
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
TemplateModelException
public boolean isEmpty(MO mo) throws TemplateModelException
MarkupOutputFormat
?hasContent
.isEmpty
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
TemplateModelException
public boolean isOutputFormatMixingAllowed()
OutputFormat
TemplateMarkupOutputModel
-s of another output formats into
it.
If true
, the foreign TemplateMarkupOutputModel
will be inserted into the output. If the current
output format is a MarkupOutputFormat
this is done using the
MarkupOutputFormat.outputForeign(TemplateMarkupOutputModel, Writer)
method, which can implement smart
conversions. The default behavior (and the only behavior for non-markup outputs) is to behave as if the surrounding
output format was the same; this is usually a bad idea to allow, as such an event could
indicate application bugs.
If this method returns false
(recommended), then FreeMarker will try to assimilate the inserted value by
converting its format to this format, which will currently (2.3.24) cause exception, unless the inserted value is
made by escaping plain text and the target format is non-escaping, in which case format conversion is trivially
possible. (It's not impossible that conversions will be extended beyond this, if there will be demand for that.)
true
value is used by UndefinedOutputFormat
.
isOutputFormatMixingAllowed
in class OutputFormat
public boolean isAutoEscapedByDefault()
MarkupOutputFormat
true
if you need to escape
on most of the places where you insert values.isAutoEscapedByDefault
in class MarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
Configuration.setAutoEscapingPolicy(int)
protected abstract MO newTemplateMarkupOutputModel(java.lang.String plainTextContent, java.lang.String markupContent) throws TemplateModelException
CommonTemplateMarkupOutputModel
that's bound to this OutputFormat
instance.
When this is called from CommonMarkupOutputFormat
, exactly one of the parameters will be
non-null
.plainTextContent
- null
if the content is markup that possibly can be described as plain text without loss.markupContent
- Typically will be null
if plainTextContent
is not null
. While the plain text always
can be converted to markup via MarkupOutputFormat.escapePlainText(String)
, it's up to the implementation if it wants
to do that now and store the markup, or later on demand (like each time when
getMarkupString(CommonTemplateMarkupOutputModel)
is called).TemplateModelException