polishing

This commit is contained in:
Juergen Hoeller 2011-12-01 15:11:32 +00:00
parent ca4eafd4dd
commit 45a0ae3fb9
2 changed files with 19 additions and 36 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2011 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,7 +54,7 @@ abstract class ServletAnnotationMappingUtils {
/** /**
* Check whether the given request matches the specified parameter conditions. * Check whether the given request matches the specified parameter conditions.
* @param params the parameter conditions, following * @param params the parameter conditions, following
* {@link org.springframework.web.bind.annotation.RequestMapping#params() RequestMapping.#params()} * {@link org.springframework.web.bind.annotation.RequestMapping#params() RequestMapping.#params()}
* @param request the current HTTP request to check * @param request the current HTTP request to check
*/ */
public static boolean checkParameters(String[] params, HttpServletRequest request) { public static boolean checkParameters(String[] params, HttpServletRequest request) {
@ -91,7 +91,7 @@ abstract class ServletAnnotationMappingUtils {
/** /**
* Check whether the given request matches the specified header conditions. * Check whether the given request matches the specified header conditions.
* @param headers the header conditions, following * @param headers the header conditions, following
* {@link org.springframework.web.bind.annotation.RequestMapping#headers() RequestMapping.headers()} * {@link org.springframework.web.bind.annotation.RequestMapping#headers() RequestMapping.headers()}
* @param request the current HTTP request to check * @param request the current HTTP request to check
*/ */
public static boolean checkHeaders(String[] headers, HttpServletRequest request) { public static boolean checkHeaders(String[] headers, HttpServletRequest request) {
@ -109,7 +109,7 @@ abstract class ServletAnnotationMappingUtils {
} }
} }
else { else {
boolean negated = separator > 0 && header.charAt(separator - 1) == '!'; boolean negated = (separator > 0 && header.charAt(separator - 1) == '!');
String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1); String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1);
String value = header.substring(separator + 1); String value = header.substring(separator + 1);
if (isMediaTypeHeader(key)) { if (isMediaTypeHeader(key)) {

View File

@ -33,17 +33,16 @@ import org.springframework.util.Assert;
* </ul> * </ul>
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @see <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>
* @since 3.0 * @since 3.0
* @see <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>
*/ */
public abstract class UriUtils { public abstract class UriUtils {
// encoding // encoding
/** /**
* Encodes the given source URI into an encoded String. All various URI components are encoded according to their * Encodes the given source URI into an encoded String. All various URI components are
* respective valid character sets. * encoded according to their respective valid character sets.
*
* @param uri the URI to be encoded * @param uri the URI to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded URI * @return the encoded URI
@ -57,10 +56,10 @@ public abstract class UriUtils {
} }
/** /**
* Encodes the given HTTP URI into an encoded String. All various URI components are encoded according to their * Encodes the given HTTP URI into an encoded String. All various URI components are
* respective valid character sets. <p><strong>Note</strong> that this method does not support fragments ({@code #}), * encoded according to their respective valid character sets.
* <p><strong>Note</strong> that this method does not support fragments ({@code #}),
* as these are not supposed to be sent to the server, but retained by the client. * as these are not supposed to be sent to the server, but retained by the client.
*
* @param httpUrl the HTTP URL to be encoded * @param httpUrl the HTTP URL to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded URL * @return the encoded URL
@ -74,12 +73,11 @@ public abstract class UriUtils {
} }
/** /**
* Encodes the given source URI components into an encoded String. All various URI components are optional, but encoded * Encodes the given source URI components into an encoded String. All various URI components
* according to their respective valid character sets. * are optional, but encoded according to their respective valid character sets.
*
* @param scheme the scheme * @param scheme the scheme
* @param authority the authority * @param authority the authority
* @param userInfo the user info * @param userInfo the user info
* @param host the host * @param host the host
* @param port the port * @param port the port
* @param path the path * @param path the path
@ -90,16 +88,11 @@ public abstract class UriUtils {
* @throws IllegalArgumentException when the given uri parameter is not a valid URI * @throws IllegalArgumentException when the given uri parameter is not a valid URI
* @throws UnsupportedEncodingException when the given encoding parameter is not supported * @throws UnsupportedEncodingException when the given encoding parameter is not supported
*/ */
public static String encodeUriComponents(String scheme, public static String encodeUriComponents(String scheme, String authority, String userInfo,
String authority, String host, String port, String path, String query, String fragment, String encoding)
String userInfo , throws UnsupportedEncodingException {
String host,
String port, int portAsInt = (port != null ? Integer.parseInt(port) : -1);
String path,
String query,
String fragment,
String encoding) throws UnsupportedEncodingException {
int portAsInt = port != null ? Integer.parseInt(port) : -1;
UriComponentsBuilder builder = UriComponentsBuilder.newInstance(); UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
builder.scheme(scheme).userInfo(userInfo).host(host).port(portAsInt); builder.scheme(scheme).userInfo(userInfo).host(host).port(portAsInt);
@ -110,11 +103,11 @@ public abstract class UriUtils {
return encoded.toUriString(); return encoded.toUriString();
} }
// encoding convenience methods // encoding convenience methods
/** /**
* Encodes the given URI scheme with the given encoding. * Encodes the given URI scheme with the given encoding.
*
* @param scheme the scheme to be encoded * @param scheme the scheme to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded scheme * @return the encoded scheme
@ -126,7 +119,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI authority with the given encoding. * Encodes the given URI authority with the given encoding.
*
* @param authority the authority to be encoded * @param authority the authority to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded authority * @return the encoded authority
@ -138,7 +130,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI user info with the given encoding. * Encodes the given URI user info with the given encoding.
*
* @param userInfo the user info to be encoded * @param userInfo the user info to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded user info * @return the encoded user info
@ -150,7 +141,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI host with the given encoding. * Encodes the given URI host with the given encoding.
*
* @param host the host to be encoded * @param host the host to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded host * @return the encoded host
@ -162,7 +152,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI port with the given encoding. * Encodes the given URI port with the given encoding.
*
* @param port the port to be encoded * @param port the port to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded port * @return the encoded port
@ -174,7 +163,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI path with the given encoding. * Encodes the given URI path with the given encoding.
*
* @param path the path to be encoded * @param path the path to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded path * @return the encoded path
@ -186,7 +174,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI path segment with the given encoding. * Encodes the given URI path segment with the given encoding.
*
* @param segment the segment to be encoded * @param segment the segment to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded segment * @return the encoded segment
@ -198,7 +185,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI query with the given encoding. * Encodes the given URI query with the given encoding.
*
* @param query the query to be encoded * @param query the query to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded query * @return the encoded query
@ -210,7 +196,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI query parameter with the given encoding. * Encodes the given URI query parameter with the given encoding.
*
* @param queryParam the query parameter to be encoded * @param queryParam the query parameter to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded query parameter * @return the encoded query parameter
@ -222,7 +207,6 @@ public abstract class UriUtils {
/** /**
* Encodes the given URI fragment with the given encoding. * Encodes the given URI fragment with the given encoding.
*
* @param fragment the fragment to be encoded * @param fragment the fragment to be encoded
* @param encoding the character encoding to encode to * @param encoding the character encoding to encode to
* @return the encoded fragment * @return the encoded fragment
@ -243,7 +227,6 @@ public abstract class UriUtils {
* <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li> * <li>Special characters {@code "-"}, {@code "_"}, {@code "."}, and {@code "*"} stay the same.</li>
* <li>A sequence "<code>%<i>xy</i></code>" is interpreted as a hexadecimal representation of the character.</li> * <li>A sequence "<code>%<i>xy</i></code>" is interpreted as a hexadecimal representation of the character.</li>
* </ul> * </ul>
*
* @param source the source string * @param source the source string
* @param encoding the encoding * @param encoding the encoding
* @return the decoded URI * @return the decoded URI