The answer to Java escape HTML shows StringUtils.replaceEach() which runs similar to multiple StringUtils.replace()s, but accepting arrays of Strings instead of having to do each replace individually.
For example:
str = StringUtils.replace(str, "&", "&");
str = StringUtils.replace(str, "\"", """);
str = StringUtils.replace(str, "<", "<");
str = StringUtils.replace(str, ">", ">");
…becomes…
str = StringUtils.replaceEach(str,
new String[]{"&", "\"", "<", ">"},
new String[]{"&", """, "<", ">"})
Much cleaner.
Where can I access StringUtils.replace()?
I have tried importing the following, to no avail:
org.springframework.util.StringUtilsorg.apache.soap.util.StringUtilsorg.apache.axis.utils.StringUtilscom.ibm.wsdl.util.StringUtils
They each have .replace(), of course.
It believe you are looking for: org.apache.commons.lang3.StringUtils
You can find more about it here:
http://commons.apache.org/lang/api-3.1/org/apache/commons/lang3/StringUtils.html
And download the .jar here:
http://commons.apache.org/lang/