Class EncodingFilteredBodyTag
- All Implemented Interfaces:
Serializable
,BodyTag
,IterationTag
,JspTag
,Tag
,TryCatchFinally
- Direct Known Subclasses:
EncodingTag
,JavaScriptTag
,JsonTag
,LdJsonTag
,MysqlTag
,PsqlTag
,ShTag
,StyleTag
,TextTag
,UrlTag
,XhtmlAttributeTag
,XhtmlTag
An implementation of BodyTagSupport
that automatically validates its
content and automatically encodes its output correctly given its context.
It also validates its own output when used in a non-validating context. For
higher performance, it filters the output from its body instead of buffering.
The content validation is primarily focused on making sure the contained data is properly encoded. This is to avoid data corruption or intermingling of data and code. It does not go through great lengths such as ensuring that XHTML Strict is valid or JavaScript will run correctly.
In additional to checking that its contents are well behaved, it also is
well behaved for its container by properly encoding its output for its
context. To determine its context, it uses the content type of the currently
registered RequestEncodingContext
to perform proper encoding.
If it fails to find any such context, it uses the content type of the
HttpServletResponse
.
Finally, if no existing RequestEncodingContext
is found, this will
validate its own output against the content type of the
HttpServletResponse
to make sure it is well-behaved.
- 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
(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(java.io.Writer)
protected int
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.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
-
Field Details
-
EVAL_BODY_FILTERED
public static final int EVAL_BODY_FILTEREDReturn value fordoStartTag(java.io.Writer)
. It will be converted to eitherTag.EVAL_BODY_INCLUDE
orBodyTag.EVAL_BODY_BUFFERED
, as appropriate to the given filtering and validation.- See Also:
-
-
Constructor Details
-
EncodingFilteredBodyTag
protected EncodingFilteredBodyTag()
-
-
Method Details
-
getContentType
Gets the type of data that is contained by this tag. This is used to determine the correct encoder. This is also the output type. -
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
EVAL_BODY_FILTERED
(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 don't actually want to buffer the content, but only want to filter and 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(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:
out
- Validates all characters against the content 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(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:
out
- Validates all characters against the content 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 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
-
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 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
-
doAfterBody(java.io.Writer)