|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.primix.tapestry.AbstractResponseWriter
Abstract base class implementing the IResponseWriter
interface.
This class is used to create a Generic Tag Markup Language (GTML) output.
It is more sophisticated than PrintWriter
in that it maintains
a concept hierarchy of open GTML tags. It also supplies a number of other
of the features that are useful when creating GTML.
Elements are started with the begin(String)
or beginEmpty(String)
methods. Once they are started, attributes for the elements may be set with
the various attribute()
methods. The element is closed off
(i.e., the closing '>' character is written) when any other method
is invoked (exception: methods which do not produce output, such as
flush()
). The end()
methods end an element,
writing an GTML close tag to the output.
TBD:
This class is derived from the original class
com.primix.servlet.HTMLWriter
,
part of the ServletUtils framework available from
The Giant
Java Tree.
Field Summary | |
protected boolean |
openTag
Indicates whether a tag is open or not. |
protected java.io.PrintWriter |
writer
The underlying PrintWriter that output is sent to. |
Constructor Summary | |
protected |
AbstractResponseWriter()
Protected constructor, needed by to construct a nested response writer. |
|
AbstractResponseWriter(java.io.OutputStream stream)
Sends output to the stream. |
Method Summary | |
void |
attribute(java.lang.String name)
Simply prints the attribute name. |
void |
attribute(java.lang.String name,
int value)
Writes an integer attribute into the currently open tag. |
void |
attribute(java.lang.String name,
java.lang.String value)
Writes an attribute into the most recently opened tag. |
void |
begin(java.lang.String name)
Closes any existing tag then starts a new element. |
void |
beginEmpty(java.lang.String name)
Starts an element that will not later be matched with an end()
call. |
boolean |
checkError()
Invokes checkError() on the
PrintWriter used to format output. |
void |
close()
Closes this IResponseWriter . |
void |
closeTag()
Closes the most recently opened element by writing the '>' that ends it. |
void |
comment(java.lang.String value)
Writes an GTML comment. |
void |
end()
Ends the element most recently started by begin(String) . |
void |
end(java.lang.String name)
Ends the most recently started element with the given name. |
void |
flush()
Forwards flush() to this AbstractResponseWriter 's
PrintWriter . |
abstract java.lang.String |
getContentType()
Implemented in concrete subclasses to identify the MIME content type produced by this response writer. |
protected abstract java.lang.String[] |
getEntities()
Implemented in concrete subclasses to provide a mapping from characters to entities. |
abstract IResponseWriter |
getNestedWriter()
Returns a nested writer, one that accumulates its changes in a buffer. |
protected abstract boolean[] |
getSafe()
Implemented in concrete subclasses to provide an indication of which characters are 'safe' to insert directly into the response. |
protected java.lang.String |
pop()
Removes the top element from the active element stack and returns it. |
void |
print(char value)
Prints a single character. |
void |
print(char[] data,
int offset,
int length)
The primary print() method, used by most other methods. |
void |
print(int value)
Prints an integer. |
void |
print(java.lang.String value)
Invokes print(char[], int, int) to print the string. |
void |
println()
Closes the open tag (if any), then prints a line seperator to the output stream. |
void |
printRaw(char[] buffer,
int offset,
int length)
Prints and portion of an output buffer to the stream. |
void |
printRaw(java.lang.String value)
Prints output to the stream. |
protected void |
push(java.lang.String name)
Adds an element to the active element stack. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.io.PrintWriter writer
PrintWriter
that output is sent to.protected boolean openTag
begin(String)
or beginEmpty(String)
.
It stays open while calls to the attribute()
methods are made. It is closed
(the '>' is written) when any other method is invoked.Constructor Detail |
protected AbstractResponseWriter()
Invokes getEntities()
and getSafe()
to determine the
necessary translatons for the response writer.
public AbstractResponseWriter(java.io.OutputStream stream)
PrintWriter
is created, which will be closed when the HTMLResponseWriter
is closed.Method Detail |
protected abstract java.lang.String[] getEntities()
Map
.protected abstract boolean[] getSafe()
public abstract java.lang.String getContentType()
getContentType
in interface IResponseWriter
public abstract IResponseWriter getNestedWriter()
IResponseWriter
IResponseWriter
.getNestedWriter
in interface IResponseWriter
public void attribute(java.lang.String name)
TBD: Check that name is legal.
attribute
in interface IResponseWriter
java.lang.IllegalStateException
- if there is no open tag.public void attribute(java.lang.String name, int value)
TBD: Validate that name is legal.
attribute
in interface IResponseWriter
java.lang.IllegalStateException
- if there is no open tag.public void attribute(java.lang.String name, java.lang.String value)
begin(String)
and before any other kind of writing (which closes the tag).
The value may be null, in which case this method behaves the same as
attribute(String)
.
Troublesome characters in the value are converted to thier GTML entities, much
like a print()
method, with the following exceptions:
attribute
in interface IResponseWriter
java.lang.IllegalStateException
- if there is no open tag.public void begin(java.lang.String name)
begin
in interface IResponseWriter
public void beginEmpty(java.lang.String name)
end()
call. This is useful for elements such as <hr;> or <br> that
do not need closing tags.beginEmpty
in interface IResponseWriter
public boolean checkError()
checkError()
on the
PrintWriter
used to format output.checkError
in interface IResponseWriter
public void close()
IResponseWriter
. Any active elements are closed. The
PrintWriter
is then sent PrintWriter.close()
.close
in interface IResponseWriter
public void closeTag()
attribute()
methods
may not be used until a new element is opened with begin(String)
or
or beginEmpty(String)
.closeTag
in interface IResponseWriter
public void comment(java.lang.String value)
<!--
and -->
,
including a blank line after the close of the comment.
Most characters are valid inside an GTML comment, so no check
of the contents is made (much like printRaw(String)
.
comment
in interface IResponseWriter
public void end()
begin(String)
.
The name of the tag
is popped off of the active element stack and used to form an GTML close tag.
TBD: Error checking for the open element stack empty.
end
in interface IResponseWriter
public void end(java.lang.String name)
TBD: Error check if the name matches nothing on the open tag stack.
end
in interface IResponseWriter
public void flush()
flush()
to this AbstractResponseWriter
's
PrintWriter
.flush
in interface IResponseWriter
protected final java.lang.String pop()
public void print(char[] data, int offset, int length)
print()
method, used by most other methods.
Prints the character array, first closing any open tag. Problematic characters ('<', '>' and '&') are converted to their GTML entities.
All 'unsafe' characters are properly converted to either a named
or numeric GTML entity. This can be somewhat expensive, so use
printRaw(char[], int, int)
if the data to print is guarenteed
to be safe.
Does nothing if data
is null.
Closes any open tag.
print
in interface IResponseWriter
public void print(char value)
Closes any open tag.
print
in interface IResponseWriter
public void print(int value)
Closes any open tag.
print
in interface IResponseWriter
public void print(java.lang.String value)
print(char[], int, int)
to print the string. Use
printRaw(String)
if the character data is known to be safe.
Does nothing if value
is null.
Closes any open tag.
print
in interface IResponseWriter
print(char[], int, int)
public void println()
println
in interface IResponseWriter
public void printRaw(char[] buffer, int offset, int length)
print()
.
Does nothing if buffer
is null.
Closes any open tag.
printRaw
in interface IResponseWriter
public void printRaw(java.lang.String value)
print()
. Does nothing
if value
is null.
Closes any open tag.
printRaw
in interface IResponseWriter
protected final void push(java.lang.String name)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |