|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.clients.web.util.HTML
public class HTML
This class contains a set of static methods that may be useful in a web application for handling text/HTML strings.
Field Summary | |
---|---|
private static Pattern |
AMP
|
private static Pattern |
AMPERSAND
|
private static Pattern |
AT_OR_DOT
|
private static Pattern |
BACKSLASH
|
private static Pattern |
DOUBLE_QUOTE
|
static Pattern |
EMAIL_REGEXP
This pattern can be used to find email addresses. |
private static Pattern |
GT
|
private static Pattern |
HASH
|
private static Pattern |
IMAGE_EXTENSION
|
private static Pattern |
LEADING_TRAILING_LINEBREAKS
|
static Pattern |
LINEBREAKS_REGEXP
This pattern can be used to find line breaks. |
static int |
LINK_EMAIL
This flag is used in scanForLinks(String,int)
when you want to create links for email addresses. |
static int |
LINK_URL
This flag is used in scanForLinks(String,int)
when you want to create links for URL:s. |
private static Pattern |
LT
|
static Pattern |
MARKUP
Pattern that matches everything inside a HTML tag. |
private static Pattern |
NEWLINE
|
private static Pattern |
PERCENT
|
private static Pattern |
PLUS
|
private static Pattern |
QUOTE
|
static Pattern |
SAFE_TAGS
This pattern is a list of HTML tags considered "safe". |
private static Pattern |
SINGLE_QUOTE
|
static int |
SMART_IMAGES
This flag is used in scanForLinks(String,int)
when you want to create links for images with a <img> tag instead of
an <a> tag. |
private static Pattern |
SPACE
|
static Pattern |
TAG_REGEXP
This pattern can be used to fins HTML tags. |
static Pattern |
URL_REGEXP
This pattern can be used to find URL:s. |
Constructor Summary | |
---|---|
HTML()
|
Method Summary | |
---|---|
static String |
encodeTags(String in)
Scans a string for HTML tags and replaces all & with &, < with <, > with > and all " with " |
static String |
encodeTags(String in,
Pattern safeTags)
|
static String |
encodeTags(String in,
String safeTags)
|
static String |
formatLineBreaks(String in)
Finds all linebreaks in a string and replaces them with a <br> tag, except that leading and trailing linebreaks will be removed. |
static boolean |
isValidEmail(String email)
Checks if the given string looks like an email address. |
static boolean |
isValidUrl(String url)
Checks if the given string looks like an URL. |
static String |
javaScriptEncode(String in)
Escape a string to make it safe for use in a JavaScript statement. |
static String |
niceFormat(String in)
A convenience method for doing encodeTags(in, SAFE_TAGS) ,
scanForLinks(in, "_new") and formatLineBreaks(in) in a single operation. |
static String |
niceFormat(String in,
int flags)
A convenience method for doing encodeTags(in, SAFE_TAGS) ,
scanForLinks(in, flags, "_new") and
formatLineBreaks(in) in a single operation. |
static String |
niceFormat(String in,
int flags,
String linkTarget)
A convenience method for doing encodeTags(in, SAFE_TAGS) ,
scanForLinks(in, flags, link_target)
and formatLineBreaks(in) in a single operation. |
static String |
niceFormat(String in,
String linkTarget)
A convenience method for doing encodeTags(in, SAFE_TAGS) ,
scanForLinks(in, target) and
formatLineBreaks(in) in a single operation. |
static String |
scanForLinks(String in)
Scans a string for email addresses and URL:s and replaces them with <a href="---"> tags. |
static String |
scanForLinks(String in,
int flags)
Scans a string for email addresses and URL:s and replaces them with <a href="---"> tags. |
static String |
scanForLinks(String in,
int flags,
String target)
Scans a string for email addresses and URL:s and replaces them with <a href="---"> tags. |
static String |
scanForLinks(String in,
String target)
Scans a string for email addresses and URL:s and replaces them with <a href="---"> tags. |
static String |
stripMarkup(CharSequence in)
Remove all HTML markup in a string and return what is left. |
static int |
textLength(CharSequence html)
Counts the length of a string ignoring all characters in HTML markup tags. |
static String |
urlEncode(String in)
Encode URL-unsafe characters in a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int LINK_URL
scanForLinks(String,int)
when you want to create links for URL:s.
public static final int LINK_EMAIL
scanForLinks(String,int)
when you want to create links for email addresses.
public static final int SMART_IMAGES
scanForLinks(String,int)
when you want to create links for images with a <img> tag instead of
an <a> tag.
public static final Pattern EMAIL_REGEXP
public static final Pattern URL_REGEXP
http://
, https://
, ftp://
or
www. followed by at least one subdomain and one topdomain followed by
an optional port number and an optional path including query information.
public static final Pattern LINEBREAKS_REGEXP
public static final Pattern TAG_REGEXP
public static final Pattern SAFE_TAGS
public static final Pattern MARKUP
private static final Pattern LEADING_TRAILING_LINEBREAKS
private static final Pattern AT_OR_DOT
private static final Pattern IMAGE_EXTENSION
private static final Pattern AMP
private static final Pattern LT
private static final Pattern GT
private static final Pattern QUOTE
private static final Pattern PERCENT
private static final Pattern PLUS
private static final Pattern SPACE
private static final Pattern HASH
private static final Pattern AMPERSAND
private static final Pattern BACKSLASH
private static final Pattern NEWLINE
private static final Pattern SINGLE_QUOTE
private static final Pattern DOUBLE_QUOTE
Constructor Detail |
---|
public HTML()
Method Detail |
---|
public static boolean isValidEmail(String email)
EMAIL_REGEXP
pattern.
email
- The string to check
EMAIL_REGEXP
public static boolean isValidUrl(String url)
URL_REGEXP
pattern.
url
- The string to check
URL_REGEXP
public static String formatLineBreaks(String in)
in
- The string to search
public static String scanForLinks(String in)
<a href="---">
tags.
Using this method is equivalent to:
scanForLinks(in, LINK_URL+LINK_EMAIL+SMART_IMAGES, null);
in
- The string to search
public static String scanForLinks(String in, int flags)
<a href="---">
tags.
Using this method is equivalent to:
scanForLinks(in, flags, null);
in
- The string to searchflags
- A combination of the following flags to indicate what we should
search for: LINK_URL
, LINK_EMAIL
SMART_IMAGES
public static String scanForLinks(String in, String target)
<a href="---">
tags.
Using this method is equivalent to:
scanForLinks(in, LINK_URL+LINK_EMAIL+SMART_IMAGES, target);
in
- The string to searchtarget
- The name of the target window in which the link should be opened
public static String scanForLinks(String in, int flags, String target)
<a href="---">
tags.
in
- The string to searchflags
- A combination of the following flags to indicate what we should
search for: LINK_URL
, LINK_EMAIL
SMART_IMAGES
target
- The name of the target window in which the link should be opened
public static String encodeTags(String in)
in
- The string to search
public static String encodeTags(String in, String safeTags)
public static String encodeTags(String in, Pattern safeTags)
public static String urlEncode(String in)
in
- The string to encode
public static String javaScriptEncode(String in)
in
- String to escape.
public static String niceFormat(String in)
encodeTags(in, SAFE_TAGS)
,
scanForLinks(in, "_new")
and formatLineBreaks(in)
in a single operation.
in
- The string to format
public static String niceFormat(String in, int flags)
encodeTags(in, SAFE_TAGS)
,
scanForLinks(in, flags, "_new")
and
formatLineBreaks(in)
in a single operation.
in
- The string to formatflags
- Flags to be used in the call to scanForLinks
public static String niceFormat(String in, String linkTarget)
encodeTags(in, SAFE_TAGS)
,
scanForLinks(in, target)
and
formatLineBreaks(in)
in a single operation.
in
- The string to formatlinkTarget
- The target parameter to be used in the call to
scanForLinks(String,String)
public static String niceFormat(String in, int flags, String linkTarget)
encodeTags(in, SAFE_TAGS)
,
scanForLinks(in, flags, link_target)
and formatLineBreaks(in)
in a single operation.
in
- The string to formatflags
- Flags to be used in the call to scanForLinks
linkTarget
- The target parameter to be used in the call to
scanForLinks(String,int,String)
public static String stripMarkup(CharSequence in)
in
- The string to strip from HTML
public static int textLength(CharSequence html)
html
- The HTML string
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |