OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 Google Inc. | 2 * Copyright (c) 2010 Google Inc. |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.apache.org/licenses/LICENSE-2.0 | 7 * http://www.apache.org/licenses/LICENSE-2.0 |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 13 matching lines...) Expand all Loading... |
24 * @since 1.0 | 24 * @since 1.0 |
25 */ | 25 */ |
26 public final class CharEscapers { | 26 public final class CharEscapers { |
27 | 27 |
28 private static final Escaper URI_ESCAPER = | 28 private static final Escaper URI_ESCAPER = |
29 new PercentEscaper(PercentEscaper.SAFECHARS_URLENCODER, true); | 29 new PercentEscaper(PercentEscaper.SAFECHARS_URLENCODER, true); |
30 | 30 |
31 private static final Escaper URI_PATH_ESCAPER = | 31 private static final Escaper URI_PATH_ESCAPER = |
32 new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false); | 32 new PercentEscaper(PercentEscaper.SAFEPATHCHARS_URLENCODER, false); |
33 | 33 |
| 34 private static final Escaper URI_RESERVED_ESCAPER = |
| 35 new PercentEscaper(PercentEscaper.SAFE_PLUS_RESERVED_CHARS_URLENCODER, fal
se); |
| 36 |
34 private static final Escaper URI_USERINFO_ESCAPER = | 37 private static final Escaper URI_USERINFO_ESCAPER = |
35 new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER, false); | 38 new PercentEscaper(PercentEscaper.SAFEUSERINFOCHARS_URLENCODER, false); |
36 | 39 |
37 private static final Escaper URI_QUERY_STRING_ESCAPER = | 40 private static final Escaper URI_QUERY_STRING_ESCAPER = |
38 new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER, false); | 41 new PercentEscaper(PercentEscaper.SAFEQUERYSTRINGCHARS_URLENCODER, false); |
39 | 42 |
40 /** | 43 /** |
41 * Escapes the string value so it can be safely included in URIs. For details
on escaping URIs, | 44 * Escapes the string value so it can be safely included in URIs. For details
on escaping URIs, |
42 * see <a href="http://tools.ietf.org/html/rfc3986#section-2.4">RFC 3986 - sec
tion 2.4</a>. | 45 * see <a href="http://tools.ietf.org/html/rfc3986#section-2.4">RFC 3986 - sec
tion 2.4</a>. |
43 * | 46 * |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 * <a href="http://tools.ietf.org/html/rfc3986"> RFC 3986</a>:<br> | 121 * <a href="http://tools.ietf.org/html/rfc3986"> RFC 3986</a>:<br> |
119 * <i>"URI producers and normalizers should use uppercase hexadecimal digits f
or all | 122 * <i>"URI producers and normalizers should use uppercase hexadecimal digits f
or all |
120 * percent-encodings."</i> | 123 * percent-encodings."</i> |
121 * </p> | 124 * </p> |
122 */ | 125 */ |
123 public static String escapeUriPath(String value) { | 126 public static String escapeUriPath(String value) { |
124 return URI_PATH_ESCAPER.escape(value); | 127 return URI_PATH_ESCAPER.escape(value); |
125 } | 128 } |
126 | 129 |
127 /** | 130 /** |
| 131 * Escapes a URI path but retains all reserved characters, including all gener
al delimiters. |
| 132 * That is the same as {@link #escapeUriPath(String)} except that it keeps '?'
, '+', and '/' |
| 133 * unescaped. |
| 134 */ |
| 135 public static String escapeUriPathWithoutReserved(String value) { |
| 136 return URI_RESERVED_ESCAPER.escape(value); |
| 137 } |
| 138 |
| 139 /** |
128 * Escapes the string value so it can be safely included in URI user info part
. For details on | 140 * Escapes the string value so it can be safely included in URI user info part
. For details on |
129 * escaping URIs, see <a href="http://tools.ietf.org/html/rfc3986#section-2.4"
>RFC 3986 - section | 141 * escaping URIs, see <a href="http://tools.ietf.org/html/rfc3986#section-2.4"
>RFC 3986 - section |
130 * 2.4</a>. | 142 * 2.4</a>. |
131 * | 143 * |
132 * <p> | 144 * <p> |
133 * When encoding a String, the following rules apply: | 145 * When encoding a String, the following rules apply: |
134 * <ul> | 146 * <ul> |
135 * <li>The alphanumeric characters "a" through "z", "A" through "Z" and "0" th
rough "9" remain the | 147 * <li>The alphanumeric characters "a" through "z", "A" through "Z" and "0" th
rough "9" remain the |
136 * same. | 148 * same. |
137 * <li>The unreserved characters ".", "-", "~", and "_" remain the same. | 149 * <li>The unreserved characters ".", "-", "~", and "_" remain the same. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 * percent-encodings."</i> | 209 * percent-encodings."</i> |
198 * </p> | 210 * </p> |
199 */ | 211 */ |
200 public static String escapeUriQuery(String value) { | 212 public static String escapeUriQuery(String value) { |
201 return URI_QUERY_STRING_ESCAPER.escape(value); | 213 return URI_QUERY_STRING_ESCAPER.escape(value); |
202 } | 214 } |
203 | 215 |
204 private CharEscapers() { | 216 private CharEscapers() { |
205 } | 217 } |
206 } | 218 } |
OLD | NEW |