Class CommonMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Direct Known Subclasses:
CombinedMarkupOutputFormat
,HTMLOutputFormat
,RTFOutputFormat
,XMLOutputFormat
MarkupOutputFormat
-s that use a CommonTemplateMarkupOutputModel
subclass.- Since:
- 2.3.24
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns aTemplateMarkupOutputModel
that contains the content of bothTemplateMarkupOutputModel
objects concatenated.fromMarkup(String markupText)
Wraps aString
that's already markup toTemplateMarkupOutputModel
interface, to indicate its format.fromPlainTextByEscaping(String textToEsc)
Converts aString
that's assumed to be plain text toTemplateMarkupOutputModel
, by escaping any special characters in the plain text.getMarkupString(MO mo)
Returns the content as markup text; nevernull
.getSourcePlainText(MO mo)
If thisTemplateMarkupOutputModel
was created withMarkupOutputFormat.fromPlainTextByEscaping(String)
, it returns the original plain text, otherwise it returnsnull
.boolean
Tells if by default auto-escaping should be on for this format.boolean
Returns if the markup is empty (0 length).boolean
Tells if this output format allows insertingTemplateMarkupOutputModel
-s of another output formats into it.protected abstract MO
newTemplateMarkupOutputModel(String plainTextContent, String markupContent)
Creates a newCommonTemplateMarkupOutputModel
that's bound to thisOutputFormat
instance.abstract void
Equivalent to callingMarkupOutputFormat.fromPlainTextByEscaping(String)
and thenMarkupOutputFormat.output(TemplateMarkupOutputModel, Writer)
, but the implementation may use a more efficient solution.void
Prints the parameter model to the output.Methods inherited from class freemarker.core.MarkupOutputFormat
escapePlainText, isLegacyBuiltInBypassed, outputForeign
Methods inherited from class freemarker.core.OutputFormat
getMimeType, getName, toString, toStringExtraProperties
-
Constructor Details
-
CommonMarkupOutputFormat
protected CommonMarkupOutputFormat()
-
-
Method Details
-
fromPlainTextByEscaping
Description copied from class:MarkupOutputFormat
Converts aString
that's assumed to be plain text toTemplateMarkupOutputModel
, by escaping any special characters in the plain text. This corresponds to?esc
, or, to outputting with auto-escaping if that wasn't usingMarkupOutputFormat.output(String, Writer)
as an optimization.- Specified by:
fromPlainTextByEscaping
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
TemplateModelException
- See Also:
MarkupOutputFormat.escapePlainText(String)
,MarkupOutputFormat.getSourcePlainText(TemplateMarkupOutputModel)
-
fromMarkup
Description copied from class:MarkupOutputFormat
Wraps aString
that's already markup toTemplateMarkupOutputModel
interface, to indicate its format. This corresponds to?noEsc
. (This methods is allowed to throwTemplateModelException
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.)- Specified by:
fromMarkup
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
TemplateModelException
- See Also:
MarkupOutputFormat.getMarkupString(TemplateMarkupOutputModel)
-
output
Description copied from class:MarkupOutputFormat
Prints the parameter model to the output.- Specified by:
output
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
IOException
TemplateModelException
-
output
public abstract void output(String textToEsc, Writer out) throws IOException, TemplateModelExceptionDescription copied from class:MarkupOutputFormat
Equivalent to callingMarkupOutputFormat.fromPlainTextByEscaping(String)
and thenMarkupOutputFormat.output(TemplateMarkupOutputModel, Writer)
, but the implementation may use a more efficient solution.- Specified by:
output
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
IOException
TemplateModelException
-
getSourcePlainText
Description copied from class:MarkupOutputFormat
If thisTemplateMarkupOutputModel
was created withMarkupOutputFormat.fromPlainTextByEscaping(String)
, it returns the original plain text, otherwise it returnsnull
. 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.- Specified by:
getSourcePlainText
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
TemplateModelException
-
getMarkupString
Description copied from class:MarkupOutputFormat
Returns the content as markup text; nevernull
. If thisTemplateMarkupOutputModel
was created withMarkupOutputFormat.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 thisTemplateMarkupOutputModel
wasn't created withMarkupOutputFormat.fromMarkup(String)
and it doesn't yet have the markup, it has to generate the markup now.- Specified by:
getMarkupString
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
TemplateModelException
-
concat
Description copied from class:MarkupOutputFormat
Returns aTemplateMarkupOutputModel
that contains the content of bothTemplateMarkupOutputModel
objects concatenated.- Specified by:
concat
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
TemplateModelException
-
isEmpty
Description copied from class:MarkupOutputFormat
Returns if the markup is empty (0 length). This is used by at least?hasContent
.- Specified by:
isEmpty
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- Throws:
TemplateModelException
-
isOutputFormatMixingAllowed
public boolean isOutputFormatMixingAllowed()Description copied from class:OutputFormat
Tells if this output format allows insertingTemplateMarkupOutputModel
-s of another output formats into it.If
true
, the foreignTemplateMarkupOutputModel
will be inserted into the output. If the current output format is aMarkupOutputFormat
this is done using theMarkupOutputFormat.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 byUndefinedOutputFormat
.- Specified by:
isOutputFormatMixingAllowed
in classOutputFormat
-
isAutoEscapedByDefault
public boolean isAutoEscapedByDefault()Description copied from class:MarkupOutputFormat
Tells if by default auto-escaping should be on for this format. It should betrue
if you need to escape on most of the places where you insert values.- Specified by:
isAutoEscapedByDefault
in classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
- See Also:
Configuration.setAutoEscapingPolicy(int)
-
newTemplateMarkupOutputModel
protected abstract MO newTemplateMarkupOutputModel(String plainTextContent, String markupContent) throws TemplateModelExceptionCreates a newCommonTemplateMarkupOutputModel
that's bound to thisOutputFormat
instance. When this is called fromCommonMarkupOutputFormat
, exactly one of the parameters will be non-null
.- Parameters:
plainTextContent
-null
if the content is markup that possibly can be described as plain text without loss.markupContent
- Typically will benull
ifplainTextContent
is notnull
. While the plain text always can be converted to markup viaMarkupOutputFormat.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 whengetMarkupString(CommonTemplateMarkupOutputModel)
is called).- Throws:
TemplateModelException
-