Class StringUtils
- java.lang.Object
-
- org.springframework.extensions.webscripts.ui.common.StringUtils
-
public class StringUtils extends java.lang.ObjectClass containing misc helper methods for managing Strings. NOTE: Extracted from org.alfresco.web.ui.common.Utils;- Author:
- Kevin Roast
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.owasp.html.PolicyFactorybasePolicyprotected static org.owasp.html.PolicyFactorydocPolicyprotected static booleanoverrideDocTypedefault value - NOTE: see spring-webscripts-application-context.xml
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcropEncode(java.lang.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 java.lang.StringcropEncode(java.lang.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 java.lang.Stringencode(java.lang.String string)Encodes the given string, so that it can be used within an HTML page.static java.lang.StringencodeJavascript(java.lang.String s)Encode a string to the %AB hex style JavaScript compatible notation.static java.lang.Stringjoin(java.lang.Object[] value)Join an array of values into a String valuestatic java.lang.Stringjoin(java.lang.Object[] value, java.lang.String delim)Join an array of values into a String value using supplied delimiter between each.static java.lang.Stringremove(java.lang.String str, java.lang.String match)Remove all occurances of a String from a Stringstatic java.lang.Stringreplace(java.lang.String str, java.lang.String repl, java.lang.String with)Replace one string instance with another within the specified stringstatic java.lang.StringreplaceLineBreaks(java.lang.String str, boolean xhtml)Replaces carriage returns and line breaks with the <br> tag.voidsetOverrideDocType(boolean overrideDocType)static java.lang.StringstripUnsafeHTMLDocument(java.lang.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 java.lang.StringstripUnsafeHTMLTags(java.lang.String s)Strip unsafe HTML tags from a string - only leaves most basic formatting tags and encodes the remaining characters.static java.lang.StringstripUnsafeHTMLTags(java.lang.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 java.lang.StringstripUnsafeHTMLTags(java.lang.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.static java.lang.StringstripUnsafeHTMLTags(java.lang.String s, boolean encode, boolean overrideDocumentType, boolean isHTMLDoc)Strip unsafe HTML tags from a string - only leaves most basic formatting tagsstatic java.lang.StringstripUnsafeHTMLTags(java.lang.String s, boolean encode, boolean overrideDocumentType, boolean isHTMLDoc, boolean runTwice)Strip unsafe HTML tags from a string - only leaves most basic formatting tags
-
-
-
Method Detail
-
setOverrideDocType
public void setOverrideDocType(boolean overrideDocType)
- Parameters:
overrideDocType- Decides if legacy html !DOCTYPE instructions shall be transformed to the default mode
-
encode
public static java.lang.String encode(java.lang.String string)
Encodes the given string, so that it can be used within an HTML page.- Parameters:
string- the String to convert
-
cropEncode
public static java.lang.String cropEncode(java.lang.String text)
Crop a label within a SPAN element, using ellipses '...' at the end of label and and encode the result for HTML output. A SPAN will only be generated if the label is beyond the default setting of 32 characters in length.- Parameters:
text- to crop and encode- Returns:
- encoded and cropped resulting label HTML
-
cropEncode
public static java.lang.String cropEncode(java.lang.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. A SPAN will only be generated if the label is beyond the specified number of characters in length.- Parameters:
text- to crop and encodelength- length of string to crop too- Returns:
- encoded and cropped resulting label HTML
-
encodeJavascript
public static java.lang.String encodeJavascript(java.lang.String s)
Encode a string to the %AB hex style JavaScript compatible notation. Used to encode a string to a value that can be safely inserted into an HTML page and then decoded (and probably eval()ed) using the unescape() JavaScript method.- Parameters:
s- string to encode- Returns:
- %AB hex style encoded string
-
stripUnsafeHTMLTags
public static java.lang.String stripUnsafeHTMLTags(java.lang.String s)
Strip unsafe HTML tags from a string - only leaves most basic formatting tags and encodes the remaining characters.- Parameters:
s- HTML string to strip tags from- Returns:
- safe string
-
stripUnsafeHTMLTags
public static java.lang.String stripUnsafeHTMLTags(java.lang.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.- Parameters:
s- HTML string to strip tags fromencode- if true then encode remaining html data- Returns:
- safe string
-
stripUnsafeHTMLDocument
public static java.lang.String stripUnsafeHTMLDocument(java.lang.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.- Parameters:
doc- HTML string representing an entire hml doc to strip tags fromencode- if true then encode remaining html data- Returns:
- safe string
-
stripUnsafeHTMLTags
public static java.lang.String stripUnsafeHTMLTags(java.lang.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.- Parameters:
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 used- Returns:
- safe string
-
stripUnsafeHTMLTags
public static java.lang.String stripUnsafeHTMLTags(java.lang.String s, boolean encode, boolean overrideDocumentType, boolean isHTMLDoc)Strip unsafe HTML tags from a string - only leaves most basic formatting tags- Parameters:
s- HTML string to strip tags fromencode- if true then encode remaining html data (not in use)overrideDocumentType- if true a doctype enforcing the latest browser rendition mode will usedisHTMLDoc- if true elements as html, head, body will be allowed in the sanitization- Returns:
- safe string
-
stripUnsafeHTMLTags
public static java.lang.String stripUnsafeHTMLTags(java.lang.String s, boolean encode, boolean overrideDocumentType, boolean isHTMLDoc, boolean runTwice)Strip unsafe HTML tags from a string - only leaves most basic formatting tags- Parameters:
s- HTML string to strip tags fromencode- if true then encode remaining html data (not in use)overrideDocumentType- if true a doctype enforcing the latest browser rendition mode will usedisHTMLDoc- if true elements as html, head, body will be allowed in the sanitizationrunTwice- if true, performs a second iteration against the first sanitation result- Returns:
- safe string
-
replace
public static java.lang.String replace(java.lang.String str, java.lang.String repl, java.lang.String with)Replace one string instance with another within the specified string- Parameters:
str- Stringrepl- Stringwith- String- Returns:
- replaced string
-
remove
public static java.lang.String remove(java.lang.String str, java.lang.String match)Remove all occurances of a String from a String- Parameters:
str- String to remove occurances frommatch- The string to remove- Returns:
- new String with occurances of the match removed
-
replaceLineBreaks
public static java.lang.String replaceLineBreaks(java.lang.String str, boolean xhtml)Replaces carriage returns and line breaks with the <br> tag.- Parameters:
str- The string to be parsed- Returns:
- The string with line breaks removed
-
join
public static java.lang.String join(java.lang.Object[] value)
Join an array of values into a String value- Parameters:
value- non-null array of objects - toString() of each value is used- Returns:
- concatenated string value
-
join
public static java.lang.String join(java.lang.Object[] value, java.lang.String delim)Join an array of values into a String value using supplied delimiter between each.- Parameters:
value- non-null array of objects - toString() of each value is useddelim- delimiter value to apply between each value - null indicates no delimiter- Returns:
- concatenated string value
-
-