ariba.util.core
Class HTML

java.lang.Object
  extended by ariba.util.core.HTML

public class HTML
extends java.lang.Object

Some HTML helpers


Field Summary
static char[] entityMapChars
           
static java.lang.String[] entityMapStrings
           
static char[] entityMapXMLChars
           
static java.lang.String[] entityMapXMLStrings
           
static java.lang.String[] safeHTMLStrings
           
static java.lang.String TagEndOfHead
           
static java.lang.String TagHTTPEquivStr
           
static java.lang.String TagMeta
           
 
Method Summary
static java.lang.String convertToPlainText(java.lang.String richText)
           
static java.lang.String convertToPlainTextNoHTML(java.lang.String text)
          Convert a string to plain text by removing all html including encoded html this method really attempts to take the string and extract the html markup even in the case that the client generated the html and xml encoded it so thats its not markup but instead content so we go through and look for that content that looks like markup and strip it out.
static void escape(FastStringBuffer buf)
          Escapes HTML character entities in a FastStringBuffer.res
static java.lang.String escape(java.lang.String text)
          Takes a raw text string and escapes any special character entities that need to be escaped in HTML (e.g.
static java.lang.String escape(java.lang.String str, boolean unsafeOnly)
          Escapes a string.
static java.lang.String escapeHTMLAttribute(java.lang.String attr)
          All tags within a HTML attribute are ignored by the browser.
static java.lang.String escapeUnsafe(java.lang.String str)
          Escapes unsafe tags and attributes in the given String
static java.lang.String escapeXMLString(java.lang.String buffer)
          Converts all characters in a string to XML-compatible characters.
static java.lang.String filterMargins(java.lang.String html)
          This filters out css margins in html attribute values.
static java.lang.String filterUnsafeHTML(java.lang.String str)
          Filters out any unsafe HTML and returns a safe HTML string
static java.lang.String fullyConvertToPlainText(java.lang.String text)
          Convert a string to plain text and convert encoded safe html tags
static java.lang.String fullyEscape(java.lang.String text)
          Takes a raw text string and escapes any special character entities that need to be escaped in HTML (e.g.
static java.lang.String getCharset(java.io.InputStream inStream)
          Parses a string to get the meta charset.
static java.lang.String getSafeTagBegin()
           
static java.lang.String getSafeTagEnd()
           
static boolean isProbablyHtml(java.lang.String text)
          Very simple heuristic as to whether text is HTML.
static boolean isSafeAttributeValue(java.lang.String value)
           
static boolean isSafeAttributeValue(java.lang.String attribute, java.lang.String value)
           
static java.lang.String linebreaksToBRTags(java.lang.String input)
           
static java.lang.String linksOpenInNewWindow(java.lang.String html)
          This will return an html string where links (a tags) without a target attribute have a target attribute inserted with a value of _blank.
static void main(java.lang.String[] args)
           
static void setSafeConfig(java.lang.String[] tags, java.lang.String[] attrs)
          Sets the safe tag and attribute definitions
static java.lang.String trimHTML(java.lang.String html)
           
static java.lang.String unescapeEuro(java.lang.String escapedHtml)
          Returns a string that "un-escapes" any numeric character values of the euro.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityMapChars

public static final char[] entityMapChars

entityMapStrings

public static final java.lang.String[] entityMapStrings

entityMapXMLChars

public static final char[] entityMapXMLChars

entityMapXMLStrings

public static final java.lang.String[] entityMapXMLStrings

safeHTMLStrings

public static final java.lang.String[] safeHTMLStrings

TagMeta

public static final java.lang.String TagMeta
See Also:
Constant Field Values

TagEndOfHead

public static final java.lang.String TagEndOfHead
See Also:
Constant Field Values

TagHTTPEquivStr

public static final java.lang.String TagHTTPEquivStr
See Also:
Constant Field Values
Method Detail

escape

public static java.lang.String escape(java.lang.String text)
Takes a raw text string and escapes any special character entities that need to be escaped in HTML (e.g. "<" for "<", etc.).


escape

public static void escape(FastStringBuffer buf)
Escapes HTML character entities in a FastStringBuffer.res


escape

public static java.lang.String escape(java.lang.String str,
                                      boolean unsafeOnly)
Escapes a string. The flag unsafeOnly determines a unsafe only escape or a full escape.

Returns:
the escaped string

fullyEscape

public static java.lang.String fullyEscape(java.lang.String text)
Takes a raw text string and escapes any special character entities that need to be escaped in HTML (e.g. "<" for "<", etc.). If the doNBSPs parameter is true, null or empty text strings will be converted to a single non-breaking space (" "). If the doBRs parameter is true, newline characters ('\n') will be converted to HTML line breaks ("
").

Parameters:
text - The text string to turn into HTML.
Returns:
the HTML string.

escapeUnsafe

public static java.lang.String escapeUnsafe(java.lang.String str)
Escapes unsafe tags and attributes in the given String

Returns:
the escaped string

unescapeEuro

public static java.lang.String unescapeEuro(java.lang.String escapedHtml)
Returns a string that "un-escapes" any numeric character values of the euro. I.e., it translates "€" to "€" and translates the WinLatin1 "€" to "€".


escapeXMLString

public static java.lang.String escapeXMLString(java.lang.String buffer)
Converts all characters in a string to XML-compatible characters.


escapeHTMLAttribute

public static java.lang.String escapeHTMLAttribute(java.lang.String attr)
All tags within a HTML attribute are ignored by the browser. But with XMLHTTP requests, we search for the script tags and execute them. Fixing this on the client is expensive. This method replaces all quotes with " and the opening angle bracket of the script tag with a ?.

Parameters:
attr -
Returns:
String with escaped quotes and ? for opening angle bracket of script tag.

getCharset

public static java.lang.String getCharset(java.io.InputStream inStream)
                                   throws java.io.IOException
Parses a string to get the meta charset. Returns null if there is no meta charset information. Charset is an attribute of the meta tag. The standard format is Note: IE has non-standard attribute for meta tag: there can be multiple tags in a document can use single or double quotes We do not handle this format.

Throws:
java.io.IOException

linebreaksToBRTags

public static java.lang.String linebreaksToBRTags(java.lang.String input)

main

public static void main(java.lang.String[] args)

setSafeConfig

public static void setSafeConfig(java.lang.String[] tags,
                                 java.lang.String[] attrs)
Sets the safe tag and attribute definitions


isSafeAttributeValue

public static boolean isSafeAttributeValue(java.lang.String value)

isSafeAttributeValue

public static boolean isSafeAttributeValue(java.lang.String attribute,
                                           java.lang.String value)

getSafeTagBegin

public static java.lang.String getSafeTagBegin()

getSafeTagEnd

public static java.lang.String getSafeTagEnd()

filterUnsafeHTML

public static java.lang.String filterUnsafeHTML(java.lang.String str)
Filters out any unsafe HTML and returns a safe HTML string


filterMargins

public static java.lang.String filterMargins(java.lang.String html)
This filters out css margins in html attribute values.


linksOpenInNewWindow

public static java.lang.String linksOpenInNewWindow(java.lang.String html)
This will return an html string where links (a tags) without a target attribute have a target attribute inserted with a value of _blank. This makes the tag open the link in a new window or tab, as specified in the browser's settings.

Parameters:
html - The HTML string to modify.
Returns:
A new HTML string where the links open in a new window or tab.

trimHTML

public static java.lang.String trimHTML(java.lang.String html)

convertToPlainText

public static java.lang.String convertToPlainText(java.lang.String richText)

isProbablyHtml

public static boolean isProbablyHtml(java.lang.String text)
Very simple heuristic as to whether text is HTML. Not very reliable.

Parameters:
text -
Returns:

fullyConvertToPlainText

public static java.lang.String fullyConvertToPlainText(java.lang.String text)
Convert a string to plain text and convert encoded safe html tags

Parameters:
text -
Returns:
converted string

convertToPlainTextNoHTML

public static java.lang.String convertToPlainTextNoHTML(java.lang.String text)
Convert a string to plain text by removing all html including encoded html this method really attempts to take the string and extract the html markup even in the case that the client generated the html and xml encoded it so thats its not markup but instead content so we go through and look for that content that looks like markup and strip it out.

Parameters:
text -
Returns:
converted string


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.