@Test public void testConstructorExists() { new EntityArrays(); }
@Test public void testHTML40_EXTENDED_ESCAPE(){ final Set<String> col0 = new HashSet<>(); final Set<String> col1 = new HashSet<>(); final String [][] sa = EntityArrays.HTML40_EXTENDED_ESCAPE(); for(int i =0; i <sa.length; i++){ assertTrue("Already added entry 0: "+i+" "+sa[i][0],col0.add(sa[i][0])); assertTrue("Already added entry 1: "+i+" "+sa[i][1],col1.add(sa[i][1])); } }
@Test public void testISO8859_1_ESCAPE(){ final Set<String> col0 = new HashSet<>(); final Set<String> col1 = new HashSet<>(); final String [][] sa = EntityArrays.ISO8859_1_ESCAPE(); boolean success = true; for(int i =0; i <sa.length; i++){ final boolean add0 = col0.add(sa[i][0]); final boolean add1 = col1.add(sa[i][1]); if (!add0) { success = false; System.out.println("Already added entry 0: "+i+" "+sa[i][0]+" "+sa[i][1]); } if (!add1) { success = false; System.out.println("Already added entry 1: "+i+" "+sa[i][0]+" "+sa[i][1]); } } assertTrue("One or more errors detected",success); }
/** * Returns the given input HTML with all necessary characters escaped. * * @param html * The input HTML. * @return The escaped version. */ public static String escapeHtml(CharSequence html) { return new AggregateTranslator( new LookupTranslator(new String[][]{{"/", "/"}}), new LookupTranslator(EntityArrays.BASIC_ESCAPE()), new LookupTranslator(EntityArrays.APOS_ESCAPE())//, ).translate(html); }
for (String[] ent : EntityArrays.ISO8859_1_UNESCAPE()) { xmlFile = xmlFile.replace(ent[0], ent[1]);
/** * Escape the string with given quote character. */ public static String escape(String value, char quote) { final CharSequenceTranslator escape = new LookupTranslator( new String[][]{ {Character.toString(quote), "\\" + quote}, {"\\", "\\\\"}, }).with( new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE()) ).with( JavaUnicodeEscaper.outsideOf(32, 0x7f) ); return quote + escape.translate(value) + quote; }