String (String text) { if (text == null) return null; String offensiveChars = "<>&\n"; final int textLength = text.length(); if (textLength > 0 && (Character.isWhitespace(text.charAt(0)) || Character.isWhitespace(text.charAt(textLength - 1)))) { return "<![CDATA[" + text + "]]>"; } for (int i = 0; i < offensiveChars.length(); i++) { char c = offensiveChars.charAt(i); if (text.indexOf(c) != -1) { return "<![CDATA[" + text + "]]>"; } } return text; }