public class StringUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static Set<String> |
attrBlackList
JavaScript event handler attributes starting with "on" are always removed
|
protected static Set<String> |
attrGreyList
default list - NOTE: see spring-webscripts-application-context.xml
|
protected static Map<String,Set<String>> |
attrValueBlackList
default list - NOTE: see spring-webscripts-application-context.xml
|
protected static boolean |
overrideDocType
default value - NOTE: see spring-webscripts-application-context.xml
|
protected static Set<String> |
tagWhiteList
default list - NOTE: see spring-webscripts-application-context.xml
|
| Constructor and Description |
|---|
StringUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
cropEncode(String text)
Crop a label within a SPAN element, using ellipses '...' at the end of label and
and encode the result for HTML output.
|
static String |
cropEncode(String text,
int length)
Crop a label within a SPAN element, using ellipses '...' at the end of label and
and encode the result for HTML output.
|
static String |
encode(String string)
Encodes the given string, so that it can be used within an HTML page.
|
static String |
encodeJavascript(String s)
Encode a string to the %AB hex style JavaScript compatible notation.
|
static String |
join(Object[] value)
Join an array of values into a String value
|
static String |
join(Object[] value,
String delim)
Join an array of values into a String value using supplied delimiter between each.
|
static String |
remove(String str,
String match)
Remove all occurances of a String from a String
|
static String |
replace(String str,
String repl,
String with)
Replace one string instance with another within the specified string
|
static String |
replaceLineBreaks(String str,
boolean xhtml)
Replaces carriage returns and line breaks with the <br> tag.
|
void |
setAttributeBlackList(Set<String> attributes) |
void |
setAttributeGreyList(Set<String> attributes) |
void |
setAttributeValueBlackList(Map<String,Set<String>> attrValueBlackList) |
void |
setOverrideDocType(boolean overrideDocType) |
void |
setTagWhiteList(Set<String> tags) |
static String |
stripUnsafeHTMLDocument(String doc,
boolean encode)
Strip unsafe HTML tags from a string that represent an entire hml doc - only leaves most basic formatting tags
and optionally encodes or strips the remaining characters.
|
static String |
stripUnsafeHTMLTags(String s)
Strip unsafe HTML tags from a string - only leaves most basic formatting tags
and encodes the remaining characters.
|
static String |
stripUnsafeHTMLTags(String s,
boolean encode)
Strip unsafe HTML tags from a string - only leaves most basic formatting tags
and optionally encodes or strips the remaining characters.
|
static String |
stripUnsafeHTMLTags(String s,
boolean encode,
boolean overrideDocumentType)
Strip unsafe HTML tags from a string - only leaves most basic formatting tags
and optionally encodes or strips the remaining characters.
|
protected static Set<String> attrBlackList
protected static Set<String> attrGreyList
protected static Map<String,Set<String>> attrValueBlackList
protected static Set<String> tagWhiteList
protected static boolean overrideDocType
public void setTagWhiteList(Set<String> tags)
tags - Set of safe HTML tagspublic void setAttributeGreyList(Set<String> attributes)
attributes - Set of HTML attributes to consider for sanitisationpublic void setAttributeBlackList(Set<String> attributes)
attributes - Set of HTML attributes to be removedpublic void setAttributeValueBlackList(Map<String,Set<String>> attrValueBlackList)
attrValueBlackList - Map between HTML tag attributes and set of forbidden values to be removedpublic void setOverrideDocType(boolean overrideDocType)
overrideDocType - Decides if legacy html !DOCTYPE instructions shall be transformed to the default modepublic static String encode(String string)
string - the String to convertpublic static String cropEncode(String text)
text - to crop and encodepublic static String cropEncode(String text, int length)
text - to crop and encodelength - length of string to crop toopublic static String encodeJavascript(String s)
s - string to encodepublic static String stripUnsafeHTMLTags(String s)
s - HTML string to strip tags frompublic static String stripUnsafeHTMLTags(String s, boolean encode)
s - HTML string to strip tags fromencode - if true then encode remaining html datapublic static String stripUnsafeHTMLDocument(String doc, boolean encode)
doc - HTML string representing an entire hml doc to strip tags fromencode - if true then encode remaining html datapublic static String stripUnsafeHTMLTags(String s, boolean encode, boolean overrideDocumentType)
s - HTML string to strip tags fromencode - if true then encode remaining html dataoverrideDocumentType - if true a doctype enforcing the latest browser rendition mode will usedpublic static String replace(String str, String repl, String with)
str - Stringrepl - Stringwith - Stringpublic static String remove(String str, String match)
str - String to remove occurances frommatch - The string to removepublic static String replaceLineBreaks(String str, boolean xhtml)
str - The string to be parsedpublic static String join(Object[] value)
value - non-null array of objects - toString() of each value is usedpublic static String join(Object[] value, String delim)
value - non-null array of objects - toString() of each value is useddelim - delimiter value to apply between each value - null indicates no delimiterCopyright © 2005–2019 Alfresco Software. All rights reserved.