master
Juergen Hoeller 13 years ago
parent ca4eafd4dd
commit 45a0ae3fb9
  1. 8
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationMappingUtils.java
  2. 47
      org.springframework.web/src/main/java/org/springframework/web/util/UriUtils.java

@ -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");
* 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.
* @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
*/
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.
* @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
*/
public static boolean checkHeaders(String[] headers, HttpServletRequest request) {
@ -109,7 +109,7 @@ abstract class ServletAnnotationMappingUtils {
}
}
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 value = header.substring(separator + 1);
if (isMediaTypeHeader(key)) {

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

Loading…
Cancel
Save