public class TagWriter
extends java.lang.Object
Writer
instance.
Intended to support output from JSP tag libraries.
Modifier and Type | Class and Description |
---|---|
private static class |
TagWriter.SafeWriter
Simple
Writer wrapper that wraps all
IOExceptions in JspExceptions . |
private static class |
TagWriter.TagStateEntry
Holds state about a tag and its rendered behavior.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Stack |
tagState
Stores
tag state . |
private TagWriter.SafeWriter |
writer
The
TagWriter.SafeWriter to write to. |
Constructor and Description |
---|
TagWriter(PageContext pageContext)
Create a new instance of the
TagWriter class that writes to
the supplied PageContext . |
Modifier and Type | Method and Description |
---|---|
void |
appendValue(java.lang.String value)
Close the current opening tag (if necessary) and appends the
supplied value as inner text.
|
private void |
closeTagAndMarkAsBlock()
Closes the current opening tag and marks it as a block tag.
|
private TagWriter.TagStateEntry |
currentState() |
void |
endTag()
Close the current tag.
|
void |
endTag(boolean enforceClosingTag)
Close the current tag, allowing to enforce a full closing tag.
|
void |
forceBlock()
Indicate that the currently open tag should be closed and marked
as a block level element.
|
private boolean |
inTag() |
private void |
push(java.lang.String tagName)
Adds the supplied tag name to the
tag state . |
void |
startTag(java.lang.String tagName)
Start a new tag with the supplied name.
|
void |
writeAttribute(java.lang.String attributeName,
java.lang.String attributeValue)
Write an HTML attribute with the specified name and value.
|
void |
writeOptionalAttributeValue(java.lang.String attributeName,
java.lang.String attributeValue)
Write an HTML attribute if the supplied value is not
null
or zero length. |
private final TagWriter.SafeWriter writer
TagWriter.SafeWriter
to write to.private final java.util.Stack tagState
tag state
. Stack model naturally supports tag nesting.public TagWriter(PageContext pageContext)
TagWriter
class that writes to
the supplied PageContext
.pageContext
- the JSP PageContext to obtain the Writer
frompublic void startTag(java.lang.String tagName) throws JspException
JspException
endTag()
public void writeAttribute(java.lang.String attributeName, java.lang.String attributeValue) throws JspException
Be sure to write all attributes before writing any inner text or nested tags.
java.lang.IllegalStateException
- if the opening tag is closedJspException
public void writeOptionalAttributeValue(java.lang.String attributeName, java.lang.String attributeValue) throws JspException
null
or zero length.JspException
writeAttribute(String, String)
public void appendValue(java.lang.String value) throws JspException
java.lang.IllegalStateException
- if no tag is openJspException
public void forceBlock() throws JspException
Useful when you plan to write additional content in the body
outside the context of the current TagWriter
.
JspException
public void endTag() throws JspException
Correctly writes an empty tag if no inner text or nested tags have been written.
JspException
public void endTag(boolean enforceClosingTag) throws JspException
Correctly writes an empty tag if no inner text or nested tags have been written.
enforceClosingTag
- whether a full closing tag should be
rendered in any case, even in case of a non-block tagJspException
private void push(java.lang.String tagName)
tag state
.private void closeTagAndMarkAsBlock() throws JspException
JspException
private boolean inTag()
private TagWriter.TagStateEntry currentState()