- java.lang.Object
-
- javax.servlet.jsp.tagext.SimpleTagSupport
-
- com.aoapps.encoding.taglib.EncodingBufferedTag
-
public abstract class EncodingBufferedTag extends SimpleTagSupport
The exhibits all of the behavior of
EncodingFilteredTag
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.
-
-
Constructor Summary
Constructors Constructor Description EncodingBufferedTag()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
doTag()
Deprecated.You should probably be implementing indoTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)
protected void
doTag(BufferResult capturedBody, Writer out)
abstract MediaType
getContentType()
Gets the type of data that is contained by this tag.abstract MediaType
getOutputType()
Gets the output type of this tag.long
getTempFileThreshold()
Gets the number of characters that may be buffered before switching to the use of a temp file.protected void
invoke(JspFragment body, MediaValidator captureValidator)
Invokes the body.static BufferWriter
newBufferWriter(TempFileContext tempFileContext)
static BufferWriter
newBufferWriter(TempFileContext tempFileContext, long tempFileThreshold)
Creates an instance of the currently preferredBufferWriter
.static BufferWriter
newBufferWriter(ServletRequest request)
static BufferWriter
newBufferWriter(ServletRequest request, long tempFileThreshold)
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.SimpleTagSupport
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setJspContext, setParent
-
-
-
-
Method Detail
-
newBufferWriter
public static BufferWriter newBufferWriter(TempFileContext tempFileContext, long tempFileThreshold)
Creates an instance of the currently preferredBufferWriter
. Buffering strategies may change over time as technology develops and options become available.- See Also:
TempFileContext
,AutoTempFileWriter
-
newBufferWriter
public static BufferWriter newBufferWriter(TempFileContext tempFileContext)
-
newBufferWriter
public static BufferWriter newBufferWriter(ServletRequest request, long tempFileThreshold)
-
newBufferWriter
public static BufferWriter newBufferWriter(ServletRequest request)
-
getContentType
public abstract MediaType getContentType()
Gets the type of data that is contained by this tag.
-
getOutputType
public abstract MediaType 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:
AutoTempFileWriter.DEFAULT_TEMP_FILE_THRESHOLD
-
doTag
@Deprecated public void doTag() throws JspException, IOException
Deprecated.You should probably be implementing indoTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)
- Specified by:
doTag
in interfaceSimpleTag
- Overrides:
doTag
in classSimpleTagSupport
- Throws:
JspException
IOException
- See Also:
doTag(com.aoapps.io.buffer.BufferResult, java.io.Writer)
-
invoke
protected void invoke(JspFragment body, MediaValidator captureValidator) throws JspException, IOException
Invokes the body. This is only called when a body exists. Subclasses may override this to perform actions before and/or after invoking the body. Any overriding implementation should callsuper.invoke(JspFragment,MediaValidator)
to invoke the body, unless it wants to suppress the body invocation.This implementation invokes
JspFragment.invoke(java.io.Writer)
providing the capture validator.- Throws:
JspException
IOException
-
writePrefix
protected void writePrefix(MediaType containerType, Writer out) throws JspException, IOException
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 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:
getOutputType()
-
setMediaEncoderOptions
protected void setMediaEncoderOptions(MediaEncoder mediaEncoder)
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
-
doTag
protected void doTag(BufferResult capturedBody, Writer out) throws JspException, IOException
Once the outJspWriter
has been replaced to output the proper content type, this version ofdoTag()
is called.The body, if present, has already been invoked with any output captured.
This default implementation does nothing.
- 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)
.- 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
protected void writeSuffix(MediaType containerType, Writer out) throws JspException, IOException
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 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:
getOutputType()
-
-