Renamed UriBuilder to URIBuilder
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1172642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
40a0ed44d2
commit
eab98043c4
|
@ -36,7 +36,10 @@ import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.http.protocol.HTTP;
|
import org.apache.http.protocol.HTTP;
|
||||||
|
|
||||||
public class UriBuilder {
|
/**
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public class URIBuilder {
|
||||||
|
|
||||||
private String scheme;
|
private String scheme;
|
||||||
private String schemeSpecificPart;
|
private String schemeSpecificPart;
|
||||||
|
@ -48,17 +51,17 @@ public class UriBuilder {
|
||||||
private List<NameValuePair> queryParams;
|
private List<NameValuePair> queryParams;
|
||||||
private String fragment;
|
private String fragment;
|
||||||
|
|
||||||
public UriBuilder() {
|
public URIBuilder() {
|
||||||
super();
|
super();
|
||||||
this.port = -1;
|
this.port = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UriBuilder(final String string) throws URISyntaxException {
|
public URIBuilder(final String string) throws URISyntaxException {
|
||||||
super();
|
super();
|
||||||
digestURI(new URI(string));
|
digestURI(new URI(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UriBuilder(final URI uri) {
|
public URIBuilder(final URI uri) {
|
||||||
super();
|
super();
|
||||||
digestURI(uri);
|
digestURI(uri);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +111,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets URI scheme.
|
* Sets URI scheme.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setScheme(final String scheme) {
|
public URIBuilder setScheme(final String scheme) {
|
||||||
this.scheme = scheme;
|
this.scheme = scheme;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +119,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets URI user-info.
|
* Sets URI user-info.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setUserInfo(final String userInfo) {
|
public URIBuilder setUserInfo(final String userInfo) {
|
||||||
this.userInfo = userInfo;
|
this.userInfo = userInfo;
|
||||||
this.schemeSpecificPart = null;
|
this.schemeSpecificPart = null;
|
||||||
this.authority = null;
|
this.authority = null;
|
||||||
|
@ -126,14 +129,14 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets URI user-info in a form of 'username:password'.
|
* Sets URI user-info in a form of 'username:password'.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setUserInfo(final String username, final String password) {
|
public URIBuilder setUserInfo(final String username, final String password) {
|
||||||
return setUserInfo(username + ':' + password);
|
return setUserInfo(username + ':' + password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets URI host.
|
* Sets URI host.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setHost(final String host) {
|
public URIBuilder setHost(final String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.schemeSpecificPart = null;
|
this.schemeSpecificPart = null;
|
||||||
this.authority = null;
|
this.authority = null;
|
||||||
|
@ -143,7 +146,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets URI port.
|
* Sets URI port.
|
||||||
*/
|
*/
|
||||||
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.schemeSpecificPart = null;
|
this.schemeSpecificPart = null;
|
||||||
this.authority = null;
|
this.authority = null;
|
||||||
|
@ -153,7 +156,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets URI path.
|
* Sets URI path.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setPath(final String path) {
|
public URIBuilder setPath(final String path) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.schemeSpecificPart = null;
|
this.schemeSpecificPart = null;
|
||||||
return this;
|
return this;
|
||||||
|
@ -162,7 +165,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Removes all query parameters.
|
* Removes all query parameters.
|
||||||
*/
|
*/
|
||||||
public UriBuilder removeQuery() {
|
public URIBuilder removeQuery() {
|
||||||
this.queryParams = null;
|
this.queryParams = null;
|
||||||
this.schemeSpecificPart = null;
|
this.schemeSpecificPart = null;
|
||||||
return this;
|
return this;
|
||||||
|
@ -171,7 +174,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Set URI query.
|
* Set URI query.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setQuery(final String query) {
|
public URIBuilder setQuery(final String query) {
|
||||||
this.queryParams = parseQuery(query, HTTP.UTF_8);
|
this.queryParams = parseQuery(query, HTTP.UTF_8);
|
||||||
this.schemeSpecificPart = null;
|
this.schemeSpecificPart = null;
|
||||||
return this;
|
return this;
|
||||||
|
@ -180,7 +183,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Adds a parameter-value pair to URI query.
|
* Adds a parameter-value pair to URI query.
|
||||||
*/
|
*/
|
||||||
public UriBuilder addParameter(final String param, final String value) {
|
public URIBuilder addParameter(final String param, final String value) {
|
||||||
if (this.queryParams == null) {
|
if (this.queryParams == null) {
|
||||||
this.queryParams = new ArrayList<NameValuePair>();
|
this.queryParams = new ArrayList<NameValuePair>();
|
||||||
}
|
}
|
||||||
|
@ -192,7 +195,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets parameter-value pair to URI query removing existing parameters with the same name.
|
* Sets parameter-value pair to URI query removing existing parameters with the same name.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setParameter(final String param, final String value) {
|
public URIBuilder setParameter(final String param, final String value) {
|
||||||
if (this.queryParams == null) {
|
if (this.queryParams == null) {
|
||||||
this.queryParams = new ArrayList<NameValuePair>();
|
this.queryParams = new ArrayList<NameValuePair>();
|
||||||
}
|
}
|
||||||
|
@ -212,7 +215,7 @@ public class UriBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets URI fragment.
|
* Sets URI fragment.
|
||||||
*/
|
*/
|
||||||
public UriBuilder setFragment(final String fragment) {
|
public URIBuilder setFragment(final String fragment) {
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testHierarchicalUri() throws Exception {
|
public void testHierarchicalUri() throws Exception {
|
||||||
URI uri = new URI("http", "stuff", "localhost", 80, "/some stuff", "param=stuff", "fragment");
|
URI uri = new URI("http", "stuff", "localhost", 80, "/some stuff", "param=stuff", "fragment");
|
||||||
UriBuilder uribuilder = new UriBuilder(uri);
|
URIBuilder uribuilder = new URIBuilder(uri);
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(uri, result);
|
Assert.assertEquals(uri, result);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testOpaqueUri() throws Exception {
|
public void testOpaqueUri() throws Exception {
|
||||||
URI uri = new URI("stuff", "some-stuff", "fragment");
|
URI uri = new URI("stuff", "some-stuff", "fragment");
|
||||||
UriBuilder uribuilder = new UriBuilder(uri);
|
URIBuilder uribuilder = new URIBuilder(uri);
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(uri, result);
|
Assert.assertEquals(uri, result);
|
||||||
}
|
}
|
||||||
|
@ -52,19 +52,19 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testOpaqueUriMutation() throws Exception {
|
public void testOpaqueUriMutation() throws Exception {
|
||||||
URI uri = new URI("stuff", "some-stuff", "fragment");
|
URI uri = new URI("stuff", "some-stuff", "fragment");
|
||||||
UriBuilder uribuilder = new UriBuilder(uri).setQuery("param1¶m2=stuff").setFragment(null);
|
URIBuilder uribuilder = new URIBuilder(uri).setQuery("param1¶m2=stuff").setFragment(null);
|
||||||
Assert.assertEquals(new URI("stuff:?param1¶m2=stuff"), uribuilder.build());
|
Assert.assertEquals(new URI("stuff:?param1¶m2=stuff"), uribuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHierarchicalUriMutation() throws Exception {
|
public void testHierarchicalUriMutation() throws Exception {
|
||||||
UriBuilder uribuilder = new UriBuilder("/").setScheme("http").setHost("localhost").setPort(80).setPath("/stuff");
|
URIBuilder uribuilder = new URIBuilder("/").setScheme("http").setHost("localhost").setPort(80).setPath("/stuff");
|
||||||
Assert.assertEquals(new URI("http://localhost:80/stuff"), uribuilder.build());
|
Assert.assertEquals(new URI("http://localhost:80/stuff"), uribuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmpty() throws Exception {
|
public void testEmpty() throws Exception {
|
||||||
UriBuilder uribuilder = new UriBuilder();
|
URIBuilder uribuilder = new URIBuilder();
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(new URI(""), result);
|
Assert.assertEquals(new URI(""), result);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testSetUserInfo() throws Exception {
|
public void testSetUserInfo() throws Exception {
|
||||||
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
|
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
|
||||||
UriBuilder uribuilder = new UriBuilder(uri).setUserInfo("user", "password");
|
URIBuilder uribuilder = new URIBuilder(uri).setUserInfo("user", "password");
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(new URI("http://user:password@localhost:80/?param=stuff"), result);
|
Assert.assertEquals(new URI("http://user:password@localhost:80/?param=stuff"), result);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveParameters() throws Exception {
|
public void testRemoveParameters() throws Exception {
|
||||||
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
|
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
|
||||||
UriBuilder uribuilder = new UriBuilder(uri).removeQuery();
|
URIBuilder uribuilder = new URIBuilder(uri).removeQuery();
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(new URI("http://localhost:80/"), result);
|
Assert.assertEquals(new URI("http://localhost:80/"), result);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testSetParameter() throws Exception {
|
public void testSetParameter() throws Exception {
|
||||||
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null);
|
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null);
|
||||||
UriBuilder uribuilder = new UriBuilder(uri).setParameter("param", "some other stuff")
|
URIBuilder uribuilder = new URIBuilder(uri).setParameter("param", "some other stuff")
|
||||||
.setParameter("blah", "blah");
|
.setParameter("blah", "blah");
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(new URI("http://localhost:80/?param=some+other+stuff&blah=blah"), result);
|
Assert.assertEquals(new URI("http://localhost:80/?param=some+other+stuff&blah=blah"), result);
|
||||||
|
@ -97,7 +97,7 @@ public class TestURIBuilder {
|
||||||
@Test
|
@Test
|
||||||
public void testAddParameter() throws Exception {
|
public void testAddParameter() throws Exception {
|
||||||
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null);
|
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null);
|
||||||
UriBuilder uribuilder = new UriBuilder(uri).addParameter("param", "some other stuff")
|
URIBuilder uribuilder = new URIBuilder(uri).addParameter("param", "some other stuff")
|
||||||
.addParameter("blah", "blah");
|
.addParameter("blah", "blah");
|
||||||
URI result = uribuilder.build();
|
URI result = uribuilder.build();
|
||||||
Assert.assertEquals(new URI("http://localhost:80/?param=stuff&blah&blah&" +
|
Assert.assertEquals(new URI("http://localhost:80/?param=stuff&blah&blah&" +
|
||||||
|
|
Loading…
Reference in New Issue