Class 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
bodyContent
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Deprecated.protected int
doAfterBody
(BufferResult capturedBody, Writer out) While the outJspWriter
is still replaced to output the proper content type, this version ofdoAfterBody()
is called.void
int
doEndTag()
Deprecated.You should probably be implementing indoEndTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)
protected int
doEndTag
(BufferResult capturedBody, Writer out) While the outJspWriter
is still replaced to output the proper content type, this version ofdoEndTag()
is called.void
void
The only way to replace the "out" variable in the generated JSP is to useBodyTag.EVAL_BODY_BUFFERED
.int
Deprecated.You should probably be implementing indoStartTag(java.io.Writer)
protected int
doStartTag
(Writer out) Once the outJspWriter
has been replaced to output the proper content type, this version ofdoStartTag()
is called.abstract MediaType
Gets the type of data that is contained by this tag.abstract MediaType
Gets the output type of this tag.long
Gets the number of characters that may be buffered before switching to the use of a temp file.protected void
setMediaEncoderOptions
(MediaEncoder mediaEncoder) Sets the media encoder options.protected void
writeEncoderPrefix
(MediaEncoder mediaEncoder, Writer out) protected void
writeEncoderSuffix
(MediaEncoder mediaEncoder, Writer out, boolean trim) protected void
writePrefix
(MediaType containerType, Writer out) Writes any prefix in the container's media type.protected void
writeSuffix
(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, setBodyContent
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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
. Whennull
is 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_VALUE
to never use temp files. - See Also:
-
doStartTag
Deprecated.You should probably be implementing indoStartTag(java.io.Writer)
- Specified by:
doStartTag
in interfaceTag
- Overrides:
doStartTag
in classBodyTagSupport
- Throws:
JspException
- See Also:
-
doStartTag
Once the outJspWriter
has 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:
JspException
IOException
-
doInitBody
The only way to replace the "out" variable in the generated JSP is to use
BodyTag.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:
doInitBody
in interfaceBodyTag
- Overrides:
doInitBody
in classBodyTagSupport
- Throws:
JspException
-
doAfterBody
Deprecated.You should probably be implementing indoAfterBody(com.aoapps.io.buffer.BufferResult, java.io.Writer)
- Specified by:
doAfterBody
in interfaceIterationTag
- Overrides:
doAfterBody
in classBodyTagSupport
- Throws:
JspException
- See Also:
-
doAfterBody
While the outJspWriter
is 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:
JspException
IOException
-
doEndTag
Deprecated.You should probably be implementing indoEndTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)
- Specified by:
doEndTag
in interfaceTag
- Overrides:
doEndTag
in classBodyTagSupport
- Throws:
JspException
- See Also:
-
doEndTag
While the outJspWriter
is 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:
JspException
IOException
-
doCatch
- Specified by:
doCatch
in interfaceTryCatchFinally
- Throws:
Throwable
-
doFinally
public void doFinally()- Specified by:
doFinally
in 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 is
null
.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:
JspException
IOException
- 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:
JspException
IOException
-
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:
JspException
IOException
-
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 is
null
.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:
JspException
IOException
- See Also:
-
doAfterBody(com.aoapps.io.buffer.BufferResult, java.io.Writer)