Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id EDB60200C43 for ; Sun, 12 Mar 2017 03:08:14 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id EC5A5160B7B; Sun, 12 Mar 2017 02:08:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9021C160B99 for ; Sun, 12 Mar 2017 03:08:10 +0100 (CET) Received: (qmail 53414 invoked by uid 500); 12 Mar 2017 02:08:09 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 53045 invoked by uid 99); 12 Mar 2017 02:08:09 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Mar 2017 02:08:09 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B50B13A4854 for ; Sun, 12 Mar 2017 02:08:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1008161 [41/44] - in /websites/production/commons/content/proper/commons-text: ./ apidocs/ apidocs/org/apache/commons/text/ apidocs/org/apache/commons/text/class-use/ apidocs/org/apache/commons/text/diff/ apidocs/org/apache/commons/text/di... Date: Sun, 12 Mar 2017 02:08:05 -0000 To: notifications@commons.apache.org From: chtompki@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170312020807.B50B13A4854@svn01-us-west.apache.org> archived-at: Sun, 12 Mar 2017 02:08:15 -0000 Modified: websites/production/commons/content/proper/commons-text/xref/org/apache/commons/text/StringEscapeUtils.html ============================================================================== --- websites/production/commons/content/proper/commons-text/xref/org/apache/commons/text/StringEscapeUtils.html (original) +++ websites/production/commons/content/proper/commons-text/xref/org/apache/commons/text/StringEscapeUtils.html Sun Mar 12 02:08:01 2017 @@ -34,937 +34,845 @@ 26 import org.apache.commons.text.translate.NumericEntityEscaper; 27 import org.apache.commons.text.translate.NumericEntityUnescaper; 28 import org.apache.commons.text.translate.OctalUnescaper; -29 import org.apache.commons.text.translate.SingleLookupTranslator; -30 import org.apache.commons.text.translate.UnicodeUnescaper; -31 import org.apache.commons.text.translate.UnicodeUnpairedSurrogateRemover; -32 -33 import java.io.IOException; -34 import java.io.Writer; -35 import java.util.Collections; -36 import java.util.HashMap; -37 import java.util.Map; -38 -39 /** -40 * <p>Escapes and unescapes {@code String}s for -41 * Java, Java Script, HTML and XML.</p> -42 * -43 * <p>#ThreadSafe#</p> +29 import org.apache.commons.text.translate.UnicodeUnescaper; +30 import org.apache.commons.text.translate.UnicodeUnpairedSurrogateRemover; +31 +32 import java.io.IOException; +33 import java.io.Writer; +34 import java.util.Collections; +35 import java.util.HashMap; +36 import java.util.Map; +37 +38 /** +39 * <p>Escapes and unescapes {@code String}s for +40 * Java, Java Script, HTML and XML.</p> +41 * +42 * <p>#ThreadSafe#</p> +43 * 44 * -45 * -46 * <p> -47 * This code has been adapted from Apache Commons Lang 3.5. -48 * </p> -49 * -50 * @since 1.0 -51 */ -52 public class StringEscapeUtils { -53 -54 /* ESCAPE TRANSLATORS */ -55 -56 /** -57 * Translator object for escaping Java. -58 * -59 * While {@link #escapeJava(String)} is the expected method of use, this -60 * object allows the Java escaping functionality to be used -61 * as the foundation for a custom translator. -62 */ -63 public static final CharSequenceTranslator ESCAPE_JAVA; -64 static { -65 Map<CharSequence, CharSequence> escapeJavaMap = new HashMap<>(); -66 escapeJavaMap.put("\"", "\\\""); -67 escapeJavaMap.put("\\", "\\\\"); -68 ESCAPE_JAVA = new AggregateTranslator( -69 new LookupTranslator(Collections.unmodifiableMap(escapeJavaMap)), -70 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE), -71 JavaUnicodeEscaper.outsideOf(32, 0x7f) -72 ); -73 } -74 -75 /** -76 * Translator object for escaping EcmaScript/JavaScript. -77 * -78 * While {@link #escapeEcmaScript(String)} is the expected method of use, this -79 * object allows the EcmaScript escaping functionality to be used -80 * as the foundation for a custom translator. -81 */ -82 public static final CharSequenceTranslator ESCAPE_ECMASCRIPT; -83 static { -84 Map<CharSequence, CharSequence> escapeEcmaScriptMap = new HashMap<>(); -85 escapeEcmaScriptMap.put("'", "\\'"); -86 escapeEcmaScriptMap.put("\"", "\\\""); -87 escapeEcmaScriptMap.put("\\", "\\\\"); -88 escapeEcmaScriptMap.put("/", "\\/"); -89 ESCAPE_ECMASCRIPT = new AggregateTranslator( -90 new LookupTranslator(Collections.unmodifiableMap(escapeEcmaScriptMap)), -91 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE), -92 JavaUnicodeEscaper.outsideOf(32, 0x7f) -93 ); -94 } -95 -96 /** -97 * Translator object for escaping Json. -98 * -99 * While {@link #escapeJson(String)} is the expected method of use, this -100 * object allows the Json escaping functionality to be used -101 * as the foundation for a custom translator. -102 */ -103 public static final CharSequenceTranslator ESCAPE_JSON; -104 static { -105 Map<CharSequence, CharSequence> escapeJsonMap = new HashMap<>(); -106 escapeJsonMap.put("\"", "\\\""); -107 escapeJsonMap.put("\\", "\\\\"); -108 escapeJsonMap.put("/", "\\/"); -109 ESCAPE_JSON = new AggregateTranslator( -110 new LookupTranslator(Collections.unmodifiableMap(escapeJsonMap)), -111 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE), -112 JavaUnicodeEscaper.outsideOf(32, 0x7f) -113 ); -114 } -115 -116 /** -117 * Translator object for escaping XML 1.0. -118 * -119 * While {@link #escapeXml10(String)} is the expected method of use, this -120 * object allows the XML escaping functionality to be used -121 * as the foundation for a custom translator. -122 */ -123 public static final CharSequenceTranslator ESCAPE_XML10; -124 static { -125 Map<CharSequence, CharSequence> escapeXml10Map = new HashMap<>(); -126 escapeXml10Map.put("\u0000", StringUtils.EMPTY); -127 escapeXml10Map.put("\u0001", StringUtils.EMPTY); -128 escapeXml10Map.put("\u0002", StringUtils.EMPTY); -129 escapeXml10Map.put("\u0003", StringUtils.EMPTY); -130 escapeXml10Map.put("\u0004", StringUtils.EMPTY); -131 escapeXml10Map.put("\u0005", StringUtils.EMPTY); -132 escapeXml10Map.put("\u0006", StringUtils.EMPTY); -133 escapeXml10Map.put("\u0007", StringUtils.EMPTY); -134 escapeXml10Map.put("\u0008", StringUtils.EMPTY); -135 escapeXml10Map.put("\u000b", StringUtils.EMPTY); -136 escapeXml10Map.put("\u000c", StringUtils.EMPTY); -137 escapeXml10Map.put("\u000e", StringUtils.EMPTY); -138 escapeXml10Map.put("\u000f", StringUtils.EMPTY); -139 escapeXml10Map.put("\u0010", StringUtils.EMPTY); -140 escapeXml10Map.put("\u0011", StringUtils.EMPTY); -141 escapeXml10Map.put("\u0012", StringUtils.EMPTY); -142 escapeXml10Map.put("\u0013", StringUtils.EMPTY); -143 escapeXml10Map.put("\u0014", StringUtils.EMPTY); -144 escapeXml10Map.put("\u0015", StringUtils.EMPTY); -145 escapeXml10Map.put("\u0016", StringUtils.EMPTY); -146 escapeXml10Map.put("\u0017", StringUtils.EMPTY); -147 escapeXml10Map.put("\u0018", StringUtils.EMPTY); -148 escapeXml10Map.put("\u0019", StringUtils.EMPTY); -149 escapeXml10Map.put("\u001a", StringUtils.EMPTY); -150 escapeXml10Map.put("\u001b", StringUtils.EMPTY); -151 escapeXml10Map.put("\u001c", StringUtils.EMPTY); -152 escapeXml10Map.put("\u001d", StringUtils.EMPTY); -153 escapeXml10Map.put("\u001e", StringUtils.EMPTY); -154 escapeXml10Map.put("\u001f", StringUtils.EMPTY); -155 escapeXml10Map.put("\ufffe", StringUtils.EMPTY); -156 escapeXml10Map.put("\uffff", StringUtils.EMPTY); -157 ESCAPE_XML10 = new AggregateTranslator( -158 new LookupTranslator(EntityArrays.BASIC_ESCAPE), -159 new LookupTranslator(EntityArrays.APOS_ESCAPE), -160 new LookupTranslator(Collections.unmodifiableMap(escapeXml10Map)), -161 NumericEntityEscaper.between(0x7f, 0x84), -162 NumericEntityEscaper.between(0x86, 0x9f), -163 new UnicodeUnpairedSurrogateRemover() -164 ); -165 } -166 -167 /** -168 * Translator object for escaping XML 1.1. -169 * -170 * While {@link #escapeXml11(String)} is the expected method of use, this -171 * object allows the XML escaping functionality to be used -172 * as the foundation for a custom translator. -173 */ -174 public static final CharSequenceTranslator ESCAPE_XML11; -175 static { -176 Map<CharSequence, CharSequence> escapeXml11Map = new HashMap<>(); -177 escapeXml11Map.put("\u0000", StringUtils.EMPTY); -178 escapeXml11Map.put("\u000b", "&#11;"); -179 escapeXml11Map.put("\u000c", "&#12;"); -180 escapeXml11Map.put("\ufffe", StringUtils.EMPTY); -181 escapeXml11Map.put("\uffff", StringUtils.EMPTY); -182 ESCAPE_XML11 = new AggregateTranslator( -183 new LookupTranslator(EntityArrays.BASIC_ESCAPE), -184 new LookupTranslator(EntityArrays.APOS_ESCAPE), -185 new LookupTranslator(Collections.unmodifiableMap(escapeXml11Map)), -186 NumericEntityEscaper.between(0x1, 0x8), -187 NumericEntityEscaper.between(0xe, 0x1f), -188 NumericEntityEscaper.between(0x7f, 0x84), -189 NumericEntityEscaper.between(0x86, 0x9f), -190 new UnicodeUnpairedSurrogateRemover() -191 ); -192 } -193 -194 /** -195 * Translator object for escaping HTML version 3.0. -196 * -197 * While {@link #escapeHtml3(String)} is the expected method of use, this -198 * object allows the HTML escaping functionality to be used -199 * as the foundation for a custom translator. -200 */ -201 public static final CharSequenceTranslator ESCAPE_HTML3 = -202 new AggregateTranslator( -203 new LookupTranslator(EntityArrays.BASIC_ESCAPE), -204 new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE) -205 ); -206 -207 /** -208 * The improved translator object for escaping HTML version 3.0. -209 * The 'improved' part of this translator is that it checks if the html is already translated. -210 * This check prevents double, triple, or recursive translations. -211 * -212 * While {@link #escapeHtml3Once(String)} is the expected method of use, this -213 * object allows the HTML escaping functionality to be used -214 * as the foundation for a custom translator. -215 * -216 * Note that, multiple lookup tables should be passed to this translator -217 * instead of passing multiple instances of this translator to the -218 * AggregateTranslator. Because, a SingleLookupTranslator only checks the values of the -219 * lookup table passed to that instance while deciding whether a value is -220 * already translated or not. -221 */ -222 public static final CharSequenceTranslator ESCAPE_HTML3_ONCE = -223 new SingleLookupTranslator(EntityArrays.BASIC_ESCAPE, EntityArrays.ISO8859_1_ESCAPE); -224 -225 -226 /** -227 * Translator object for escaping HTML version 4.0. -228 * -229 * While {@link #escapeHtml4(String)} is the expected method of use, this -230 * object allows the HTML escaping functionality to be used -231 * as the foundation for a custom translator. -232 */ -233 public static final CharSequenceTranslator ESCAPE_HTML4 = -234 new AggregateTranslator( -235 new LookupTranslator(EntityArrays.BASIC_ESCAPE), -236 new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE), -237 new LookupTranslator(EntityArrays.HTML40_EXTENDED_ESCAPE) -238 ); -239 -240 /** -241 * The improved translator object for escaping HTML version 4.0. -242 * The 'improved' part of this translator is that it checks if the html is already translated. -243 * This check prevents double, triple, or recursive translations. -244 * -245 * While {@link #escapeHtml4Once(String)} is the expected method of use, this -246 * object allows the HTML escaping functionality to be used -247 * as the foundation for a custom translator. -248 * -249 * Note that, multiple lookup tables should be passed to this translator -250 * instead of passing multiple instances of this translator to the -251 * AggregateTranslator. Because, a SingleLookupTranslator only checks the values of the -252 * lookup table passed to that instance while deciding whether a value is -253 * already translated or not. -254 */ -255 public static final CharSequenceTranslator ESCAPE_HTML4_ONCE = -256 new SingleLookupTranslator( -257 EntityArrays.BASIC_ESCAPE, -258 EntityArrays.ISO8859_1_ESCAPE, -259 EntityArrays.HTML40_EXTENDED_ESCAPE -260 ); -261 -262 /** -263 * Translator object for escaping individual Comma Separated Values. -264 * -265 * While {@link #escapeCsv(String)} is the expected method of use, this -266 * object allows the CSV escaping functionality to be used -267 * as the foundation for a custom translator. -268 */ -269 public static final CharSequenceTranslator ESCAPE_CSV = new CsvTranslators.CsvEscaper(); -270 -271 /** -272 * Translator object for escaping Shell command language. -273 * -274 * @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html">Shell Command Language</a> -275 */ -276 public static final CharSequenceTranslator ESCAPE_XSI; -277 static { -278 Map<CharSequence, CharSequence> escapeXsiMap = new HashMap<>(); -279 escapeXsiMap.put("|", "\\|"); -280 escapeXsiMap.put("&", "\\&"); -281 escapeXsiMap.put(";", "\\;"); -282 escapeXsiMap.put("<", "\\<"); -283 escapeXsiMap.put(">", "\\>"); -284 escapeXsiMap.put("(", "\\("); -285 escapeXsiMap.put(")", "\\)"); -286 escapeXsiMap.put("$", "\\$"); -287 escapeXsiMap.put("`", "\\`"); -288 escapeXsiMap.put("\\", "\\\\"); -289 escapeXsiMap.put("\"", "\\\""); -290 escapeXsiMap.put("'", "\\'"); -291 escapeXsiMap.put(" ", "\\ "); -292 escapeXsiMap.put("\t", "\\\t"); -293 escapeXsiMap.put("\r\n", ""); -294 escapeXsiMap.put("\n", ""); -295 escapeXsiMap.put("*", "\\*"); -296 escapeXsiMap.put("?", "\\?"); -297 escapeXsiMap.put("[", "\\["); -298 escapeXsiMap.put("#", "\\#"); -299 escapeXsiMap.put("~", "\\~"); -300 escapeXsiMap.put("=", "\\="); -301 escapeXsiMap.put("%", "\\%"); -302 ESCAPE_XSI = new LookupTranslator( -303 Collections.unmodifiableMap(escapeXsiMap) -304 ); -305 } +45 * <p> +46 * This code has been adapted from Apache Commons Lang 3.5. +47 * </p> +48 * +49 * @since 1.0 +50 */ +51 public class StringEscapeUtils { +52 +53 /* ESCAPE TRANSLATORS */ +54 +55 /** +56 * Translator object for escaping Java. +57 * +58 * While {@link #escapeJava(String)} is the expected method of use, this +59 * object allows the Java escaping functionality to be used +60 * as the foundation for a custom translator. +61 */ +62 public static final CharSequenceTranslator ESCAPE_JAVA; +63 static { +64 Map<CharSequence, CharSequence> escapeJavaMap = new HashMap<>(); +65 escapeJavaMap.put("\"", "\\\""); +66 escapeJavaMap.put("\\", "\\\\"); +67 ESCAPE_JAVA = new AggregateTranslator( +68 new LookupTranslator(Collections.unmodifiableMap(escapeJavaMap)), +69 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE), +70 JavaUnicodeEscaper.outsideOf(32, 0x7f) +71 ); +72 } +73 +74 /** +75 * Translator object for escaping EcmaScript/JavaScript. +76 * +77 * While {@link #escapeEcmaScript(String)} is the expected method of use, this +78 * object allows the EcmaScript escaping functionality to be used +79 * as the foundation for a custom translator. +80 */ +81 public static final CharSequenceTranslator ESCAPE_ECMASCRIPT; +82 static { +83 Map<CharSequence, CharSequence> escapeEcmaScriptMap = new HashMap<>(); +84 escapeEcmaScriptMap.put("'", "\\'"); +85 escapeEcmaScriptMap.put("\"", "\\\""); +86 escapeEcmaScriptMap.put("\\", "\\\\"); +87 escapeEcmaScriptMap.put("/", "\\/"); +88 ESCAPE_ECMASCRIPT = new AggregateTranslator( +89 new LookupTranslator(Collections.unmodifiableMap(escapeEcmaScriptMap)), +90 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE), +91 JavaUnicodeEscaper.outsideOf(32, 0x7f) +92 ); +93 } +94 +95 /** +96 * Translator object for escaping Json. +97 * +98 * While {@link #escapeJson(String)} is the expected method of use, this +99 * object allows the Json escaping functionality to be used +100 * as the foundation for a custom translator. +101 */ +102 public static final CharSequenceTranslator ESCAPE_JSON; +103 static { +104 Map<CharSequence, CharSequence> escapeJsonMap = new HashMap<>(); +105 escapeJsonMap.put("\"", "\\\""); +106 escapeJsonMap.put("\\", "\\\\"); +107 escapeJsonMap.put("/", "\\/"); +108 ESCAPE_JSON = new AggregateTranslator( +109 new LookupTranslator(Collections.unmodifiableMap(escapeJsonMap)), +110 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE), +111 JavaUnicodeEscaper.outsideOf(32, 0x7f) +112 ); +113 } +114 +115 /** +116 * Translator object for escaping XML 1.0. +117 * +118 * While {@link #escapeXml10(String)} is the expected method of use, this +119 * object allows the XML escaping functionality to be used +120 * as the foundation for a custom translator. +121 */ +122 public static final CharSequenceTranslator ESCAPE_XML10; +123 static { +124 Map<CharSequence, CharSequence> escapeXml10Map = new HashMap<>(); +125 escapeXml10Map.put("\u0000", StringUtils.EMPTY); +126 escapeXml10Map.put("\u0001", StringUtils.EMPTY); +127 escapeXml10Map.put("\u0002", StringUtils.EMPTY); +128 escapeXml10Map.put("\u0003", StringUtils.EMPTY); +129 escapeXml10Map.put("\u0004", StringUtils.EMPTY); +130 escapeXml10Map.put("\u0005", StringUtils.EMPTY); +131 escapeXml10Map.put("\u0006", StringUtils.EMPTY); +132 escapeXml10Map.put("\u0007", StringUtils.EMPTY); +133 escapeXml10Map.put("\u0008", StringUtils.EMPTY); +134 escapeXml10Map.put("\u000b", StringUtils.EMPTY); +135 escapeXml10Map.put("\u000c", StringUtils.EMPTY); +136 escapeXml10Map.put("\u000e", StringUtils.EMPTY); +137 escapeXml10Map.put("\u000f", StringUtils.EMPTY); +138 escapeXml10Map.put("\u0010", StringUtils.EMPTY); +139 escapeXml10Map.put("\u0011", StringUtils.EMPTY); +140 escapeXml10Map.put("\u0012", StringUtils.EMPTY); +141 escapeXml10Map.put("\u0013", StringUtils.EMPTY); +142 escapeXml10Map.put("\u0014", StringUtils.EMPTY); +143 escapeXml10Map.put("\u0015", StringUtils.EMPTY); +144 escapeXml10Map.put("\u0016", StringUtils.EMPTY); +145 escapeXml10Map.put("\u0017", StringUtils.EMPTY); +146 escapeXml10Map.put("\u0018", StringUtils.EMPTY); +147 escapeXml10Map.put("\u0019", StringUtils.EMPTY); +148 escapeXml10Map.put("\u001a", StringUtils.EMPTY); +149 escapeXml10Map.put("\u001b", StringUtils.EMPTY); +150 escapeXml10Map.put("\u001c", StringUtils.EMPTY); +151 escapeXml10Map.put("\u001d", StringUtils.EMPTY); +152 escapeXml10Map.put("\u001e", StringUtils.EMPTY); +153 escapeXml10Map.put("\u001f", StringUtils.EMPTY); +154 escapeXml10Map.put("\ufffe", StringUtils.EMPTY); +155 escapeXml10Map.put("\uffff", StringUtils.EMPTY); +156 ESCAPE_XML10 = new AggregateTranslator( +157 new LookupTranslator(EntityArrays.BASIC_ESCAPE), +158 new LookupTranslator(EntityArrays.APOS_ESCAPE), +159 new LookupTranslator(Collections.unmodifiableMap(escapeXml10Map)), +160 NumericEntityEscaper.between(0x7f, 0x84), +161 NumericEntityEscaper.between(0x86, 0x9f), +162 new UnicodeUnpairedSurrogateRemover() +163 ); +164 } +165 +166 /** +167 * Translator object for escaping XML 1.1. +168 * +169 * While {@link #escapeXml11(String)} is the expected method of use, this +170 * object allows the XML escaping functionality to be used +171 * as the foundation for a custom translator. +172 */ +173 public static final CharSequenceTranslator ESCAPE_XML11; +174 static { +175 Map<CharSequence, CharSequence> escapeXml11Map = new HashMap<>(); +176 escapeXml11Map.put("\u0000", StringUtils.EMPTY); +177 escapeXml11Map.put("\u000b", "&#11;"); +178 escapeXml11Map.put("\u000c", "&#12;"); +179 escapeXml11Map.put("\ufffe", StringUtils.EMPTY); +180 escapeXml11Map.put("\uffff", StringUtils.EMPTY); +181 ESCAPE_XML11 = new AggregateTranslator( +182 new LookupTranslator(EntityArrays.BASIC_ESCAPE), +183 new LookupTranslator(EntityArrays.APOS_ESCAPE), +184 new LookupTranslator(Collections.unmodifiableMap(escapeXml11Map)), +185 NumericEntityEscaper.between(0x1, 0x8), +186 NumericEntityEscaper.between(0xe, 0x1f), +187 NumericEntityEscaper.between(0x7f, 0x84), +188 NumericEntityEscaper.between(0x86, 0x9f), +189 new UnicodeUnpairedSurrogateRemover() +190 ); +191 } +192 +193 /** +194 * Translator object for escaping HTML version 3.0. +195 * +196 * While {@link #escapeHtml3(String)} is the expected method of use, this +197 * object allows the HTML escaping functionality to be used +198 * as the foundation for a custom translator. +199 */ +200 public static final CharSequenceTranslator ESCAPE_HTML3 = +201 new AggregateTranslator( +202 new LookupTranslator(EntityArrays.BASIC_ESCAPE), +203 new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE) +204 ); +205 +206 /** +207 * Translator object for escaping HTML version 4.0. +208 * +209 * While {@link #escapeHtml4(String)} is the expected method of use, this +210 * object allows the HTML escaping functionality to be used +211 * as the foundation for a custom translator. +212 */ +213 public static final CharSequenceTranslator ESCAPE_HTML4 = +214 new AggregateTranslator( +215 new LookupTranslator(EntityArrays.BASIC_ESCAPE), +216 new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE), +217 new LookupTranslator(EntityArrays.HTML40_EXTENDED_ESCAPE) +218 ); +219 +220 /** +221 * Translator object for escaping individual Comma Separated Values. +222 * +223 * While {@link #escapeCsv(String)} is the expected method of use, this +224 * object allows the CSV escaping functionality to be used +225 * as the foundation for a custom translator. +226 */ +227 public static final CharSequenceTranslator ESCAPE_CSV = new CsvTranslators.CsvEscaper(); +228 +229 /** +230 * Translator object for escaping Shell command language. +231 * +232 * @see <a href="http://pubs.opengroup.org/onlinepubs/7908799/xcu/chap2.html">Shell Command Language</a> +233 */ +234 public static final CharSequenceTranslator ESCAPE_XSI; +235 static { +236 Map<CharSequence, CharSequence> escapeXsiMap = new HashMap<>(); +237 escapeXsiMap.put("|", "\\|"); +238 escapeXsiMap.put("&", "\\&"); +239 escapeXsiMap.put(";", "\\;"); +240 escapeXsiMap.put("<", "\\<"); +241 escapeXsiMap.put(">", "\\>"); +242 escapeXsiMap.put("(", "\\("); +243 escapeXsiMap.put(")", "\\)"); +244 escapeXsiMap.put("$", "\\$"); +245 escapeXsiMap.put("`", "\\`"); +246 escapeXsiMap.put("\\", "\\\\"); +247 escapeXsiMap.put("\"", "\\\""); +248 escapeXsiMap.put("'", "\\'"); +249 escapeXsiMap.put(" ", "\\ "); +250 escapeXsiMap.put("\t", "\\\t"); +251 escapeXsiMap.put("\r\n", ""); +252 escapeXsiMap.put("\n", ""); +253 escapeXsiMap.put("*", "\\*"); +254 escapeXsiMap.put("?", "\\?"); +255 escapeXsiMap.put("[", "\\["); +256 escapeXsiMap.put("#", "\\#"); +257 escapeXsiMap.put("~", "\\~"); +258 escapeXsiMap.put("=", "\\="); +259 escapeXsiMap.put("%", "\\%"); +260 ESCAPE_XSI = new LookupTranslator( +261 Collections.unmodifiableMap(escapeXsiMap) +262 ); +263 } +264 +265 /* UNESCAPE TRANSLATORS */ +266 +267 /** +268 * Translator object for unescaping escaped Java. +269 * +270 * While {@link #unescapeJava(String)} is the expected method of use, this +271 * object allows the Java unescaping functionality to be used +272 * as the foundation for a custom translator. +273 */ +274 public static final CharSequenceTranslator UNESCAPE_JAVA; +275 static { +276 Map<CharSequence, CharSequence> unescapeJavaMap = new HashMap<>(); +277 unescapeJavaMap.put("\\\\", "\\"); +278 unescapeJavaMap.put("\\\"", "\""); +279 unescapeJavaMap.put("\\'", "'"); +280 unescapeJavaMap.put("\\", ""); +281 UNESCAPE_JAVA = new AggregateTranslator( +282 new OctalUnescaper(), // .between('\1', '\377'), +283 new UnicodeUnescaper(), +284 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_UNESCAPE), +285 new LookupTranslator(Collections.unmodifiableMap(unescapeJavaMap)) +286 ); +287 } +288 +289 /** +290 * Translator object for unescaping escaped EcmaScript. +291 * +292 * While {@link #unescapeEcmaScript(String)} is the expected method of use, this +293 * object allows the EcmaScript unescaping functionality to be used +294 * as the foundation for a custom translator. +295 */ +296 public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = UNESCAPE_JAVA; +297 +298 /** +299 * Translator object for unescaping escaped Json. +300 * +301 * While {@link #unescapeJson(String)} is the expected method of use, this +302 * object allows the Json unescaping functionality to be used +303 * as the foundation for a custom translator. +304 */ +305 public static final CharSequenceTranslator UNESCAPE_JSON = UNESCAPE_JAVA; 306 -307 /* UNESCAPE TRANSLATORS */ -308 -309 /** -310 * Translator object for unescaping escaped Java. -311 * -312 * While {@link #unescapeJava(String)} is the expected method of use, this -313 * object allows the Java unescaping functionality to be used -314 * as the foundation for a custom translator. -315 */ -316 // TODO: throw "illegal character: \92" as an Exception if a \ on the end of the Java (as per the compiler)? -317 public static final CharSequenceTranslator UNESCAPE_JAVA; -318 static { -319 Map<CharSequence, CharSequence> unescapeJavaMap = new HashMap<>(); -320 unescapeJavaMap.put("\\\\", "\\"); -321 unescapeJavaMap.put("\\\"", "\""); -322 unescapeJavaMap.put("\\'", "'"); -323 unescapeJavaMap.put("\\", ""); -324 UNESCAPE_JAVA = new AggregateTranslator( -325 new OctalUnescaper(), // .between('\1', '\377'), -326 new UnicodeUnescaper(), -327 new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_UNESCAPE), [... 1164 lines stripped ...]