WikiHyperLinks { public String addLinks(String text) { RegExp REGEXP_LINKS = RegExp.compile("\\[.*?\\s*(.*?)\\]", "g"); MatchResult matchResult = REGEXP_LINKS.exec(text); if (matchResult != null && matchResult.getGroupCount() == 2) { String content = matchResult.getGroup(1); StringBuilder sb = new StringBuilder("<a href=\""); int space = content.indexOf(' '); if (space == -1) { sb.append(UriUtils.sanitizeUri(content)); sb.append("\">"); sb.append(UriUtils.sanitizeUri(content)); } else { sb.append(UriUtils.sanitizeUri(content.substring(0, space))); sb.append("\">"); sb.append(content.substring(space + 1, content.length())); } sb.append("</a>"); String hyperLinksValue = text.replace(matchResult.getGroup(0), sb.toString()); return addLinks(hyperLinksValue); } return text; }  String addLinks(String text);  }
@Test public void checkSimpleLink() { String text = "hello this is a test [http: assertEquals(addLinks(text), "hello this is a test <a href=\"http: }
@Test public void checkTwoLinks() { String text = "hello this is a test [http: assertEquals(addLinks(text), "hello this is a test <a href=\"http: }
@Test public void checkLinkWithSimpleTitle() { String text = "hello this is a test [http: assertEquals(addLinks(text), "hello this is a test <a href=\"http: }
@Test public void checkLinkWithLongTitle() { String text = "hello this is a test [http: assertEquals(addLinks(text), "hello this is a test <a href=\"http: }