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
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
MarkupOutputFormatsubclass always has a correspondingTemplateMarkupOutputModelsubclass pair (likeHTMLOutputFormathasTemplateHTMLOutputModel). TheOutputFormatimplements the operations related toTemplateMarkupOutputModelobjects of that kind, while theTemplateMarkupOutputModelonly 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 protectedMarkupOutputFormat()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract MOconcat(MO mo1, MO mo2)Returns aTemplateMarkupOutputModelthat contains the content of bothTemplateMarkupOutputModelobjects concatenated.abstract java.lang.StringescapePlainText(java.lang.String plainTextContent)Should give the same result asfromPlainTextByEscaping(String)and thengetMarkupString(TemplateMarkupOutputModel), but the implementation may uses a more efficient solution.abstract MOfromMarkup(java.lang.String markupText)Wraps aStringthat's already markup toTemplateMarkupOutputModelinterface, to indicate its format.abstract MOfromPlainTextByEscaping(java.lang.String textToEsc)Converts aStringthat's assumed to be plain text toTemplateMarkupOutputModel, by escaping any special characters in the plain text.abstract java.lang.StringgetMarkupString(MO mo)Returns the content as markup text; nevernull.abstract java.lang.StringgetSourcePlainText(MO mo)If thisTemplateMarkupOutputModelwas created withfromPlainTextByEscaping(String), it returns the original plain text, otherwise it returnsnull.abstract booleanisAutoEscapedByDefault()Tells if by default auto-escaping should be on for this format.abstract booleanisEmpty(MO mo)Returns if the markup is empty (0 length).abstract booleanisLegacyBuiltInBypassed(java.lang.String builtInName)Tells if a string built-in that can't handle aTemplateMarkupOutputModelleft hand operand can bypass this object as is.abstract voidoutput(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 voidoutput(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 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
public abstract MO fromMarkup(java.lang.String markupText) throws TemplateModelException
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
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.IOExceptionTemplateModelException
-
output
public abstract void output(java.lang.String textToEsc, java.io.Writer out) throws java.io.IOException, TemplateModelExceptionEquivalent to callingfromPlainTextByEscaping(String)and thenoutput(TemplateMarkupOutputModel, Writer), but the implementation may uses a more efficient solution.- Throws:
java.io.IOExceptionTemplateModelException
-
getSourcePlainText
public abstract java.lang.String getSourcePlainText(MO mo) throws TemplateModelException
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
public abstract java.lang.String getMarkupString(MO mo) throws TemplateModelException
Returns the content as markup text; nevernull. If thisTemplateMarkupOutputModelwas 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 thisTemplateMarkupOutputModelwasn'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 aTemplateMarkupOutputModelthat contains the content of bothTemplateMarkupOutputModelobjects concatenated.- Throws:
TemplateModelException
-
escapePlainText
public abstract java.lang.String escapePlainText(java.lang.String plainTextContent) throws TemplateModelExceptionShould 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 TemplateModelExceptionTells 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)
-
-