Module com.aoapps.encoding.taglib
Class EncodingBufferedBodyTag
java.lang.Object
javax.servlet.jsp.tagext.TagSupport
javax.servlet.jsp.tagext.BodyTagSupport
com.aoapps.encoding.taglib.legacy.EncodingBufferedBodyTag
- All Implemented Interfaces:
Serializable,BodyTag,IterationTag,JspTag,Tag,TryCatchFinally
The exhibits all of the behavior of
EncodingFilteredBodyTag with
the only exception being that it buffers its content instead of using filters.
This allows the tag to capture its body. Character validation is performed
as the data goes into the buffer to ensure the captured data is correct for
its content type.
The tag also has the addition of a separate output type. Thus, we have three types involved:
- contentType - The characters are validated to this type as they go into the buffer.
- outputType - Our output characters are validated to this type as they are written.
- containerType - Our output characters are encoded to this type as they are written.
- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContentFields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContextFields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAGFields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAINFields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintDeprecated.protected intdoAfterBody(BufferResult capturedBody, Writer out) While the outJspWriteris still replaced to output the proper content type, this version ofdoAfterBody()is called.voidintdoEndTag()Deprecated.You should probably be implementing indoEndTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)protected intdoEndTag(BufferResult capturedBody, Writer out) While the outJspWriteris still replaced to output the proper content type, this version ofdoEndTag()is called.voidvoidThe only way to replace the "out" variable in the generated JSP is to useBodyTag.EVAL_BODY_BUFFERED.intDeprecated.You should probably be implementing indoStartTag(java.io.Writer)protected intdoStartTag(Writer out) Once the outJspWriterhas been replaced to output the proper content type, this version ofdoStartTag()is called.abstract MediaTypeGets the type of data that is contained by this tag.abstract MediaTypeGets the output type of this tag.longGets the number of characters that may be buffered before switching to the use of a temp file.protected voidsetMediaEncoderOptions(MediaEncoder mediaEncoder) Sets the media encoder options.protected voidwriteEncoderPrefix(MediaEncoder mediaEncoder, Writer out) protected voidwriteEncoderSuffix(MediaEncoder mediaEncoder, Writer out, boolean trim) protected voidwritePrefix(MediaType containerType, Writer out) Writes any prefix in the container's media type.protected voidwriteSuffix(MediaType containerType, Writer out) Writes any suffix in the container's media type.Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
getBodyContent, getPreviousOut, release, setBodyContentMethods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
-
Constructor Details
-
EncodingBufferedBodyTag
protected EncodingBufferedBodyTag()
-
-
Method Details
-
getContentType
Gets the type of data that is contained by this tag. -
getOutputType
Gets the output type of this tag. This is used to determine the correct encoder. If the tag never has any output this should returnnull. Whennullis returned, any output will result in an error. -
getTempFileThreshold
public long getTempFileThreshold()Gets the number of characters that may be buffered before switching to the use of a temp file.- Returns:
- the threshold or
Long.MAX_VALUEto never use temp files. - See Also:
-
doStartTag
Deprecated.You should probably be implementing indoStartTag(java.io.Writer)- Specified by:
doStartTagin interfaceTag- Overrides:
doStartTagin classBodyTagSupport- Throws:
JspException- See Also:
-
doStartTag
Once the outJspWriterhas been replaced to output the proper content type, this version ofdoStartTag()is called.- Parameters:
out- When the output type isnull, will throw an exception if anything written, otherwise validates all characters against the output type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Returns:
- Must return either
BodyTag.EVAL_BODY_BUFFERED(the default) orTag.SKIP_BODY - Throws:
JspExceptionIOException
-
doInitBody
The only way to replace the "out" variable in the generated JSP is to useBodyTag.EVAL_BODY_BUFFERED. Without this, any writer given toJspContext.pushBody(java.io.Writer)is not used. We want to both use our own buffer implementation as well as validate the data on-the-fly.To workaround this issue, this very hackily replaces the writer field directly on the
BodyContentImpl. When unable to replace the field, falls back to using the standard buffering (much less desirable).This is similar to the direct field access performed by
BodyContentImplCoercionOptimizerInitializer.- Specified by:
doInitBodyin interfaceBodyTag- Overrides:
doInitBodyin classBodyTagSupport- Throws:
JspException
-
doAfterBody
Deprecated.You should probably be implementing indoAfterBody(com.aoapps.io.buffer.BufferResult, java.io.Writer)- Specified by:
doAfterBodyin interfaceIterationTag- Overrides:
doAfterBodyin classBodyTagSupport- Throws:
JspException- See Also:
-
doAfterBody
While the outJspWriteris still replaced to output the proper content type, this version ofdoAfterBody()is called.- Parameters:
capturedBody- The buffered result of the most recent body invocation.out- When the output type isnull, will throw an exception if anything written, otherwise validates all characters against the output type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Returns:
- Must return either
Tag.SKIP_BODY(the default) orIterationTag.EVAL_BODY_AGAIN - Throws:
JspExceptionIOException
-
doEndTag
Deprecated.You should probably be implementing indoEndTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)- Specified by:
doEndTagin interfaceTag- Overrides:
doEndTagin classBodyTagSupport- Throws:
JspException- See Also:
-
doEndTag
While the outJspWriteris still replaced to output the proper content type, this version ofdoEndTag()is called.- Parameters:
capturedBody- The buffered result of the most recent body invocation orEmptyResult.getInstance()when body never invoked.out- When the output type isnull, will throw an exception if anything written, otherwise validates all characters against the output type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Returns:
- Must return either
Tag.EVAL_PAGE(the default) orTag.SKIP_PAGE - Throws:
JspExceptionIOException
-
doCatch
- Specified by:
doCatchin interfaceTryCatchFinally- Throws:
Throwable
-
doFinally
public void doFinally()- Specified by:
doFinallyin interfaceTryCatchFinally
-
writePrefix
Writes any prefix in the container's media type. The output must be valid for the provided type. This will not be called when the initial output type isnull.This default implementation prints nothing.
- Parameters:
out- Validates all characters against the container media type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Throws:
JspExceptionIOException- See Also:
-
setMediaEncoderOptions
Sets the media encoder options. This is how subclass tag attributes can effect the encoding. -
writeEncoderPrefix
protected void writeEncoderPrefix(MediaEncoder mediaEncoder, Writer out) throws JspException, IOException - Parameters:
out- Validates all characters against the container media type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Throws:
JspExceptionIOException
-
writeEncoderSuffix
protected void writeEncoderSuffix(MediaEncoder mediaEncoder, Writer out, boolean trim) throws JspException, IOException - Parameters:
out- Validates all characters against the container media type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Throws:
JspExceptionIOException
-
writeSuffix
Writes any suffix in the container's media type. The output must be valid for the provided type. This will not be called when the initial output type isnull.This default implementation prints nothing.
- Parameters:
out- Validates all characters against the container media type. Already optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder).- Throws:
JspExceptionIOException- See Also:
-

doAfterBody(com.aoapps.io.buffer.BufferResult, java.io.Writer)