Package freemarker.core
Class MarkupOutputFormat<MO extends TemplateMarkupOutputModel>
- java.lang.Object
-
- freemarker.core.OutputFormat
-
- freemarker.core.MarkupOutputFormat<MO>
-
- Type Parameters:
MO
- TheTemplateMarkupOutputModel
class this output format can deal with.
- Direct Known Subclasses:
CommonMarkupOutputFormat
public abstract class MarkupOutputFormat<MO extends TemplateMarkupOutputModel> extends OutputFormat
Superclass ofOutputFormat
-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 correspondingTemplateMarkupOutputModel
subclass pair (likeHTMLOutputFormat
hasTemplateHTMLOutputModel
). TheOutputFormat
implements the operations related toTemplateMarkupOutputModel
objects of that kind, while theTemplateMarkupOutputModel
only encapsulates the data (the actual markup or text).To implement a custom output format, you may want to extend
CommonMarkupOutputFormat
.- Since:
- 2.3.24
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MarkupOutputFormat()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract MO
concat(MO mo1, MO mo2)
Returns aTemplateMarkupOutputModel
that contains the content of bothTemplateMarkupOutputModel
objects concatenated.abstract java.lang.String
escapePlainText(java.lang.String plainTextContent)
Should give the same result asfromPlainTextByEscaping(String)
and thengetMarkupString(TemplateMarkupOutputModel)
, but the implementation may uses a more efficient solution.abstract MO
fromMarkup(java.lang.String markupText)
Wraps aString
that's already markup toTemplateMarkupOutputModel
interface, to indicate its format.abstract MO
fromPlainTextByEscaping(java.lang.String textToEsc)
Converts aString
that's assumed to be plain text toTemplateMarkupOutputModel
, by escaping any special characters in the plain text.abstract java.lang.String
getMarkupString(MO mo)
Returns the content as markup text; nevernull
.abstract java.lang.String
getSourcePlainText(MO mo)
If thisTemplateMarkupOutputModel
was created withfromPlainTextByEscaping(String)
, it returns the original plain text, otherwise it returnsnull
.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 aTemplateMarkupOutputModel
left hand operand can bypass this object as is.abstract void
output(java.lang.String textToEsc, java.io.Writer out)
Equivalent to callingfromPlainTextByEscaping(String)
and thenoutput(TemplateMarkupOutputModel, Writer)
, but the implementation may uses a more efficient solution.abstract void
output(MO mo, java.io.Writer out)
Prints the parameter model to the output.-
Methods inherited from class freemarker.core.OutputFormat
getMimeType, getName, isOutputFormatMixingAllowed, toString, toStringExtraProperties
-
-
-
-
Method Detail
-
fromPlainTextByEscaping
public abstract MO fromPlainTextByEscaping(java.lang.String textToEsc) throws TemplateModelException
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 usingoutput(String, Writer)
as an optimization.
-
fromMarkup
public abstract MO fromMarkup(java.lang.String markupText) throws TemplateModelException
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.)- Throws:
TemplateModelException
- See Also:
getMarkupString(TemplateMarkupOutputModel)
-
output
public abstract void output(MO mo, java.io.Writer out) throws java.io.IOException, TemplateModelException
Prints the parameter model to the output.- Throws:
java.io.IOException
TemplateModelException
-
output
public abstract void output(java.lang.String textToEsc, java.io.Writer out) throws java.io.IOException, TemplateModelException
Equivalent to callingfromPlainTextByEscaping(String)
and thenoutput(TemplateMarkupOutputModel, Writer)
, but the implementation may uses a more efficient solution.- Throws:
java.io.IOException
TemplateModelException
-
getSourcePlainText
public abstract java.lang.String getSourcePlainText(MO mo) throws TemplateModelException
If thisTemplateMarkupOutputModel
was created withfromPlainTextByEscaping(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.- Throws:
TemplateModelException
-
getMarkupString
public abstract java.lang.String getMarkupString(MO mo) throws TemplateModelException
Returns the content as markup text; nevernull
. If thisTemplateMarkupOutputModel
was created withfromMarkup(String)
, it might returns the original markup text literally, but this is not required as far as the returned markup means the same. If thisTemplateMarkupOutputModel
wasn't created withfromMarkup(String)
and it doesn't yet have the markup, it has to generate the markup now.- Throws:
TemplateModelException
-
concat
public abstract MO concat(MO mo1, MO mo2) throws TemplateModelException
Returns aTemplateMarkupOutputModel
that contains the content of bothTemplateMarkupOutputModel
objects concatenated.- Throws:
TemplateModelException
-
escapePlainText
public abstract java.lang.String escapePlainText(java.lang.String plainTextContent) throws TemplateModelException
Should give the same result asfromPlainTextByEscaping(String)
and thengetMarkupString(TemplateMarkupOutputModel)
, but the implementation may uses a more efficient solution.- Throws:
TemplateModelException
-
isEmpty
public abstract boolean isEmpty(MO mo) throws TemplateModelException
Returns if the markup is empty (0 length). This is used by at least?hasContent
.- Throws:
TemplateModelException
-
isLegacyBuiltInBypassed
public abstract boolean isLegacyBuiltInBypassed(java.lang.String builtInName) throws TemplateModelException
Tells if a string built-in that can't handle aTemplateMarkupOutputModel
left hand operand can bypass this object as is. A typical such case would be when aTemplateHTMLOutputModel
of "HTML" format bypasses?html
.- Throws:
TemplateModelException
-
isAutoEscapedByDefault
public abstract boolean isAutoEscapedByDefault()
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.- See Also:
Configuration.setAutoEscapingPolicy(int)
-
-