|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tapestry.AbstractMarkupWriter
public abstract class AbstractMarkupWriter
Abstract base class implementing the IMarkupWriter
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.
Constructor Summary | |
---|---|
protected |
AbstractMarkupWriter(boolean[] safe,
String[] entities,
String contentType)
Special constructor used for nested response writers. |
protected |
AbstractMarkupWriter(boolean[] safe,
String[] entities,
String contentType,
OutputStream stream)
General constructor used by subclasses. |
protected |
AbstractMarkupWriter(boolean[] safe,
String[] entities,
String contentType,
PrintWriter writer)
Creates new markup writer around the underlying PrintWriter . |
protected |
AbstractMarkupWriter(boolean[] safe,
String[] entities,
String contentType,
String encoding,
OutputStream stream)
General constructor used by subclasses. |
Method Summary | |
---|---|
void |
attribute(String name,
boolean value)
Writes a boolean attribute into the currently open tag. |
void |
attribute(String name,
int value)
Writes an integer attribute into the currently open tag. |
void |
attribute(String name,
String value)
Writes an attribute into the most recently opened tag. |
void |
attributeRaw(String name,
String value)
Similar to attribute(String, String) but no escaping of invalid elements
is done for the value. |
void |
begin(String name)
Closes any existing tag then starts a new element. |
void |
beginEmpty(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 IMarkupWriter . |
void |
closeTag()
Closes the most recently opened element by writing the '>' that ends it. |
void |
comment(String value)
Writes an GTML comment. |
void |
end()
Ends the element most recently started by begin(String) . |
void |
end(String name)
Ends the most recently started element with the given name. |
void |
flush()
Forwards flush() to this AbstractMarkupWriter 's
PrintWriter . |
String |
getContentType()
Returns the type of content generated by this response writer, as a MIME type. |
abstract IMarkupWriter |
getNestedWriter()
Returns a nested writer, one that accumulates its changes in a buffer. |
protected 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(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(String value)
Prints output to the stream. |
protected void |
push(String name)
Adds an element to the active element stack. |
protected void |
setOutputStream(OutputStream stream,
String encoding)
|
protected void |
setWriter(PrintWriter writer)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractMarkupWriter(boolean[] safe, String[] entities, String contentType, String encoding, OutputStream stream)
safe
- an array of flags indicating which characters
can be passed directly through with out filtering. Characters marked
unsafe, or outside the range defined by safe, are converted to entities.entities
- a set of prefered entities, unsafe characters with
a defined entity use the entity, other characters are converted
to numeric entities.contentType
- the MIME type of the content produced by the writer.encoding
- the encoding of content produced by the writer.stream
- stream to which content will be written.protected AbstractMarkupWriter(boolean[] safe, String[] entities, String contentType, OutputStream stream)
safe
- an array of flags indicating which characters
can be passed directly through with out filtering. Characters marked
unsafe, or outside the range defined by safe, are converted to entities.entities
- a set of prefered entities, unsafe characters with
a defined entity use the entity, other characters are converted
to numeric entities.contentType
- the type of content produced by the
writer.stream
- stream to which content will be written.protected AbstractMarkupWriter(boolean[] safe, String[] entities, String contentType, PrintWriter writer)
PrintWriter
.
This is primarily used by TagSupportService
,
which is inlcuding content, and therefore this method will not
close the writer when the markup writer is closed.
protected AbstractMarkupWriter(boolean[] safe, String[] entities, String contentType)
Method Detail |
---|
public String getContentType()
IMarkupWriter
getContentType
in interface IMarkupWriter
public abstract IMarkupWriter getNestedWriter()
IMarkupWriter
IMarkupWriter
.
getNestedWriter
in interface IMarkupWriter
protected void setWriter(PrintWriter writer)
protected void setOutputStream(OutputStream stream, String encoding)
public void attribute(String name, int value)
TBD: Validate that name is legal.
attribute
in interface IMarkupWriter
IllegalStateException
- if there is no open tag.public void attribute(String name, boolean value)
TBD: Validate that name is legal.
attribute
in interface IMarkupWriter
IllegalStateException
- if there is no open tag.public void attribute(String name, String value)
begin(String)
and before any other kind of writing (which closes the tag).
The value may be null. A null value will be rendered as an empty string.
Troublesome characters in the value are converted to thier GTML entities, much
like a print()
method, with the following exceptions:
attribute
in interface IMarkupWriter
name
- The name of the attribute to write (no validation
is done on the name).value
- The value to write. If null, the attribute
name is written as the value. Otherwise, the
value is written,
IllegalStateException
- if there is no open tag.public void attributeRaw(String name, String value)
attribute(String, String)
but no escaping of invalid elements
is done for the value.
attributeRaw
in interface IMarkupWriter
IllegalStateException
- if there is no open tag.public void begin(String name)
begin
in interface IMarkupWriter
public void beginEmpty(String name)
end()
call. This is useful for elements such as <hr;> or <br> that
do not need closing tags.
beginEmpty
in interface IMarkupWriter
public boolean checkError()
checkError()
on the
PrintWriter
used to format output.
checkError
in interface IMarkupWriter
public void close()
IMarkupWriter
. Any active elements are closed. The
PrintWriter
is then sent PrintWriter.close()
.
close
in interface IMarkupWriter
public void closeTag()
beginEmpty(String)
.
Once this is invoked, the attribute()
methods
may not be used until a new element is opened with begin(String)
or
or beginEmpty(String)
.
closeTag
in interface IMarkupWriter
public void comment(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 IMarkupWriter
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 IMarkupWriter
public void end(String name)
TBD: Error check if the name matches nothing on the open tag stack.
end
in interface IMarkupWriter
public void flush()
flush()
to this AbstractMarkupWriter
's
PrintWriter
.
flush
in interface IMarkupWriter
protected final 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 IMarkupWriter
public void print(char value)
Closes any open tag.
print
in interface IMarkupWriter
public void print(int value)
Closes any open tag.
print
in interface IMarkupWriter
public void print(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 IMarkupWriter
print(char[], int, int)
public void println()
println
in interface IMarkupWriter
public void printRaw(char[] buffer, int offset, int length)
print()
.
Does nothing if buffer
is null.
Closes any open tag.
printRaw
in interface IMarkupWriter
public void printRaw(String value)
print()
. Does nothing
if value
is null.
Closes any open tag.
printRaw
in interface IMarkupWriter
protected final void push(String name)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |