public class HTMLWriter
extends java.io.Writer
Writer w; // given as the place the page is being written
String val = "<a><b>value of b</b><c>value of c</c></a>";
w.write("<p>The sample XML expression is: ");
HTMLWriter.writeHtml(w, val);
w.write("</p></n>");
The val can be ANY legal String value, e.g. something a user typed in. The
output stream of characters will accurately converted to HTML so that the
value is displayed to the user.
Author: Keith Swenson Copyright: Keith Swenson, all rights reserved License:
This code is made available under the GNU Lesser GPL license.| Constructor and Description |
|---|
HTMLWriter(java.io.Writer _wrapped) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
flush() |
void |
write(char[] chs,
int start,
int len) |
void |
write(int c) |
static void |
writeHtml(java.io.Writer w,
java.lang.String val)
Encodes a single
String value to a HTML markup so that the
HTML page will display the original passed in value exactly.. |
static void |
writeHtmlWithLines(java.io.Writer w,
java.lang.String val)
writeHtmlWithLines is a special case routine for certain situations.
|
public void write(int c)
throws java.io.IOException
write in class java.io.Writerjava.io.IOExceptionpublic void write(char[] chs,
int start,
int len)
throws java.io.IOException
write in class java.io.Writerjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Writerjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOExceptionpublic static void writeHtml(java.io.Writer w,
java.lang.String val)
throws java.io.IOException
String value to a HTML markup so that the
HTML page will display the original passed in value exactly..
If you are constructing an HTML page, and you have a String value that you want to be displayed on the page, and you do not want anything within that string value to be accidentally misinterpreted as markup, you must use this method to scan the String and convert any embedded problematic characters into their escaped equivalents. The result of the conversion is written into the stream that you pass in.
w - The Writer object to which the encoded String value is added.val - The String value to encode.java.io.IOExceptionpublic static void writeHtmlWithLines(java.io.Writer w,
java.lang.String val)
throws java.io.IOException
java.io.IOException