All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class nl.nmg.servlet.HTMLWriter

java.lang.Object
   |
   +----java.io.Writer
           |
           +----java.io.PrintWriter
                   |
                   +----nl.nmg.servlet.HTMLWriter

public class HTMLWriter
extends PrintWriter
The HTMLWriter class is a subclass for a PrintWriter that adds methods for printing HTML elements, especially form elements.


Constructor Index

 o HTMLWriter(OutputStream)
Create a new HTMLWriter, without automatic line flushing, from an existing OutputStream.
 o HTMLWriter(OutputStream, boolean)
Create a new HTMLWriter from an existing OutputStream.
 o HTMLWriter(Writer)
Create a new HTMLWriter, without automatic line flushing.
 o HTMLWriter(Writer, boolean)
Create a new HTMLWriter.

Method Index

 o printCheckboxInput(String)
Prints a <INPUT type="checkbox"> form element without a label or value and checked attributes.
 o printCheckboxInput(String, boolean)
Prints a <INPUT type="checkbox"> form element without a label or a value attribute.
 o printCheckboxInput(String, boolean, String)
Prints a <INPUT type="checkbox"> form element without a value attribute.
 o printCheckboxInput(String, String)
Prints a <INPUT type="checkbox"> form element without value and checked attributes.
 o printCheckboxInput(String, String, boolean)
Prints a <INPUT type="checkbox"> form element without a label.
 o printCheckboxInput(String, String, boolean, String)
Prints a <INPUT type="checkbox"> form element.
 o printDate(Date)
Prints a date (day, month and year) using SimpleDateFormat's default format.
 o printDate(String, Date)
Prints a date (day, month and year) using a SimpleDateFormat.
 o printDateSelect(String, int, int)
Prints three <SELECT> form elements that can be used to select a date.
 o printDateSelect(String, int, int, Date)
Prints three <SELECT> form elements that can be used to select a date.
 o printDateSelect(String, int, int, Date, boolean)
Prints three <SELECT> form elements that can be used to select a date.
 o printFileInput(String)
Prints a <INPUT type="file"> form element without size and maxlength attributes.
 o printFileInput(String, int)
Prints a <INPUT type="file"> form element without a maxlength attribute.
 o printFileInput(String, int, int)
Prints a <INPUT type="file"> form element.
 o printHiddenInput(String, String)
Prints a <INPUT type="hidden"> form element.
 o printMultipleSelect(String, int, String[])
Prints a <SELECT> form element for multiple selections with the values for labels, without a selected option.
 o printMultipleSelect(String, int, String[], boolean[])
Prints a <SELECT> form element for multiple selections with the values for labels.
 o printMultipleSelect(String, int, String[], boolean[], String[])
Prints a <SELECT> form element for multiple selections.
 o printPasswordInput(String)
Prints a <INPUT type="password"> form element without value, size and maxlength attributes.
 o printPasswordInput(String, String)
Prints a <INPUT type="password"> form element without size and maxlength attributes.
 o printPasswordInput(String, String, int)
Prints a <INPUT type="password"> form element without a maxlength attribute.
 o printPasswordInput(String, String, int, int)
Prints a <INPUT type="password"> form element.
 o printRadioInput(String)
Prints a <INPUT type="radio"> form element without a label or value and checked attributes.
 o printRadioInput(String, boolean)
Prints a <INPUT type="radio"> form element without a label or a value attribute.
 o printRadioInput(String, boolean, String)
Prints a <INPUT type="radio"> form element without a value attribute.
 o printRadioInput(String, String)
Prints a <INPUT type="radio"> form element without value and checked attributes.
 o printRadioInput(String, String, boolean)
Prints a <INPUT type="radio"> form element without a label.
 o printRadioInput(String, String, boolean, String)
Prints a <INPUT type="radio"> form element.
 o printResetInput()
Prints a <INPUT type="reset"> form element without a value attribute.
 o printResetInput(String)
Prints a <INPUT type="reset"> form element.
 o printSingleSelect(String, String[])
Prints a <SELECT> form element with the values for labels, without a selected option.
 o printSingleSelect(String, String[], String)
Prints a <SELECT> form element with the values for labels.
 o printSingleSelect(String, String[], String, String[])
Prints a <SELECT> form element.
 o printSubmitInput()
Prints a <INPUT type="submit"> form element without name and value attributes.
 o printSubmitInput(String)
Prints a <INPUT type="submit"> form element without a value attribute.
 o printSubmitInput(String, String)
Prints a <INPUT type="submit"> form element.
 o printText(BufferedReader)
Prints free-form ascii text as nicely formatted HTML code.
 o printText(BufferedReader, boolean)
Prints free-form ascii text as nicely formatted HTML code.
 o printText(String)
Prints free-form ascii text as nicely formatted HTML code.
 o printText(String, boolean)
Prints free-form ascii text as nicely formatted HTML code.
 o printTextArea(String)
Prints an empty <TEXTAREA> form element without wrap, cols and rows attributes.
 o printTextArea(String, int, int)
Prints an empty <TEXTAREA> form element without a wrap attribute.
 o printTextArea(String, int, int, String)
Prints an empty <TEXTAREA> form element.
 o printTextArea(String, int, int, String, String)
Prints a <TEXTAREA> form element.
 o printTextInput(String)
Prints a <INPUT type="text"> form element without value, size and maxlength attributes.
 o printTextInput(String, String)
Prints a <INPUT type="text"> form element without size and maxlength attributes.
 o printTextInput(String, String, int)
Prints a <INPUT type="text"> form element without a maxlength attribute.
 o printTextInput(String, String, int, int)
Prints a <INPUT type="text"> form element.

Constructors

 o HTMLWriter
 public HTMLWriter(Writer out)
Create a new HTMLWriter, without automatic line flushing.

Parameters:
out - A character-output stream
 o HTMLWriter
 public HTMLWriter(Writer out,
                   boolean autoFlush)
Create a new HTMLWriter.

Parameters:
out - A character-output stream
autoFlush - A boolean; if true, the println() methods will flush the output buffer
 o HTMLWriter
 public HTMLWriter(OutputStream out)
Create a new HTMLWriter, without automatic line flushing, from an existing OutputStream. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will convert characters into bytes using the default character encoding.

Parameters:
out - An output stream
See Also:
OutputStreamWriter
 o HTMLWriter
 public HTMLWriter(OutputStream out,
                   boolean autoFlush)
Create a new HTMLWriter from an existing OutputStream. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will convert characters into bytes using the default character encoding.

Parameters:
out - An output stream
autoFlush - A boolean; if true, the println() methods will flush the output buffer
See Also:
OutputStreamWriter

Methods

 o printHiddenInput
 public void printHiddenInput(String name,
                              String value)
Prints a <INPUT type="hidden"> form element. If the value is null, a comment is printed instead.

Parameters:
name - the value of the name attribute
value - the value of the value attribute or null if no form element should be printed.
 o printTextInput
 public void printTextInput(String name,
                            String value,
                            int size,
                            int maxlength)
Prints a <INPUT type="text"> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
maxlength - the value of the maxlength attribute or -1 if it should not be set
 o printTextInput
 public void printTextInput(String name,
                            String value,
                            int size)
Prints a <INPUT type="text"> form element without a maxlength attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
 o printTextInput
 public void printTextInput(String name,
                            String value)
Prints a <INPUT type="text"> form element without size and maxlength attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
 o printTextInput
 public void printTextInput(String name)
Prints a <INPUT type="text"> form element without value, size and maxlength attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printPasswordInput
 public void printPasswordInput(String name,
                                String value,
                                int size,
                                int maxlength)
Prints a <INPUT type="password"> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
maxlength - the value of the maxlength attribute or -1 if it should not be set
 o printPasswordInput
 public void printPasswordInput(String name,
                                String value,
                                int size)
Prints a <INPUT type="password"> form element without a maxlength attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
 o printPasswordInput
 public void printPasswordInput(String name,
                                String value)
Prints a <INPUT type="password"> form element without size and maxlength attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
 o printPasswordInput
 public void printPasswordInput(String name)
Prints a <INPUT type="password"> form element without value, size and maxlength attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printFileInput
 public void printFileInput(String name,
                            int size,
                            int maxlength)
Prints a <INPUT type="file"> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
maxlength - the value of the maxlength attribute or -1 if it should not be set
 o printFileInput
 public void printFileInput(String name,
                            int size)
Prints a <INPUT type="file"> form element without a maxlength attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
 o printFileInput
 public void printFileInput(String name)
Prints a <INPUT type="file"> form element without size and maxlength attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printSubmitInput
 public void printSubmitInput(String name,
                              String value)
Prints a <INPUT type="submit"> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
 o printSubmitInput
 public void printSubmitInput(String value)
Prints a <INPUT type="submit"> form element without a value attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printSubmitInput
 public void printSubmitInput()
Prints a <INPUT type="submit"> form element without name and value attributes.

 o printResetInput
 public void printResetInput(String value)
Prints a <INPUT type="reset"> form element.

Parameters:
value - the value of the value attribute or null if it should not be set
 o printResetInput
 public void printResetInput()
Prints a <INPUT type="reset"> form element without a value attribute.

 o printCheckboxInput
 public void printCheckboxInput(String name,
                                String value,
                                boolean checked,
                                String label)
Prints a <INPUT type="checkbox"> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
checked - the value of the checked attribute
label - the label to follow the checkbox or null if there should be no label.
 o printCheckboxInput
 public void printCheckboxInput(String name,
                                String value,
                                boolean checked)
Prints a <INPUT type="checkbox"> form element without a label.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
checked - the value of the checked attribute
 o printCheckboxInput
 public void printCheckboxInput(String name,
                                boolean checked,
                                String label)
Prints a <INPUT type="checkbox"> form element without a value attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
checked - the value of the checked attribute
label - the label to follow the checkbox or null if there should be no label.
 o printCheckboxInput
 public void printCheckboxInput(String name,
                                boolean checked)
Prints a <INPUT type="checkbox"> form element without a label or a value attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
checked - the value of the checked attribute
 o printCheckboxInput
 public void printCheckboxInput(String name,
                                String label)
Prints a <INPUT type="checkbox"> form element without value and checked attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
label - the label to follow the checkbox or null if there should be no label.
 o printCheckboxInput
 public void printCheckboxInput(String name)
Prints a <INPUT type="checkbox"> form element without a label or value and checked attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printRadioInput
 public void printRadioInput(String name,
                             String value,
                             boolean checked,
                             String label)
Prints a <INPUT type="radio"> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
checked - the value of the checked attribute
label - the label to follow the radio or null if there should be no label.
 o printRadioInput
 public void printRadioInput(String name,
                             String value,
                             boolean checked)
Prints a <INPUT type="radio"> form element without a label.

Parameters:
name - the value of the name attribute or null if it should not be set
value - the value of the value attribute or null if it should not be set
checked - the value of the checked attribute
 o printRadioInput
 public void printRadioInput(String name,
                             boolean checked,
                             String label)
Prints a <INPUT type="radio"> form element without a value attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
checked - the value of the checked attribute
label - the label to follow the radio or null if there should be no label.
 o printRadioInput
 public void printRadioInput(String name,
                             boolean checked)
Prints a <INPUT type="radio"> form element without a label or a value attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
checked - the value of the checked attribute
 o printRadioInput
 public void printRadioInput(String name,
                             String label)
Prints a <INPUT type="radio"> form element without value and checked attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
label - the label to follow the radio or null if there should be no label.
 o printRadioInput
 public void printRadioInput(String name)
Prints a <INPUT type="radio"> form element without a label or value and checked attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printTextArea
 public void printTextArea(String name,
                           int cols,
                           int rows,
                           String wrap,
                           String value)
Prints a <TEXTAREA> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
cols - the value of the cols attribute or -1 if it should not be set
rows - the value of the rows attribute or -1 if it should not be set
wrap - the value of the wrap attribute or null if it should not be set
value - the value between the <TEXTAREA> and </TEXTAREA> tags or null if it should be empty.
 o printTextArea
 public void printTextArea(String name,
                           int cols,
                           int rows,
                           String wrap)
Prints an empty <TEXTAREA> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
cols - the value of the cols attribute or -1 if it should not be set
rows - the value of the rows attribute or -1 if it should not be set
wrap - the value of the wrap attribute or null if it should not be set
 o printTextArea
 public void printTextArea(String name,
                           int cols,
                           int rows)
Prints an empty <TEXTAREA> form element without a wrap attribute.

Parameters:
name - the value of the name attribute or null if it should not be set
cols - the value of the cols attribute or -1 if it should not be set
rows - the value of the rows attribute or -1 if it should not be set
 o printTextArea
 public void printTextArea(String name)
Prints an empty <TEXTAREA> form element without wrap, cols and rows attributes.

Parameters:
name - the value of the name attribute or null if it should not be set
 o printSingleSelect
 public void printSingleSelect(String name,
                               String values[],
                               String selected,
                               String labels[])
Prints a <SELECT> form element.

Parameters:
name - the value of the name attribute or null if it should not be set
values - the values for the <OPTION> form elements.
selected - the value of the <OPTION> that should have a selected attribute.
labels - the labels for the <OPTION> form elements.
 o printSingleSelect
 public void printSingleSelect(String name,
                               String values[],
                               String selected)
Prints a <SELECT> form element with the values for labels.

Parameters:
name - the value of the name attribute or null if it should not be set
values - the values and labels for the <OPTION> form elements.
selected - the value of the <OPTION> that should have a selected attribute.
 o printSingleSelect
 public void printSingleSelect(String name,
                               String values[])
Prints a <SELECT> form element with the values for labels, without a selected option.

Parameters:
name - the value of the name attribute or null if it should not be set
values - the values and labels for the <OPTION> form elements.
 o printMultipleSelect
 public void printMultipleSelect(String name,
                                 int size,
                                 String values[],
                                 boolean selected[],
                                 String labels[])
Prints a <SELECT> form element for multiple selections.

Parameters:
name - the value of the name attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
values - the values for the <OPTION> form elements.
selected - an array of booleans of the same size as values. If one of the booleans is true, the corresponding option gets a selected attribute.
labels - the labels for the <OPTION> form elements.
 o printMultipleSelect
 public void printMultipleSelect(String name,
                                 int size,
                                 String values[],
                                 boolean selected[])
Prints a <SELECT> form element for multiple selections with the values for labels.

Parameters:
name - the value of the name attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
values - the values for the <OPTION> form elements.
selected - an array of booleans of the same size as values. If one of the booleans is true, the corresponding option gets a selected attribute.
 o printMultipleSelect
 public void printMultipleSelect(String name,
                                 int size,
                                 String values[])
Prints a <SELECT> form element for multiple selections with the values for labels, without a selected option.

Parameters:
name - the value of the name attribute or null if it should not be set
size - the value of the size attribute or -1 if it should not be set
values - the values for the <OPTION> form elements.
 o printDateSelect
 public void printDateSelect(String prefix,
                             int lowestYear,
                             int highestYear,
                             Date selected,
                             boolean allowNull)
Prints three <SELECT> form elements that can be used to select a date. "_day", "_month" and "_year" are added to the prefix to make the name attributes for the form elements.

Parameters:
prefix - the prefix for the name attributes
lowestYear - the lowest year to display in the year selection element
highestYear - the highest year to display in the year selection element
selected - the date that should be selected in the selection element or null if no date should be selected
allowNull - is true when the form should allow for empty dates
See Also:
getDateParameter
 o printDateSelect
 public void printDateSelect(String prefix,
                             int lowestYear,
                             int highestYear,
                             Date selected)
Prints three <SELECT> form elements that can be used to select a date. "_day", "_month" and "_year" are added to the prefix to make the name attributes for the form elements. The form elements allow for empty dates.

Parameters:
prefix - the prefix for the name attributes
lowestYear - the lowest year to display in the year selection element
highestYear - the highest year to display in the year selection element
selected - the date that should be selected in the selection element or null if no date should be selected.
See Also:
getDateParameter
 o printDateSelect
 public void printDateSelect(String prefix,
                             int lowestYear,
                             int highestYear)
Prints three <SELECT> form elements that can be used to select a date. "_day", "_month" and "_year" are added to the prefix to make the name attributes for the form elements. The form elements allow for empty dates, no date is selected.

Parameters:
prefix - the prefix for the name attributes
lowestYear - the lowest year to display in the year selection element
highestYear - the highest year to display in the year selection element
See Also:
getDateParameter
 o printText
 public void printText(BufferedReader in,
                       boolean allowHtml) throws IOException
Prints free-form ascii text as nicely formatted HTML code. Depending upon the value of allowHtml the following transformations are done:

This method is meant to be used to print text entered by people that know little to no HTML. It tries to do its best to generate nice looking HTML, but the algorithm has to guess a lot of the time. So do not be surprised when the output is not what you expected. Have a look at the code, and try to fix it. :)

Parameters:
in - a BufferedReader that can be read to get the text or null to print nothing.
allowHtml - is true when HTML tags are allowed (you may want to set this to false when making something like a guestbook)
Throws: IOException
when an I/O error occurs
 o printText
 public void printText(BufferedReader in) throws IOException
Prints free-form ascii text as nicely formatted HTML code. HTML tags are allowed.

Parameters:
in - a BufferedReader that can be read to get the text or null to print nothing.
Throws: IOException
when an I/O error occurs
See Also:
printText
 o printText
 public void printText(String text,
                       boolean allowHtml)
Prints free-form ascii text as nicely formatted HTML code.

Parameters:
text - the text or null to print nothing
allowHtml - is true when HTML tags are allowed (you may want to set this to false when making something like a guestbook)
See Also:
printText
 o printText
 public void printText(String text)
Prints free-form ascii text as nicely formatted HTML code. HTML tags are allowed.

Parameters:
text - the text or null to print nothing
See Also:
printText
 o printDate
 public void printDate(String format,
                       Date value)
Prints a date (day, month and year) using a SimpleDateFormat.

Parameters:
format - the format to use or null to use the default format (see the documentation for SimpleDateFormat)
value - the date to print or null to print nothing
See Also:
SimpleDateFormat
 o printDate
 public void printDate(Date value)
Prints a date (day, month and year) using SimpleDateFormat's default format.

Parameters:
value - the date to print or null to print nothing
See Also:
SimpleDateFormat

All Packages  Class Hierarchy  This Package  Previous  Next  Index