Remove stringutils and add simple escaper (#34)

This commit is contained in:
David
2017-01-29 17:26:54 +01:00
parent f44d62d93a
commit e0b0425da4
4 changed files with 33 additions and 9 deletions

View File

@@ -52,11 +52,6 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
<packaging>jar</packaging>

View File

@@ -1,6 +1,7 @@
package j2html.attributes;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
import j2html.utils.SimpleEscaper;
public class Attribute {
private String name;
@@ -8,7 +9,7 @@ public class Attribute {
public Attribute(String name, String value) {
this.name = name;
this.value = escapeHtml4(value);
this.value = SimpleEscaper.escape(value);
}
public Attribute(String name) {

View File

@@ -1,6 +1,6 @@
package j2html.tags;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
import j2html.utils.SimpleEscaper;
public class Text extends DomContent {
@@ -12,7 +12,7 @@ public class Text extends DomContent {
@Override
public String render() {
return escapeHtml4(text);
return SimpleEscaper.escape(text);
}
}

View File

@@ -0,0 +1,28 @@
package j2html.utils;
import java.util.HashMap;
import java.util.Map;
public class SimpleEscaper {
private static Map<Character, String> map = new HashMap<Character, String>() {{
put('&', "&amp;");
put('<', "&lt;");
put('>', "&gt;");
put('"', "&quot;");
put('\'', "&#x27;");
}};
public static String escape(String s) {
if(s == null) {
return null;
}
String escapedString = "";
for(char c : s.toCharArray()) {
String escaped = map.get(c);
escapedString += escaped != null ? escaped : c;
}
return escapedString;
}
}