Updated Branches: refs/heads/master 8f52e1229 -> 222291cad
TAP5-1990: Link interface should be more fluid to allow setting of anchor, etc., more concisely Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/222291ca Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/222291ca Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/222291ca Branch: refs/heads/master Commit: 222291cad5f6849febb2b24a41a49fc673872724 Parents: 8f52e12 Author: Howard M. Lewis Ship <[email protected]> Authored: Thu Jul 25 13:36:49 2013 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Thu Jul 25 13:36:49 2013 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/tapestry5/Link.java | 29 ++++++++++++++------ .../tapestry5/internal/services/LinkImpl.java | 17 ++++++++++-- 2 files changed, 34 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/222291ca/tapestry-core/src/main/java/org/apache/tapestry5/Link.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/Link.java b/tapestry-core/src/main/java/org/apache/tapestry5/Link.java index f61475c..212cb90 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/Link.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/Link.java @@ -44,10 +44,10 @@ public interface Link /** * Returns the value of a specifically named query parameter, or <tt>null</tt> if no such query parameter is stored * in the link. - * + * <p/> * <p>Use this method only when you are sure the parameter has only one value. If the parameter might have more than * one value, use {@link #getParameterValues}. - * + * <p/> * <p>If you use this method with a multivalued parameter, the value returned is equal to the first value in the * array returned by <code>getParameterValues</code>. * @@ -59,10 +59,14 @@ public interface Link * Adds a parameter value. The value will be added, as is, to the URL. In many cases, the value should be URL * encoded via {@link URLCodec}. * - * @param parameterName the name of the parameter to store - * @param value the value to store, a null or blank value is allowed (as of Tapestry 5.3) + * @param parameterName + * the name of the parameter to store + * @param value + * the value to store, a null or blank value is allowed (as of Tapestry 5.3) + * @return this Link, to support method chaining */ - void addParameter(String parameterName, String value); + @IncompatibleChange(release = "5.4", details = "changed from void to Link") + Link addParameter(String parameterName, String value); /** * Adds a parameter value as a value object; the value object is converted to a string via @@ -77,9 +81,11 @@ public interface Link * Removes a parameter value, which is occasionally useful when transforming a parameter into a portion of * the path. * + * @return this Link, to support method chaining * @since 5.2.0 */ - void removeParameter(String parameterName); + @IncompatibleChange(release = "5.4", details = "changed from void to Link") + Link removeParameter(String parameterName); /** * Returns the completely unadorned base path. Other methods (such as {@link #toURI()}), may append @@ -93,6 +99,7 @@ public interface Link * Creates a copy of this link that has the same parameters, anchor, and other attributes, but a different * {@linkplain #getBasePath() base path}. * + * @return a new Link instance * @since 5.2.0 */ Link copyWithBasePath(String basePath); @@ -120,9 +127,12 @@ public interface Link /** * Sets the link anchor. Null and empty anchors will be ignored when building the link URI. * - * @param anchor the link anchor + * @param anchor + * the link anchor + * @return this Link, to support method chaining */ - void setAnchor(String anchor); + @IncompatibleChange(release = "5.4", details = "changed from void to Link") + Link setAnchor(String anchor); /** * Returns the absolute URL, which includes the scheme, hostname and possibly port (as per @@ -149,7 +159,8 @@ public interface Link * Changes the link's security, which can be useful to force a link to be either secure or insecure * when normally it might not be. * - * @param newSecurity new security value, not null, typically {@link LinkSecurity#FORCE_SECURE} or {@link LinkSecurity#FORCE_INSECURE} + * @param newSecurity + * new security value, not null, typically {@link LinkSecurity#FORCE_SECURE} or {@link LinkSecurity#FORCE_INSECURE} * @since 5.3 */ @IncompatibleChange(release = "5.4", details = "LinkSecurity class moved from internal package to org.apache.tapestry5.") http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/222291ca/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LinkImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LinkImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LinkImpl.java index 5333d75..ee192e4 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LinkImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/LinkImpl.java @@ -80,14 +80,18 @@ public class LinkImpl implements Link parameters.put(parameterName, Arrays.asList(value)); } - public void addParameter(String parameterName, String value) + public Link addParameter(String parameterName, String value) { assert InternalUtils.isNonBlank(parameterName); if (parameters == null) + { parameters = new TreeMap<String, List<String>>(); + } InternalUtils.addToMapList(parameters, parameterName, value == null ? "" : value); + + return this; } public String getBasePath() @@ -95,11 +99,16 @@ public class LinkImpl implements Link return basePath; } - public void removeParameter(String parameterName) + public Link removeParameter(String parameterName) { assert InternalUtils.isNonBlank(parameterName); + if (parameters != null) + { parameters.remove(parameterName); + } + + return this; } public String getAnchor() @@ -118,9 +127,11 @@ public class LinkImpl implements Link return values != null && !values.isEmpty() ? values.get(0) : null; } - public void setAnchor(String anchor) + public Link setAnchor(String anchor) { this.anchor = anchor; + + return this; } public String toAbsoluteURI()
