• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.testng.util;
2 
3 import org.testng.collections.Lists;
4 import org.testng.collections.Maps;
5 
6 import java.util.List;
7 import java.util.Map;
8 
9 public class Strings {
isNullOrEmpty(String string)10   public static boolean isNullOrEmpty(String string) {
11     return string == null || string.length() == 0; // string.isEmpty() in Java 6
12   }
13 
14   private static List<String> ESCAPE_HTML_LIST = Lists.newArrayList(
15     "&", "&amp;",
16     "<", "&lt;",
17     ">", "&gt;"
18   );
19 
20   private static final Map<String, String> ESCAPE_HTML_MAP = Maps.newLinkedHashMap();
21 
22   static {
23     for (int i = 0; i < ESCAPE_HTML_LIST.size(); i += 2) {
ESCAPE_HTML_LIST.get(i)24       ESCAPE_HTML_MAP.put(ESCAPE_HTML_LIST.get(i), ESCAPE_HTML_LIST.get(i + 1));
25     }
26   }
27 
escapeHtml(String text)28   public static String escapeHtml(String text) {
29     String result = text;
30     for (Map.Entry<String, String> entry : ESCAPE_HTML_MAP.entrySet()) {
31       result = result.replace(entry.getKey(), entry.getValue());
32     }
33     return result;
34   }
35 
main(String[] args)36   public static void main(String[] args) {
37     System.out.println(escapeHtml("10 < 20 && 30 > 20"));
38   }
39 }
40