Class TextUtils
java.lang.Object
org.archive.util.TextUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringMinimally escapes a string so that it can be placed inside XML/HTML attribute.static StringEscapes a string so that it can be passed as an argument to a javscript in a JSP page.static StringEscapes a string so that it can be placed inside XML/HTML attribute.static StringexceptionToString(String message, Throwable e) static Stringstatic MatchergetMatcher(String pattern, CharSequence input) Get a matcher object for a precompiled regex pattern.static booleanmatches(String pattern, CharSequence input) Utility method using a precompiled pattern instead of using the matches method of the String class.static voidstatic StringreplaceAll(String pattern, CharSequence input, String replacement) Utility method using a precompiled pattern instead of using the replaceAll method of the String class.static StringreplaceFirst(String pattern, CharSequence input, String replacement) Utility method using a precompiled pattern instead of using the replaceFirst method of the String class.static String[]split(String pattern, CharSequence input) Utility method using a precompiled pattern instead of using the split method of the String class.static CharSequenceReplaces HTML Entity Encodings.static StringException- and warning-free URL-escaping utility method.static StringException- and warning-free URL-unescaping utility method.static voidwriteEscapedForHTML(String s, Writer w) Utility method for writing a (potentially large) String to a JspWriter, escaping it for HTML display, without constructing another large String of the whole content.
-
Constructor Details
-
TextUtils
public TextUtils()
-
-
Method Details
-
getMatcher
Get a matcher object for a precompiled regex pattern. This method tries to reuse Matcher objects for efficiency. It can hold for recycling one Matcher per pattern per thread. Matchers retrieved should be returned for reuse via the recycleMatcher() method, but no errors will occur if they are not. This method is a hotspot frequently accessed.- Parameters:
pattern- the string pattern to useinput- the character sequence the matcher should be using- Returns:
- a matcher object loaded with the submitted character sequence
-
recycleMatcher
-
replaceAll
Utility method using a precompiled pattern instead of using the replaceAll method of the String class. This method will also be reusing Matcher objects.- Parameters:
pattern- precompiled Pattern to match againstinput- the character sequence to checkreplacement- the String to substitute every match with- Returns:
- the String with all the matches substituted
- See Also:
-
replaceFirst
Utility method using a precompiled pattern instead of using the replaceFirst method of the String class. This method will also be reusing Matcher objects.- Parameters:
pattern- precompiled Pattern to match againstinput- the character sequence to checkreplacement- the String to substitute the first match with- Returns:
- the String with the first match substituted
- See Also:
-
matches
Utility method using a precompiled pattern instead of using the matches method of the String class. This method will also be reusing Matcher objects.- Parameters:
pattern- precompiled Pattern to match againstinput- the character sequence to check- Returns:
- true if character sequence matches
- See Also:
-
split
Utility method using a precompiled pattern instead of using the split method of the String class.- Parameters:
pattern- precompiled Pattern to split byinput- the character sequence to split- Returns:
- array of Strings split by pattern
- See Also:
-
getFirstWord
-
escapeForHTMLJavascript
Escapes a string so that it can be passed as an argument to a javscript in a JSP page. This method takes a string and returns the same string with any single quote escaped by prepending the character with a backslash. Linebreaks are also replaced with '\n'. Also, less-than signs and ampersands are replaced with HTML entities.- Parameters:
s- The string to escape- Returns:
- The same string escaped.
-
escapeForMarkupAttribute
-
escapeForHTML
-
writeEscapedForHTML
Utility method for writing a (potentially large) String to a JspWriter, escaping it for HTML display, without constructing another large String of the whole content.- Parameters:
s- String to writew- destination Writer- Throws:
IOException
-
unescapeHtml
Replaces HTML Entity Encodings.- Parameters:
cs- The CharSequence to remove html codes from- Returns:
- the same CharSequence or an escaped String.
-
exceptionToString
-
urlEscape
-
urlUnescape
-