Package freemarker.core
Class MarkupOutputFormat<MO extends TemplateMarkupOutputModel>
java.lang.Object
freemarker.core.OutputFormat
freemarker.core.MarkupOutputFormat<MO>
- Type Parameters:
MO- TheTemplateMarkupOutputModelclass this output format can deal with.
- Direct Known Subclasses:
CommonMarkupOutputFormat
Superclass of
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.
- Since:
- 2.3.24
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract MOReturns aTemplateMarkupOutputModelthat contains the content of bothTemplateMarkupOutputModelobjects concatenated.abstract StringescapePlainText(String plainTextContent)Should give the same result asfromPlainTextByEscaping(String)and thengetMarkupString(TemplateMarkupOutputModel), but the implementation may use a more efficient solution.abstract MOfromMarkup(String markupText)Wraps aStringthat's already markup toTemplateMarkupOutputModelinterface, to indicate its format.abstract MOfromPlainTextByEscaping(String textToEsc)Converts aStringthat's assumed to be plain text toTemplateMarkupOutputModel, by escaping any special characters in the plain text.abstract StringgetMarkupString(MO mo)Returns the content as markup text; nevernull.abstract StringgetSourcePlainText(MO mo)If thisTemplateMarkupOutputModelwas created withfromPlainTextByEscaping(String), it returns the original plain text, otherwise it returnsnull.abstract booleanTells if by default auto-escaping should be on for this format.abstract booleanReturns if the markup is empty (0 length).abstract booleanisLegacyBuiltInBypassed(String builtInName)Tells if a string built-in that can't handle aTemplateMarkupOutputModelleft hand operand can bypass this object as is.abstract voidEquivalent to callingfromPlainTextByEscaping(String)and thenoutput(TemplateMarkupOutputModel, Writer), but the implementation may use a more efficient solution.abstract voidPrints the parameter model to the output.<MO2 extends TemplateMarkupOutputModel<MO2>>
voidoutputForeign(MO2 mo, Writer out)Outputs a value from a foreign output format; only used ifOutputFormat.isOutputFormatMixingAllowed()returntrue.Methods inherited from class freemarker.core.OutputFormat
getMimeType, getName, isOutputFormatMixingAllowed, toString, toStringExtraProperties
-
Constructor Details
-
MarkupOutputFormat
protected MarkupOutputFormat()
-
-
Method Details
-
fromPlainTextByEscaping
Converts aStringthat'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
Wraps aStringthat's already markup toTemplateMarkupOutputModelinterface, to indicate its format. This corresponds to?noEsc. (This methods is allowed to throwTemplateModelExceptionif 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
Prints the parameter model to the output.- Throws:
IOExceptionTemplateModelException
-
output
public abstract void output(String textToEsc, Writer out) throws IOException, TemplateModelExceptionEquivalent to callingfromPlainTextByEscaping(String)and thenoutput(TemplateMarkupOutputModel, Writer), but the implementation may use a more efficient solution.- Throws:
IOExceptionTemplateModelException
-
outputForeign
public <MO2 extends TemplateMarkupOutputModel<MO2>> void outputForeign(MO2 mo, Writer out) throws IOException, TemplateModelExceptionOutputs a value from a foreign output format; only used ifOutputFormat.isOutputFormatMixingAllowed()returntrue. The default implementation inMarkupOutputFormatwill just let the otherOutputFormatto output value, but it can be overridden to support more nuanced conversions, or to check if outputting without conversion should be allowed.- Throws:
IOExceptionTemplateModelException- Since:
- 2.3.32
-
getSourcePlainText
If thisTemplateMarkupOutputModelwas 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
Returns the content as markup text; nevernull. If thisTemplateMarkupOutputModelwas created withfromMarkup(String), it might return the original markup text literally, but this is not required as far as the returned markup means the same. If thisTemplateMarkupOutputModelwasn't created withfromMarkup(String)and it doesn't yet have the markup, it has to generate the markup now.- Throws:
TemplateModelException
-
concat
Returns aTemplateMarkupOutputModelthat contains the content of bothTemplateMarkupOutputModelobjects concatenated.- Throws:
TemplateModelException
-
escapePlainText
Should give the same result asfromPlainTextByEscaping(String)and thengetMarkupString(TemplateMarkupOutputModel), but the implementation may use a more efficient solution.- Throws:
TemplateModelException
-
isEmpty
Returns if the markup is empty (0 length). This is used by at least?hasContent.- Throws:
TemplateModelException
-
isLegacyBuiltInBypassed
Tells if a string built-in that can't handle aTemplateMarkupOutputModelleft hand operand can bypass this object as is. A typical such case would be when aTemplateHTMLOutputModelof "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 betrueif you need to escape on most of the places where you insert values.- See Also:
Configuration.setAutoEscapingPolicy(int)
-