public class UrlRewriterTest {
@Test
public void testUrlRewriter() {
LagartoParser lagartoParser = new LagartoParser(
"<a href=\"http://jodd.org\">1</a><a href=\"page.html\">2</a>", false);
StringBuilder out = new StringBuilder();
UrlRewriterTagAdapter urlRewriterTagAdapter = new UrlRewriterTagAdapter(new TagWriter(out)) {
@Override
protected CharSequence rewriteUrl(CharSequence url) {
String u = url.toString();
if (u.startsWith("http")) {
return url;
}
return "/ctx/" + url;
}
};
lagartoParser.parse(urlRewriterTagAdapter);
assertEquals(
"<a href=\"http://jodd.org\">1</a><a href=\"/ctx/page.html\">2</a>", out.toString());
}