Skip to content

Commit

Permalink
Attempt to fix Issue #195 - not quite working
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jan 19, 2016
1 parent ee8b45f commit 68d1a01
Show file tree
Hide file tree
Showing 21 changed files with 537 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ public static AddressBuilderBase begin()
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
protected Address build()
{
if (address == null)
{
address = new ParameterizedAddressResult(this);
}
return address;
}

/**
* Generate an {@link Address} representing the current literal state of this {@link AddressBuilder}.
* <p>
* (Does not apply parameterization. E.g. The URL `/{foo}` will be treated as literal text, as opposed to calling
* {@link #build()}, which would result in `foo` being treated as a parameterized expression)
*/
protected Address buildLiteral()
{
if (address == null)
{
Expand All @@ -79,11 +94,39 @@ public static Address create(String url) throws IllegalArgumentException
URI u = new URI(url);
String scheme = u.getScheme();
String host = u.getHost();
if(scheme != null && host == null)
return AddressBuilder.begin().scheme(u.getScheme()).schemeSpecificPart(u.getRawSchemeSpecificPart()).build();
if (scheme != null && host == null)
return AddressBuilder.begin().scheme(u.getScheme()).schemeSpecificPart(u.getRawSchemeSpecificPart())
.build();
else
return AddressBuilder.begin().scheme(scheme).domain(host).port(u.getPort())
.pathEncoded(u.getRawPath()).queryLiteral(u.getRawQuery()).anchor(u.getRawFragment()).build();
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
"[" + url + "] is not a valid URL fragment. Consider encoding relevant portions of the URL with ["
+ Encoder.class + "]", e);
}
}

/**
* Create a new {@link Address} from the given fully encoded URL. Improperly formatted or encoded URLs are not
* parse-able and will result in an exception.<p>
*
* @see http://en.wikipedia.org/wiki/URI_scheme
* @throws IllegalArgumentException when the input URL or URL fragment is not valid.
*/
public static Address createLiteral(String url) throws IllegalArgumentException
{
try {
URI u = new URI(url);
String scheme = u.getScheme();
String host = u.getHost();
if (scheme != null && host == null)
return AddressBuilder.begin().scheme(u.getScheme()).schemeSpecificPart(u.getRawSchemeSpecificPart())
.buildLiteral();
else
return AddressBuilder.begin().scheme(scheme).domain(host).port(u.getPort())
.pathEncoded(u.getRawPath()).queryLiteral(u.getRawQuery()).anchor(u.getRawFragment()).build();
return AddressBuilder.begin().scheme(scheme).domain(host).port(u.getPort())
.pathEncoded(u.getRawPath()).queryLiteral(u.getRawQuery()).anchor(u.getRawFragment()).buildLiteral();
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -273,6 +316,6 @@ void setEncoded(CharSequence name, Object... values)
@Override
public String toString()
{
return build().toString();
return buildLiteral().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderAnchor
public class AddressBuilderAnchor implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderAnchor
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderBase
public class AddressBuilderBase implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -27,14 +27,18 @@ public class AddressBuilderBase
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

/**
* Set the scheme section of this {@link Address}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderDomain
public class AddressBuilderDomain implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderDomain
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

/**
* Set the port section of this {@link Address}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderPath
public class AddressBuilderPath implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderPath
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

/**
* Set a query-parameter to a value or multiple values. The given name and values will be encoded before they are
* stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderPort
public class AddressBuilderPort implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderPort
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

/**
* Set the non-encoded path section of this {@link Address}. The given value will be stored without additional
* encoding or decoding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderQuery
public class AddressBuilderQuery implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderQuery
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

/**
* Set a query-parameter to a value or multiple values. The given name and values will be encoded before they are
* stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class AddressBuilderScheme
public class AddressBuilderScheme implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderScheme
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

/**
* Set the domain section of this {@link Address}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author <a href="mailto:fabmars@gmail.com">Fabien Marsaud</a>
*/
public class AddressBuilderSchemeSpecificPart
public class AddressBuilderSchemeSpecificPart implements BuildableAddress
{
private AddressBuilder parent;

Expand All @@ -29,14 +29,18 @@ public class AddressBuilderSchemeSpecificPart
this.parent = parent;
}

/**
* Generate an {@link Address} representing the current state of this {@link AddressBuilder}.
*/
@Override
public Address build()
{
return parent.build();
}

@Override
public Address buildLiteral()
{
return parent.buildLiteral();
}

@Override
public String toString()
{
Expand Down
Loading

0 comments on commit 68d1a01

Please sign in to comment.