Package jodd.lagarto.adapter

Source Code of jodd.lagarto.adapter.UrlRewriterTest

// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.lagarto.adapter;

import jodd.lagarto.LagartoParser;
import jodd.lagarto.TagWriter;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

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());
  }

}
TOP

Related Classes of jodd.lagarto.adapter.UrlRewriterTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.