/** * For converting plain-text URLs in a String to HTML <a> tags * Any URLs in the source text that happen to be already in a <a> tag will be unaffected. * @param text the plain text to convert * @return the full source text with URLs converted to HTML. * @deprecated just a copy of {@link org.sakaiproject.util.api.FormattedText#encodeUrlsAsHtml(String)} so use that instead */ public static String encodeUrlsAsHtml(String text) { Pattern p = Pattern.compile("(?<!href=['\"]{1})(((https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt)://|mailto:)[-:;@a-zA-Z0-9_.,~%+/?=&#]+(?<![.,?:]))"); Matcher m = p.matcher(text); StringBuffer buf = new StringBuffer(); while(m.find()) { String matchedUrl = m.group(); m.appendReplacement(buf, "<a href=\"" + Web.unEscapeHtml(matchedUrl) + "\">$1</a>"); } m.appendTail(buf); return buf.toString(); }