com.ibm.as400.util.html
Class HTMLTransform
- java.lang.Object
-
- com.ibm.as400.util.html.HTMLTransform
-
public class HTMLTransform extends java.lang.Object
The HTMLTransform class encodes and decodes a string's tags for use in an HTMLTagElement's control name, initial value, or displayed text. There are a set of special characters reserved for creating HTML tags. Those special characters have a corresponding set of replacement characters that allow users to visually see those characters in a browser.For example, if you wanted to set the value attribute of a TextFormInput object to a resource link so you could see the HTML link in the text input box, the HTML link tag would need to be encoded to see the special characters(<, >, and "):
<input type="text" name="myText" value="<a href="http://www.myLink.com/">Link</a>" />
The following example uses the HTMLEncoder class to encode and decode the value of a TextFormInput so it displays properly:
// The string to use for the TextFormInput value attribute. String s = new String("<a href="http://www.myLink.com/">Link</a>"); // Encode the string. String e = HTMLTransform.encode(s); // Create the TextFormInput object. TextFormInput input = new TextFormInput("myText", e); // Set the input size so the entire value can be seen. input.setSize(45);
System.out.println("TAG: " + input.getTag() + "\n"); // Output the string with the special characters encoded for display in a browser. System.out.println("Encoded: " + e + "\n"); // Output the string with the specials characters decoded back to the original string. System.out.println("Decoded: " + HTMLTransform.decode(e));Here is what will be produced:
// The TextFormInput with an encoded string. <input type="text" name="myText" value="<a href="http://www.myLink.com/">Link</a>" size="45" /> // The encoded string. <a href="http://www.myLink.com/">Link</a> // The decode string. <a href="http://www.myLink.com/">Link</a>
Here is what the browser will show:
<form> <label for="myTextID"></label> <input type="text" name="myText" value="<a href="http://www.myLink.com/">Link</a>" size="45" id="myTextID" /> </form>
The tags that are encoded include:
- "
- &
- <
- >
-
-
Constructor Summary
Constructors Constructor and Description HTMLTransform()
-
Method Summary
Methods Modifier and Type Method and Description static java.lang.String
decode(java.lang.String source)
Decodes the HTML string, which can contain replacement characters for HTML tags such as <, >, ", or &.static java.lang.String
encode(java.lang.String source)
Encodes the HTML string, which can contain HTML tags such as < , >, ", or &.
-
-
-
Method Detail
-
encode
public static java.lang.String encode(java.lang.String source)
Encodes the HTML string, which can contain HTML tags such as < , >, ", or &.- Parameters:
source
- The HTML string containing HTML tags to be encoded.- Returns:
- The encoded string.
-
decode
public static java.lang.String decode(java.lang.String source)
Decodes the HTML string, which can contain replacement characters for HTML tags such as <, >, ", or &.- Parameters:
source
- The HTML string containing HTML replacement characters to be decoded.- Returns:
- The decoded string.
-
-