com.lowagie.text.html
public final class: HtmlEncoder [javadoc |
source]
java.lang.Object
com.lowagie.text.html.HtmlEncoder
This class converts a
String to the HTML-format of a String.
To convert the String, each character is examined:
- ASCII-characters from 000 till 031 are represented as &#xxx;
(with xxx = the value of the character)
- ASCII-characters from 032 t/m 127 are represented by the character itself, except for:
- '\n' becomes <BR>\n
- " becomes "
- & becomes &
- < becomes <
- > becomes >
- ASCII-characters from 128 till 255 are represented as &#xxx;
(with xxx = the value of the character)
Example:
String htmlPresentation = HtmlEncoder.encode("Marie-Thérèse Sørensen");
for more info: see O'Reilly; "HTML: The Definitive Guide" (page 164)
- author:
mario.maccarini - @ugent.be
| Method from com.lowagie.text.html.HtmlEncoder Detail: |
public static String encode(String string) {
int n = string.length();
char character;
StringBuffer buffer = new StringBuffer();
// loop over all the characters of the String.
for (int i = 0; i < n; i++) {
character = string.charAt(i);
// the Htmlcode of these characters are added to a StringBuffer one by one
if (character < 256) {
buffer.append(htmlCode[character]);
}
else {
// Improvement posted by Joachim Eyrich
buffer.append("").append((int)character).append(';");
}
}
return buffer.toString();
}
Converts a String to the HTML-format of this String. |
public static String encode(Color color) {
StringBuffer buffer = new StringBuffer("#");
if (color.getRed() < 16) {
buffer.append('0");
}
buffer.append(Integer.toString(color.getRed(), 16));
if (color.getGreen() < 16) {
buffer.append('0");
}
buffer.append(Integer.toString(color.getGreen(), 16));
if (color.getBlue() < 16) {
buffer.append('0");
}
buffer.append(Integer.toString(color.getBlue(), 16));
return buffer.toString();
}
Converts a Color into a HTML representation of this Color. |
public static String getAlignment(int alignment) {
switch(alignment) {
case Element.ALIGN_LEFT:
return HtmlTags.ALIGN_LEFT;
case Element.ALIGN_CENTER:
return HtmlTags.ALIGN_CENTER;
case Element.ALIGN_RIGHT:
return HtmlTags.ALIGN_RIGHT;
case Element.ALIGN_JUSTIFIED:
case Element.ALIGN_JUSTIFIED_ALL:
return HtmlTags.ALIGN_JUSTIFIED;
case Element.ALIGN_TOP:
return HtmlTags.ALIGN_TOP;
case Element.ALIGN_MIDDLE:
return HtmlTags.ALIGN_MIDDLE;
case Element.ALIGN_BOTTOM:
return HtmlTags.ALIGN_BOTTOM;
case Element.ALIGN_BASELINE:
return HtmlTags.ALIGN_BASELINE;
default:
return "";
}
}
Translates the alignment value. |