HTTPCLIENT-770: code cleanups

Contributed by Paul Lindner <lindner at inuus.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@653041 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-05-03 10:39:28 +00:00
parent 257a0ee548
commit aff60e4629
45 changed files with 123 additions and 154 deletions

View File

@ -133,9 +133,9 @@ public class UsernamePasswordCredentials implements Credentials {
*/
@Override
public String toString() {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(this.userName);
result.append(":");
result.append(':');
result.append((this.password == null) ? "null" : this.password);
return result.toString();
}

View File

@ -45,13 +45,13 @@ import org.apache.http.auth.Credentials;
public class AuthState {
/** Actual authentication scheme */
private AuthScheme authScheme = null;
private AuthScheme authScheme;
/** Actual authentication scope */
private AuthScope authScope = null;
private AuthScope authScope;
/** Credentials selected for authentication */
private Credentials credentials = null;
private Credentials credentials;
/**
* Default constructor.

View File

@ -48,7 +48,7 @@ import org.apache.http.protocol.HTTP;
abstract class HttpEntityEnclosingRequestBase
extends HttpRequestBase implements HttpEntityEnclosingRequest {
private HttpEntity entity = null;
private HttpEntity entity;
public HttpEntityEnclosingRequestBase() {
super();

View File

@ -93,8 +93,8 @@ public class HttpOptions extends HttpRequestBase {
while (it.hasNext()) {
Header header = it.nextHeader();
HeaderElement[] elements = header.getElements();
for (int i = 0; i < elements.length; i++) {
methods.add(elements[i].getName());
for (HeaderElement element : elements) {
methods.add(element.getName());
}
}
return methods;

View File

@ -149,8 +149,7 @@ public class RequestAddCookies implements HttpRequestInterceptor {
List<Cookie> cookies = cookieStore.getCookies();
// Find cookies matching the given origin
List<Cookie> matchedCookies = new ArrayList<Cookie>();
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
for (Cookie cookie : cookies) {
if (cookieSpec.match(cookie, cookieOrigin)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cookie " + cookie + " match " + cookieOrigin);
@ -161,16 +160,15 @@ public class RequestAddCookies implements HttpRequestInterceptor {
// Generate Cookie request headers
if (!matchedCookies.isEmpty()) {
List<Header> headers = cookieSpec.formatCookies(matchedCookies);
for (int i = 0; i < headers.size(); i++) {
request.addHeader(headers.get(i));
for (Header header : headers) {
request.addHeader(header);
}
}
int ver = cookieSpec.getVersion();
if (ver > 0) {
boolean needVersionHeader = false;
for (int i = 0; i < matchedCookies.size(); i++) {
Cookie cookie = matchedCookies.get(i);
for (Cookie cookie : matchedCookies) {
if (ver != cookie.getVersion()) {
needVersionHeader = true;
}

View File

@ -33,7 +33,6 @@ package org.apache.http.client.protocol;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import org.apache.http.Header;
import org.apache.http.HttpException;
@ -66,8 +65,8 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
Collection<?> defHeaders = (Collection<?>) request.getParams().getParameter(
ClientPNames.DEFAULT_HEADERS);
if (defHeaders != null) {
for (Iterator<?> it = defHeaders.iterator(); it.hasNext(); ) {
request.addHeader((Header) it.next());
for (Object defHeader : defHeaders) {
request.addHeader((Header) defHeader);
}
}
}

View File

@ -118,8 +118,7 @@ public class ResponseProcessCookies implements HttpResponseInterceptor {
Header header = iterator.nextHeader();
try {
List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin);
for (int c = 0; c < cookies.size(); c++) {
Cookie cookie = cookies.get(c);
for (Cookie cookie : cookies) {
try {
cookieSpec.validate(cookie, cookieOrigin);
cookieStore.addCookie(cookie);

View File

@ -86,22 +86,22 @@ public class URIUtils {
}
buffer.append(host);
if (port > 0) {
buffer.append(":");
buffer.append(':');
buffer.append(port);
}
}
if (path == null || !path.startsWith("/")) {
buffer.append("/");
buffer.append('/');
}
if (path != null) {
buffer.append(path);
}
if (query != null) {
buffer.append("?");
buffer.append('?');
buffer.append(query);
}
if (fragment != null) {
buffer.append("#");
buffer.append('#');
buffer.append(fragment);
}
return new URI(buffer.toString());

View File

@ -39,6 +39,7 @@ import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.SocketFactory;
@ -64,7 +65,7 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
* Gets the singleton instance of this class.
* @return the one and only plain socket factory
*/
public static final MultihomePlainSocketFactory getSocketFactory() {
public static MultihomePlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY;
}
@ -126,9 +127,7 @@ public final class MultihomePlainSocketFactory implements SocketFactory {
InetAddress[] inetadrs = InetAddress.getAllByName(host);
List<InetAddress> addresses = new ArrayList<InetAddress>(inetadrs.length);
for (InetAddress inetadr: inetadrs) {
addresses.add(inetadr);
}
addresses.addAll(Arrays.asList(inetadrs));
Collections.shuffle(addresses);
IOException lastEx = null;

View File

@ -84,7 +84,7 @@ public class HttpRouteParams {
* @return the default proxy set in the argument parameters, or
* <code>null</code> if not set
*/
public final static HttpHost getDefaultProxy(HttpParams params) {
public static HttpHost getDefaultProxy(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
@ -108,7 +108,7 @@ public class HttpRouteParams {
* <code>null</code> by {@link #getDefaultProxy},
* to allow for explicit unsetting in hierarchies.
*/
public final static void setDefaultProxy(HttpParams params,
public static void setDefaultProxy(HttpParams params,
HttpHost proxy) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
@ -128,7 +128,7 @@ public class HttpRouteParams {
* @return the forced route set in the argument parameters, or
* <code>null</code> if not set
*/
public final static HttpRoute getForcedRoute(HttpParams params) {
public static HttpRoute getForcedRoute(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
@ -152,7 +152,7 @@ public class HttpRouteParams {
* <code>null</code> by {@link #getForcedRoute},
* to allow for explicit unsetting in hierarchies.
*/
public final static void setForcedRoute(HttpParams params,
public static void setForcedRoute(HttpParams params,
HttpRoute route) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
@ -173,7 +173,7 @@ public class HttpRouteParams {
* @return the local address set in the argument parameters, or
* <code>null</code> if not set
*/
public final static InetAddress getLocalAddress(HttpParams params) {
public static InetAddress getLocalAddress(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
@ -191,7 +191,7 @@ public class HttpRouteParams {
* @param params the parameters in which to set the value
* @param local the value to set, may be <code>null</code>
*/
public final static void setLocalAddress(HttpParams params,
public static void setLocalAddress(HttpParams params,
InetAddress local) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");

View File

@ -239,8 +239,8 @@ public final class HttpRoute implements RouteInfo, Cloneable {
if ((proxies == null) || (proxies.length < 1))
return null;
for (int i=0; i<proxies.length; i++) {
if (proxies[i] == null)
for (HttpHost proxy : proxies) {
if (proxy == null)
throw new IllegalArgumentException
("Proxy chain may not contain null elements.");
}
@ -281,7 +281,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
if (hop >= hopcount)
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds route length " + hopcount +".");
" exceeds route length " + hopcount);
HttpHost result = null;
if (hop < hopcount-1)
@ -385,8 +385,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
hc ^= localAddress.hashCode();
if (this.proxyChain != null) {
hc ^= proxyChain.length;
for (int i=0; i<proxyChain.length; i++)
hc ^= proxyChain[i].hashCode();
for (HttpHost aProxyChain : proxyChain) hc ^= aProxyChain.hashCode();
}
if (this.secure)
@ -422,8 +421,8 @@ public final class HttpRoute implements RouteInfo, Cloneable {
cab.append('s');
cab.append("}->");
if (this.proxyChain != null) {
for (int i=0; i<this.proxyChain.length; i++) {
cab.append(this.proxyChain[i]);
for (HttpHost aProxyChain : this.proxyChain) {
cab.append(aProxyChain);
cab.append("->");
}
}

View File

@ -57,7 +57,7 @@ public final class PlainSocketFactory implements SocketFactory {
* Gets the singleton instance of this class.
* @return the one and only plain socket factory
*/
public static final PlainSocketFactory getSocketFactory() {
public static PlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY;
}

View File

@ -162,9 +162,9 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
names.add(cns[0]);
}
if(subjectAlts != null) {
for(int i = 0; i < subjectAlts.length; i++) {
if(subjectAlts[i] != null) {
names.add(subjectAlts[i]);
for (String subjectAlt : subjectAlts) {
if (subjectAlt != null) {
names.add(subjectAlt);
}
}
}
@ -303,12 +303,11 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
cpe.printStackTrace();
}
if(c != null) {
Iterator<List<?>> it = c.iterator();
while(it.hasNext()) {
List<?> list = it.next();
for (List<?> aC : c) {
List<?> list = aC;
int type = ((Integer) list.get(0)).intValue();
// If type is 2, then we've got a dNSName
if(type == 2) {
if (type == 2) {
String s = (String) list.get(1);
subjectAltList.add(s);
}

View File

@ -53,7 +53,7 @@ public final class CookieOrigin {
throw new IllegalArgumentException(
"Host of origin may not be null");
}
if (host.trim().equals("")) {
if (host.trim().length() == 0) {
throw new IllegalArgumentException(
"Host of origin may not be blank");
}
@ -66,7 +66,7 @@ public final class CookieOrigin {
}
this.host = host.toLowerCase(Locale.ENGLISH);
this.port = port;
if (!path.trim().equals("")) {
if (path.trim().length() != 0) {
this.path = path;
} else {
this.path = "/";
@ -93,15 +93,15 @@ public final class CookieOrigin {
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("[");
buffer.append('[');
if (this.secure) {
buffer.append("(secure)");
}
buffer.append(this.host);
buffer.append(":");
buffer.append(':');
buffer.append(Integer.toString(this.port));
buffer.append(this.path);
buffer.append("]");
buffer.append(']');
return buffer.toString();
}

View File

@ -58,7 +58,7 @@ public class CookiePathComparator implements Serializable, Comparator<Cookie> {
path = "/";
}
if (!path.endsWith("/")) {
path = path + "/";
path = path + '/';
}
return path;
}

View File

@ -120,7 +120,7 @@ public class BasicScheme extends RFC2617Scheme {
*
* @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated
* @throws InvalidCredentialsException if authentication credentials
* @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials
* are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure

View File

@ -198,7 +198,7 @@ public class DigestScheme extends RFC2617Scheme {
* @param credentials A set of credentials to be used for athentication
* @param request The request being authenticated
*
* @throws InvalidCredentialsException if authentication credentials
* @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials
* are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
@ -242,10 +242,6 @@ public class DigestScheme extends RFC2617Scheme {
/**
* Creates an MD5 response digest.
*
* @param uname Username
* @param pwd Password
* @param charset The credential charset
*
* @return The created digest as string. This will be the response tag's
* value in the Authentication HTTP header.
* @throws AuthenticationException when MD5 is an unsupported algorithm
@ -311,7 +307,7 @@ public class DigestScheme extends RFC2617Scheme {
//we do not have access to the entity-body or its hash
//TODO: add Method ":" digest-uri-value ":" H(entity-body)
} else {
a2 = method + ":" + uri;
a2 = method + ':' + uri;
}
String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2)));

View File

@ -60,7 +60,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
/**
* Authentication parameter map.
*/
private Map<String, String> params = null;
private Map<String, String> params;
/**
* Flag whether authenticating against a proxy.
@ -131,8 +131,7 @@ public abstract class RFC2617Scheme implements AuthScheme {
}
this.params = new HashMap<String, String>(elements.length);
for (int i = 0; i < elements.length; i++) {
HeaderElement element = elements[i];
for (HeaderElement element : elements) {
this.params.put(element.getName(), element.getValue());
}
}

View File

@ -33,7 +33,6 @@ package org.apache.http.impl.client;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -73,8 +72,7 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
final Header[] headers) throws MalformedChallengeException {
Map<String, Header> map = new HashMap<String, Header>(headers.length);
for (int i = 0; i < headers.length; i++) {
Header header = headers[i];
for (Header header : headers) {
CharArrayBuffer buffer;
int pos;
if (header instanceof FormattedHeader) {
@ -125,9 +123,9 @@ public abstract class AbstractAuthenticationHandler implements AuthenticationHan
}
AuthScheme authScheme = null;
for (Iterator<String> it = authPrefs.iterator(); it.hasNext(); ) {
String id = it.next();
for (String id : authPrefs) {
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(id + " authentication scheme selected");

View File

@ -109,8 +109,8 @@ public class BasicCookieStore implements CookieStore {
*/
public synchronized void addCookies(Cookie[] cookies) {
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
this.addCookie(cookies[i]);
for (Cookie cooky : cookies) {
this.addCookie(cooky);
}
}
}

View File

@ -85,7 +85,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
* Find matching {@link Credentials credentials} for the given authentication scope.
*
* @param map the credentials hash map
* @param token the {@link AuthScope authentication scope}
* @param authscope the {@link AuthScope authentication scope}
* @return the credentials
*
*/

View File

@ -761,7 +761,7 @@ public class DefaultClientRequestDirector
StringBuilder buffer = new StringBuilder(host.length() + 6);
buffer.append(host);
buffer.append(":");
buffer.append(':');
buffer.append(Integer.toString(port));
String authority = buffer.toString();

View File

@ -54,7 +54,7 @@ import org.apache.http.protocol.HTTP;
class EntityEnclosingRequestWrapper extends RequestWrapper
implements HttpEntityEnclosingRequest {
private HttpEntity entity = null;
private HttpEntity entity;
public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request)
throws ProtocolException {

View File

@ -90,7 +90,7 @@ public abstract class AbstractPoolEntry {
/**
* Creates a new pool entry.
*
* @param occ the underlying connection for this entry
* @param connOperator the Connection Operator for this entry
* @param route the planned route for the connection,
* or <code>null</code>
*/

View File

@ -223,8 +223,8 @@ public class DefaultClientConnection extends SocketHttpClientConnection
if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug("<< " + response.getStatusLine().toString());
Header[] headers = response.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
HEADERS_LOG.debug("<< " + headers[i].toString());
for (Header header : headers) {
HEADERS_LOG.debug("<< " + header.toString());
}
}
return response;
@ -237,8 +237,8 @@ public class DefaultClientConnection extends SocketHttpClientConnection
if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug(">> " + request.getRequestLine().toString());
Header[] headers = request.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
HEADERS_LOG.debug(">> " + headers[i].toString());
for (Header header : headers) {
HEADERS_LOG.debug(">> " + header.toString());
}
}
}

View File

@ -361,7 +361,6 @@ public class SingleClientConnManager implements ClientConnectionManager {
/**
* Creates a new pool entry.
*
* @param occ the underlying connection for this entry
*/
protected PoolEntry() {
super(SingleClientConnManager.this.connOperator, null);
@ -403,7 +402,7 @@ public class SingleClientConnManager implements ClientConnectionManager {
* Creates a new connection adapter.
*
* @param entry the pool entry for the connection being wrapped
* @param plan the planned route for this connection
* @param route the planned route for this connection
*/
protected ConnAdapter(PoolEntry entry, HttpRoute route) {
super(SingleClientConnManager.this, entry);

View File

@ -52,7 +52,7 @@ public class Wire {
private void wire(String header, InputStream instream)
throws IOException {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
int ch;
while ((ch = instream.read()) != -1) {
if (ch == 13) {
@ -72,8 +72,8 @@ public class Wire {
}
}
if (buffer.length() > 0) {
buffer.append("\"");
buffer.insert(0, "\"");
buffer.append('\"');
buffer.insert(0, '\"');
buffer.insert(0, header);
log.debug(buffer.toString());
}

View File

@ -97,8 +97,6 @@ public abstract class AbstractConnPool implements RefQueueHandler {
/**
* Creates a new connection pool.
*
* @param mgr the connection manager
*/
protected AbstractConnPool() {
issuedConnections = new HashSet<BasicPoolEntryRef>();

View File

@ -251,8 +251,6 @@ public class ConnPoolByRoute extends AbstractConnPool {
* @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the <code>timeout</code>,
* may be <code>null</code> only if there is no timeout
* @param operator the connection operator, in case
* a connection has to be created
* @param aborter an object which can abort a {@link WaitingThread}.
*
* @return pool entry holding a connection for the route

View File

@ -62,10 +62,10 @@ public class RouteSpecificPool {
* This list is managed LIFO, to increase idle times and
* allow for closing connections that are not really needed.
*/
protected LinkedList<BasicPoolEntry> freeEntries;
protected final LinkedList<BasicPoolEntry> freeEntries;
/** The list of threads waiting for this pool. */
protected Queue<WaitingThread> waitingThreads;
protected final Queue<WaitingThread> waitingThreads;
/** The number of created entries. */
protected int numEntries;

View File

@ -37,7 +37,7 @@
The implementation of a thread-safe client connection manager.
<center>
<image src="doc-files/tsccm-structure.png" alt="Relation Diagram"/>
<img src="doc-files/tsccm-structure.png" alt="Relation Diagram"/>
</center>
<p>
@ -48,7 +48,7 @@ maintains a <i>Pool</i> (yellow) of connections and waiting threads.
Both Manager and Pool rely on <i>Operations</i> (cyan) to provide the
actual connections.
</p>
</p>
<p>
In order to allow connection garbage collection, it is
imperative that hard object references between the areas are
restricted to the relations indicated by arrows in the diagram:

View File

@ -363,7 +363,7 @@ public class BasicClientCookie implements SetCookie, ClientCookie {
private boolean isSecure;
/** The version of the cookie specification I was created from. */
private int cookieVersion = 0;
private int cookieVersion;
}

View File

@ -50,7 +50,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute");
}
if (value.trim().equals("")) {
if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for domain attribute");
}
cookie.setDomain(value);
@ -74,7 +74,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
if (domain == null) {
throw new MalformedCookieException("Cookie domain may not be null");
}
if (host.indexOf(".") >= 0) {
if (host.contains(".")) {
// Not required to have at least two dots. RFC 2965.
// A Set-Cookie2 with Domain=ajax.com will be accepted.
@ -114,7 +114,7 @@ public class BasicDomainHandler implements CookieAttributeHandler {
return true;
}
if (!domain.startsWith(".")) {
domain = "." + domain;
domain = '.' + domain;
}
return host.endsWith(domain) || host.equals(domain.substring(1));
}

View File

@ -47,7 +47,7 @@ public class BasicPathHandler implements CookieAttributeHandler {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (value == null || value.trim().equals("")) {
if (value == null || value.trim().length() == 0) {
value = "/";
}
cookie.setPath(value);

View File

@ -57,7 +57,7 @@ public class BasicSecureHandler extends AbstractCookieAttributeHandler {
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
return cookie.isSecure() ? origin.isSecure() : true;
return !cookie.isSecure() || origin.isSecure();
}
}

View File

@ -53,9 +53,9 @@ public class BestMatchSpec implements CookieSpec {
private final String[] datepatterns;
private final boolean oneHeader;
private RFC2965Spec strict = null;
private BrowserCompatSpec compat = null;
private NetscapeDraftSpec netscape = null;
private RFC2965Spec strict;
private BrowserCompatSpec compat;
private NetscapeDraftSpec netscape;
public BestMatchSpec(final String[] datepatterns, boolean oneHeader) {
super();

View File

@ -113,7 +113,7 @@ public class BrowserCompatSpec extends CookieSpecBase {
int i1 = headervalue.toLowerCase(Locale.ENGLISH).indexOf("expires=");
if (i1 != -1) {
i1 += "expires=".length();
int i2 = headervalue.indexOf(";", i1);
int i2 = headervalue.indexOf(';', i1);
if (i2 == -1) {
i2 = headervalue.length();
}

View File

@ -71,12 +71,10 @@ public abstract class CookieSpecBase extends AbstractCookieSpec {
protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin)
throws MalformedCookieException {
List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
for (int i = 0; i < elems.length; i++) {
HeaderElement headerelement = elems[i];
for (HeaderElement headerelement : elems) {
String name = headerelement.getName();
String value = headerelement.getValue();
if (name == null || name.equals("")) {
if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty");
}

View File

@ -152,8 +152,8 @@ public final class DateUtils {
dateValue = dateValue.substring (1, dateValue.length() - 1);
}
for (int i = 0; i < dateFormats.length; i++) {
SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormats[i]);
for (String dateFormat : dateFormats) {
SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
dateParser.set2DigitYearStart(startDate);
try {

View File

@ -50,7 +50,7 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
// Perform Netscape Cookie draft specific validation
String host = origin.getHost();
String domain = cookie.getDomain();
if (host.indexOf(".") >= 0) {
if (host.contains(".")) {
int domainParts = new StringTokenizer(domain, ".").countTokens();
if (isSpecialDomain(domain)) {
@ -78,16 +78,13 @@ public class NetscapeDomainHandler extends BasicDomainHandler {
*/
private static boolean isSpecialDomain(final String domain) {
final String ucDomain = domain.toUpperCase(Locale.ENGLISH);
if (ucDomain.endsWith(".COM")
return ucDomain.endsWith(".COM")
|| ucDomain.endsWith(".EDU")
|| ucDomain.endsWith(".NET")
|| ucDomain.endsWith(".GOV")
|| ucDomain.endsWith(".MIL")
|| ucDomain.endsWith(".ORG")
|| ucDomain.endsWith(".INT")) {
return true;
}
return false;
|| ucDomain.endsWith(".INT");
}
@Override

View File

@ -52,7 +52,7 @@ public class RFC2109DomainHandler implements CookieAttributeHandler {
if (value == null) {
throw new MalformedCookieException("Missing value for domain attribute");
}
if (value.trim().equals("")) {
if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for domain attribute");
}
cookie.setDomain(value);

View File

@ -146,8 +146,7 @@ public class RFC2109Spec extends CookieSpecBase {
private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
int version = Integer.MAX_VALUE;
// Pick the lowest common denominator
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
for (Cookie cookie : cookies) {
if (cookie.getVersion() < version) {
version = cookie.getVersion();
}
@ -157,9 +156,9 @@ public class RFC2109Spec extends CookieSpecBase {
buffer.append(": ");
buffer.append("$Version=");
buffer.append(Integer.toString(version));
for (int i = 0; i < cookies.size(); i++) {
for (Cookie cooky : cookies) {
buffer.append("; ");
Cookie cookie = cookies.get(i);
Cookie cookie = cooky;
formatCookieAsVer(buffer, cookie, version);
}
List<Header> headers = new ArrayList<Header>(1);
@ -169,8 +168,7 @@ public class RFC2109Spec extends CookieSpecBase {
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
List<Header> headers = new ArrayList<Header>(cookies.size());
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
for (Cookie cookie : cookies) {
int version = cookie.getVersion();
CharArrayBuffer buffer = new CharArrayBuffer(40);
buffer.append("Cookie: ");

View File

@ -49,7 +49,7 @@ public class RFC2109VersionHandler extends AbstractCookieAttributeHandler {
if (value == null) {
throw new MalformedCookieException("Missing value for version attribute");
}
if (value.trim().equals("")) {
if (value.trim().length() == 0) {
throw new MalformedCookieException("Blank value for version attribute");
}
try {

View File

@ -65,7 +65,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
throw new MalformedCookieException(
"Missing value for domain attribute");
}
if (domain.trim().equals("")) {
if (domain.trim().length() == 0) {
throw new MalformedCookieException(
"Blank value for domain attribute");
}
@ -76,7 +76,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
// a dot, the user agent supplies a leading dot ..."
// That effectively implies that the domain attribute
// MAY NOT be an IP address of a host name
domain = "." + domain;
domain = '.' + domain;
}
cookie.setDomain(domain);
}
@ -189,10 +189,7 @@ public class RFC2965DomainAttributeHandler implements CookieAttributeHandler {
// effective host name minus domain must not contain any dots
String effectiveHostWithoutDomain = host.substring(
0, host.length() - cookieDomain.length());
if (effectiveHostWithoutDomain.indexOf('.') != -1) {
return false;
}
return true;
return effectiveHostWithoutDomain.indexOf('.') == -1;
}
}

View File

@ -108,12 +108,10 @@ public class RFC2965Spec extends RFC2109Spec {
HeaderElement[] elems = header.getElements();
List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
for (int i = 0; i < elems.length; i++) {
HeaderElement headerelement = elems[i];
for (HeaderElement headerelement : elems) {
String name = headerelement.getName();
String value = headerelement.getValue();
if (name == null || name.equals("")) {
if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty");
}
@ -135,7 +133,7 @@ public class RFC2965Spec extends RFC2109Spec {
NameValuePair param = attribs[j];
attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
}
for (Map.Entry<String, NameValuePair> entry: attribmap.entrySet()) {
for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet()) {
NameValuePair attrib = entry.getValue();
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
@ -214,7 +212,7 @@ public class RFC2965Spec extends RFC2109Spec {
* the effective host name is the same as the host name. Note
* that all effective host names contain at least one dot.
*
* @param host host name where cookie is received from or being sent to.
* @param origin origin where cookie is received from or being sent to.
* @return
*/
private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) {