private String encodeIfNecessary(String path, @Nullable HttpServletRequest request, Resource location) { if (shouldEncodeRelativePath(location) && request != null) { Charset charset = this.locationCharsets.getOrDefault(location, StandardCharsets.UTF_8); StringBuilder sb = new StringBuilder(); StringTokenizer tokenizer = new StringTokenizer(path, "/"); while (tokenizer.hasMoreTokens()) { String value = UriUtils.encode(tokenizer.nextToken(), charset); sb.append(value); sb.append("/"); } if (!path.endsWith("/")) { sb.setLength(sb.length() - 1); } return sb.toString(); } else { return path; } }
private String encodeIfNecessary(String path, @Nullable HttpServletRequest request, Resource location) { if (shouldEncodeRelativePath(location) && request != null) { Charset charset = this.locationCharsets.getOrDefault(location, StandardCharsets.UTF_8); StringBuilder sb = new StringBuilder(); StringTokenizer tokenizer = new StringTokenizer(path, "/"); while (tokenizer.hasMoreTokens()) { String value = UriUtils.encode(tokenizer.nextToken(), charset); sb.append(value); sb.append("/"); } if (!path.endsWith("/")) { sb.setLength(sb.length() - 1); } return sb.toString(); } else { return path; } }
private String encodeIfNecessary(String path, HttpServletRequest request, Resource location) { if (shouldEncodeRelativePath(location) && request != null) { Charset charset = this.locationCharsets.get(location); charset = charset != null ? charset : DEFAULT_CHARSET; StringBuilder sb = new StringBuilder(); StringTokenizer tokenizer = new StringTokenizer(path, "/"); while (tokenizer.hasMoreTokens()) { String value = null; try { value = UriUtils.encode(tokenizer.nextToken(), charset.name()); } catch (UnsupportedEncodingException ex) { // Should never happen throw new IllegalStateException("Unexpected error", ex); } sb.append(value); sb.append("/"); } if (!path.endsWith("/")) { sb.setLength(sb.length() - 1); } return sb.toString(); } else { return path; } }