Package freemarker.core
Class CommonMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
java.lang.Object
freemarker.core.OutputFormat
freemarker.core.MarkupOutputFormat<MO>
freemarker.core.CommonMarkupOutputFormat<MO>
- Direct Known Subclasses:
CombinedMarkupOutputFormat,HTMLOutputFormat,RTFOutputFormat,XMLOutputFormat
public abstract class CommonMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>
extends MarkupOutputFormat<MO>
Common superclass for implementing
MarkupOutputFormat-s that use a CommonTemplateMarkupOutputModel
subclass.- Since:
- 2.3.24
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal MOReturns aTemplateMarkupOutputModelthat contains the content of bothTemplateMarkupOutputModelobjects concatenated.final MOfromMarkup(String markupText) Wraps aStringthat's already markup toTemplateMarkupOutputModelinterface, to indicate its format.final MOfromPlainTextByEscaping(String textToEsc) Converts aStringthat's assumed to be plain text toTemplateMarkupOutputModel, by escaping any special characters in the plain text.final StringgetMarkupString(MO mo) Returns the content as markup text; nevernull.final StringgetSourcePlainText(MO mo) If thisTemplateMarkupOutputModelwas created withMarkupOutputFormat.fromPlainTextByEscaping(String), it returns the original plain text, otherwise it returnsnull.booleanTells if by default auto-escaping should be on for this format.booleanReturns if the markup is empty (0 length).booleanTells if this output format allows insertingTemplateMarkupOutputModel-s of another output formats into it.protected abstract MOnewTemplateMarkupOutputModel(String plainTextContent, String markupContent) Creates a newCommonTemplateMarkupOutputModelthat's bound to thisOutputFormatinstance.abstract voidEquivalent to callingMarkupOutputFormat.fromPlainTextByEscaping(String)and thenMarkupOutputFormat.output(TemplateMarkupOutputModel, Writer), but the implementation may uses a more efficient solution.final voidPrints the parameter model to the output.Methods inherited from class freemarker.core.MarkupOutputFormat
escapePlainText, isLegacyBuiltInBypassedMethods inherited from class freemarker.core.OutputFormat
getMimeType, getName, toString, toStringExtraProperties
-
Constructor Details
-
CommonMarkupOutputFormat
protected CommonMarkupOutputFormat()
-
-
Method Details
-
fromPlainTextByEscaping
Description copied from class:MarkupOutputFormatConverts 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 usingMarkupOutputFormat.output(String, Writer)as an optimization.- Specified by:
fromPlainTextByEscapingin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
TemplateModelException- See Also:
-
fromMarkup
Description copied from class:MarkupOutputFormatWraps 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.)- Specified by:
fromMarkupin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
TemplateModelException- See Also:
-
output
Description copied from class:MarkupOutputFormatPrints the parameter model to the output.- Specified by:
outputin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
IOExceptionTemplateModelException
-
output
public abstract void output(String textToEsc, Writer out) throws IOException, TemplateModelException Description copied from class:MarkupOutputFormatEquivalent to callingMarkupOutputFormat.fromPlainTextByEscaping(String)and thenMarkupOutputFormat.output(TemplateMarkupOutputModel, Writer), but the implementation may uses a more efficient solution.- Specified by:
outputin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
IOExceptionTemplateModelException
-
getSourcePlainText
Description copied from class:MarkupOutputFormatIf thisTemplateMarkupOutputModelwas 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:
getSourcePlainTextin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
TemplateModelException
-
getMarkupString
Description copied from class:MarkupOutputFormatReturns the content as markup text; nevernull. If thisTemplateMarkupOutputModelwas created withMarkupOutputFormat.fromMarkup(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 withMarkupOutputFormat.fromMarkup(String)and it doesn't yet have the markup, it has to generate the markup now.- Specified by:
getMarkupStringin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
TemplateModelException
-
concat
Description copied from class:MarkupOutputFormatReturns aTemplateMarkupOutputModelthat contains the content of bothTemplateMarkupOutputModelobjects concatenated.- Specified by:
concatin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
TemplateModelException
-
isEmpty
Description copied from class:MarkupOutputFormatReturns if the markup is empty (0 length). This is used by at least?hasContent.- Specified by:
isEmptyin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- Throws:
TemplateModelException
-
isOutputFormatMixingAllowed
public boolean isOutputFormatMixingAllowed()Description copied from class:OutputFormatTells if this output format allows insertingTemplateMarkupOutputModel-s of another output formats into it. Iftrue, the foreignTemplateMarkupOutputModelwill be inserted into the output as is (like 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 returnsfalse(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.)truevalue is used byUndefinedOutputFormat.- Specified by:
isOutputFormatMixingAllowedin classOutputFormat
-
isAutoEscapedByDefault
public boolean isAutoEscapedByDefault()Description copied from class:MarkupOutputFormatTells 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.- Specified by:
isAutoEscapedByDefaultin classMarkupOutputFormat<MO extends CommonTemplateMarkupOutputModel>- See Also:
-
newTemplateMarkupOutputModel
protected abstract MO newTemplateMarkupOutputModel(String plainTextContent, String markupContent) throws TemplateModelException Creates a newCommonTemplateMarkupOutputModelthat's bound to thisOutputFormatinstance.- Throws:
TemplateModelException
-