8 Commits

Author SHA1 Message Date
David
fc3bb29b6a [maven-release-plugin] prepare release j2html-1.1.0 2017-08-14 17:45:02 +02:00
Sergey Bezkostnyi
ef5777e54a Add ability to change text escaper implementation (#70) 2017-08-14 17:10:02 +02:00
David
cfc1489399 Merge pull request #63 from maztan/master
Add method to get number of children of ContainerTag
2017-07-29 19:19:08 +02:00
Ed Savailonei
8112dad1bb Add methd to get number of children of ContainerTag 2017-07-03 12:41:10 +02:00
David
235dec78ed Merge pull request #62 from kiru/patch-1
Updaate Gradle Version
2017-05-19 23:05:12 +02:00
Kiru
6316dd2262 Updaate Gradle Version 2017-05-19 21:57:04 +02:00
David
5667d7c68d Update README.md 2017-05-16 18:49:27 +02:00
David
13911d5f57 [maven-release-plugin] prepare for next development iteration 2017-05-16 18:00:33 +02:00
10 changed files with 78 additions and 12 deletions

View File

@@ -13,12 +13,12 @@ The project webpage is [j2html.com](http://j2html.com).
<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>0.99</version>
<version>1.0.0</version>
</dependency>
```
### OR the gradle dependency
```
compile 'com.j2html:j2html:0.99'
compile 'com.j2html:j2html:1.0.0'
```
### Import TagCreator and start building HTML

View File

@@ -10,7 +10,7 @@
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<name>j2html</name>
<description>Java to HTML builder with a fluent API</description>

View File

@@ -0,0 +1,13 @@
package j2html;
import j2html.utils.SimpleEscaper;
import j2html.utils.TextEscaper;
public class Config {
private Config() {
}
public static TextEscaper textEscaper = new SimpleEscaper();
}

View File

@@ -1,7 +1,7 @@
package j2html.attributes;
import j2html.utils.SimpleEscaper;
import j2html.Config;
public class Attribute {
private String name;
@@ -9,7 +9,7 @@ public class Attribute {
public Attribute(String name, String value) {
this.name = name;
this.value = SimpleEscaper.escape(value);
this.value = Config.textEscaper.escape(value);
}
public Attribute(String name) {

View File

@@ -111,7 +111,13 @@ public class ContainerTag extends Tag<ContainerTag> {
return with(new Text(text));
}
/**
* Gets number of child nodes this tag element contains
*/
public int getNumChildren() {
return children.size();
}
/**
* Render the ContainerTag and its children
*

View File

@@ -1,6 +1,6 @@
package j2html.tags;
import j2html.utils.SimpleEscaper;
import j2html.Config;
public class Text extends DomContent {
@@ -12,7 +12,7 @@ public class Text extends DomContent {
@Override
public String render() {
return SimpleEscaper.escape(text);
return Config.textEscaper.escape(text);
}
}

View File

@@ -1,8 +1,8 @@
package j2html.utils;
public class SimpleEscaper {
public class SimpleEscaper implements TextEscaper {
public static String escape(String s) {
public String escape(String s) {
if (s == null) {
return null;
}

View File

@@ -0,0 +1,7 @@
package j2html.utils;
public interface TextEscaper {
String escape(String text);
}

View File

@@ -30,8 +30,8 @@ public class PerformanceTest {
@Test
public void test_escaper_performnce() throws Exception {
timeEscaper("SimpleEscaper#short", () -> SimpleEscaper.escape(shortTestString));
timeEscaper("SimpleEscaper#long", () -> SimpleEscaper.escape(longTestString));
timeEscaper("SimpleEscaper#short", () -> new SimpleEscaper().escape(shortTestString));
timeEscaper("SimpleEscaper#long", () -> new SimpleEscaper().escape(longTestString));
timeEscaper("ApacheEscaper#short", () -> StringEscapeUtils.escapeHtml4(shortTestString));
timeEscaper("ApacheEscaper#long", () -> StringEscapeUtils.escapeHtml4(longTestString));
}

View File

@@ -0,0 +1,40 @@
package j2html;
import j2html.utils.SimpleEscaper;
import j2html.utils.TextEscaper;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
public class TextEscaperTest {
@Test
public void testTextEscaper() throws Exception {
assertThat("default text escaper is SimpleEscaper",
Config.textEscaper, is(instanceOf(SimpleEscaper.class)));
String expected = "&lt;div&gt;&lt;/div&gt;";
assertThat("default text escaper works",
Config.textEscaper.escape("<div></div>"), is(expected));
Config.textEscaper = new NoOpEscaper();
assertThat("user can change text escaper implementation",
Config.textEscaper, is(instanceOf(NoOpEscaper.class)));
expected = "<div></div>";
assertThat("user provided text escaper actually works",
Config.textEscaper.escape("<div></div>"), is(expected));
}
private static class NoOpEscaper implements TextEscaper {
@Override
public String escape(String text) {
return text;
}
}
}