"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java" between
httpcomponents-client-4.5.7-src.tar.gz and httpcomponents-client-4.5.8-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

URIBuilder.java  (httpcomponents-client-4.5.7-src):URIBuilder.java  (httpcomponents-client-4.5.8-src)
skipping to change at line 33 skipping to change at line 33
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
* *
*/ */
package org.apache.http.client.utils; package org.apache.http.client.utils;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.http.Consts; import org.apache.http.Consts;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.conn.util.InetAddressUtils; import org.apache.http.conn.util.InetAddressUtils;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.TextUtils; import org.apache.http.util.TextUtils;
/** /**
skipping to change at line 56 skipping to change at line 58
*/ */
public class URIBuilder { public class URIBuilder {
private String scheme; private String scheme;
private String encodedSchemeSpecificPart; private String encodedSchemeSpecificPart;
private String encodedAuthority; private String encodedAuthority;
private String userInfo; private String userInfo;
private String encodedUserInfo; private String encodedUserInfo;
private String host; private String host;
private int port; private int port;
private String path;
private String encodedPath; private String encodedPath;
private List<String> pathSegments;
private String encodedQuery; private String encodedQuery;
private List<NameValuePair> queryParams; private List<NameValuePair> queryParams;
private String query; private String query;
private Charset charset; private Charset charset;
private String fragment; private String fragment;
private String encodedFragment; private String encodedFragment;
/** /**
* Constructs an empty instance. * Constructs an empty instance.
*/ */
skipping to change at line 115 skipping to change at line 117
return charset; return charset;
} }
private List <NameValuePair> parseQuery(final String query, final Charset ch arset) { private List <NameValuePair> parseQuery(final String query, final Charset ch arset) {
if (query != null && !query.isEmpty()) { if (query != null && !query.isEmpty()) {
return URLEncodedUtils.parse(query, charset); return URLEncodedUtils.parse(query, charset);
} }
return null; return null;
} }
private List <String> parsePath(final String path, final Charset charset) {
if (path != null && !path.isEmpty()) {
return URLEncodedUtils.parsePathSegments(path, charset);
}
return null;
}
/** /**
* Builds a {@link URI} instance. * Builds a {@link URI} instance.
*/ */
public URI build() throws URISyntaxException { public URI build() throws URISyntaxException {
return new URI(buildString()); return new URI(buildString());
} }
private String buildString() { private String buildString() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
if (this.scheme != null) { if (this.scheme != null) {
skipping to change at line 150 skipping to change at line 159
sb.append("[").append(this.host).append("]"); sb.append("[").append(this.host).append("]");
} else { } else {
sb.append(this.host); sb.append(this.host);
} }
if (this.port >= 0) { if (this.port >= 0) {
sb.append(":").append(this.port); sb.append(":").append(this.port);
} }
} }
if (this.encodedPath != null) { if (this.encodedPath != null) {
sb.append(normalizePath(this.encodedPath, sb.length() == 0)); sb.append(normalizePath(this.encodedPath, sb.length() == 0));
} else if (this.path != null) { } else if (this.pathSegments != null) {
sb.append(encodePath(normalizePath(this.path, sb.length() == 0)) sb.append(encodePath(this.pathSegments));
);
} }
if (this.encodedQuery != null) { if (this.encodedQuery != null) {
sb.append("?").append(this.encodedQuery); sb.append("?").append(this.encodedQuery);
} else if (this.queryParams != null && !this.queryParams.isEmpty()) { } else if (this.queryParams != null && !this.queryParams.isEmpty()) {
sb.append("?").append(encodeUrlForm(this.queryParams)); sb.append("?").append(encodeUrlForm(this.queryParams));
} else if (this.query != null) { } else if (this.query != null) {
sb.append("?").append(encodeUric(this.query)); sb.append("?").append(encodeUric(this.query));
} }
} }
if (this.encodedFragment != null) { if (this.encodedFragment != null) {
skipping to change at line 189 skipping to change at line 198
private void digestURI(final URI uri) { private void digestURI(final URI uri) {
this.scheme = uri.getScheme(); this.scheme = uri.getScheme();
this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
this.encodedAuthority = uri.getRawAuthority(); this.encodedAuthority = uri.getRawAuthority();
this.host = uri.getHost(); this.host = uri.getHost();
this.port = uri.getPort(); this.port = uri.getPort();
this.encodedUserInfo = uri.getRawUserInfo(); this.encodedUserInfo = uri.getRawUserInfo();
this.userInfo = uri.getUserInfo(); this.userInfo = uri.getUserInfo();
this.encodedPath = uri.getRawPath(); this.encodedPath = uri.getRawPath();
this.path = uri.getPath(); this.pathSegments = parsePath(uri.getRawPath(), this.charset != null ? t his.charset : Consts.UTF_8);
this.encodedQuery = uri.getRawQuery(); this.encodedQuery = uri.getRawQuery();
this.queryParams = parseQuery(uri.getRawQuery(), this.charset != null ? this.charset : Consts.UTF_8); this.queryParams = parseQuery(uri.getRawQuery(), this.charset != null ? this.charset : Consts.UTF_8);
this.encodedFragment = uri.getRawFragment(); this.encodedFragment = uri.getRawFragment();
this.fragment = uri.getFragment(); this.fragment = uri.getFragment();
} }
private String encodeUserInfo(final String userInfo) { private String encodeUserInfo(final String userInfo) {
return URLEncodedUtils.encUserInfo(userInfo, this.charset != null ? this .charset : Consts.UTF_8); return URLEncodedUtils.encUserInfo(userInfo, this.charset != null ? this .charset : Consts.UTF_8);
} }
private String encodePath(final String path) { private String encodePath(final List<String> pathSegments) {
return URLEncodedUtils.encPath(path, this.charset != null ? this.charset return URLEncodedUtils.formatSegments(pathSegments, this.charset != null
: Consts.UTF_8); ? this.charset : Consts.UTF_8);
} }
private String encodeUrlForm(final List<NameValuePair> params) { private String encodeUrlForm(final List<NameValuePair> params) {
return URLEncodedUtils.format(params, this.charset != null ? this.charse t : Consts.UTF_8); return URLEncodedUtils.format(params, this.charset != null ? this.charse t : Consts.UTF_8);
} }
private String encodeUric(final String fragment) { private String encodeUric(final String fragment) {
return URLEncodedUtils.encUric(fragment, this.charset != null ? this.cha rset : Consts.UTF_8); return URLEncodedUtils.encUric(fragment, this.charset != null ? this.cha rset : Consts.UTF_8);
} }
skipping to change at line 262 skipping to change at line 271
*/ */
public URIBuilder setPort(final int port) { public URIBuilder setPort(final int port) {
this.port = port < 0 ? -1 : port; this.port = port < 0 ? -1 : port;
this.encodedSchemeSpecificPart = null; this.encodedSchemeSpecificPart = null;
this.encodedAuthority = null; this.encodedAuthority = null;
return this; return this;
} }
/** /**
* Sets URI path. The value is expected to be unescaped and may contain non ASCII characters. * Sets URI path. The value is expected to be unescaped and may contain non ASCII characters.
*
* @return this.
*/ */
public URIBuilder setPath(final String path) { public URIBuilder setPath(final String path) {
this.path = path; return setPathSegments(path != null ? URLEncodedUtils.splitPathSegments(
path) : null);
}
/**
* Sets URI path. The value is expected to be unescaped and may contain non
ASCII characters.
*
* @return this.
*
* @since 4.5.8
*/
public URIBuilder setPathSegments(final String... pathSegments) {
this.pathSegments = pathSegments.length > 0 ? Arrays.asList(pathSegments
) : null;
this.encodedSchemeSpecificPart = null;
this.encodedPath = null;
return this;
}
/**
* Sets URI path. The value is expected to be unescaped and may contain non
ASCII characters.
*
* @return this.
*
* @since 4.5.8
*/
public URIBuilder setPathSegments(final List<String> pathSegments) {
this.pathSegments = pathSegments != null && pathSegments.size() > 0 ? ne
w ArrayList<String>(pathSegments) : null;
this.encodedSchemeSpecificPart = null; this.encodedSchemeSpecificPart = null;
this.encodedPath = null; this.encodedPath = null;
return this; return this;
} }
/** /**
* Removes URI query. * Removes URI query.
*/ */
public URIBuilder removeQuery() { public URIBuilder removeQuery() {
this.queryParams = null; this.queryParams = null;
skipping to change at line 465 skipping to change at line 501
* @since 4.3 * @since 4.3
*/ */
public boolean isAbsolute() { public boolean isAbsolute() {
return this.scheme != null; return this.scheme != null;
} }
/** /**
* @since 4.3 * @since 4.3
*/ */
public boolean isOpaque() { public boolean isOpaque() {
return this.path == null; return isPathEmpty();
} }
public String getScheme() { public String getScheme() {
return this.scheme; return this.scheme;
} }
public String getUserInfo() { public String getUserInfo() {
return this.userInfo; return this.userInfo;
} }
public String getHost() { public String getHost() {
return this.host; return this.host;
} }
public int getPort() { public int getPort() {
return this.port; return this.port;
} }
/**
* @since 4.5.8
*/
public boolean isPathEmpty() {
return (this.pathSegments == null || this.pathSegments.isEmpty()) && thi
s.encodedPath == null;
}
/**
* @since 4.5.8
*/
public List<String> getPathSegments() {
return this.pathSegments != null ? new ArrayList<String>(this.pathSegmen
ts) : Collections.<String>emptyList();
}
public String getPath() { public String getPath() {
return this.path; if (this.pathSegments == null) {
return null;
}
final StringBuilder result = new StringBuilder();
for (final String segment : this.pathSegments) {
result.append('/').append(segment);
}
return result.toString();
}
/**
* @since 4.5.8
*/
public boolean isQueryEmpty() {
return (this.queryParams == null || this.queryParams.isEmpty()) && this.
encodedQuery == null;
} }
public List<NameValuePair> getQueryParams() { public List<NameValuePair> getQueryParams() {
return this.queryParams != null return this.queryParams != null ? new ArrayList<NameValuePair>(this.quer
? new ArrayList<NameValuePair>(this.queryParams) yParams) : Collections.<NameValuePair>emptyList();
: new ArrayList<NameValuePair>();
} }
public String getFragment() { public String getFragment() {
return this.fragment; return this.fragment;
} }
@Override @Override
public String toString() { public String toString() {
return buildString(); return buildString();
} }
 End of changes. 13 change blocks. 
14 lines changed or deleted 84 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)