FAQ

[Velocity-commits] svn commit: r1151728 - in /velocity/tools/branches/2.0.x: src/main/java/org/apache/velocity/tools/generic/LinkTool.java xdocs/changes.xml

Nbubna
Jul 28, 2011 at 4:12 am
Author: nbubna
Date: Thu Jul 28 04:12:16 2011
New Revision: 1151728

URL: http://svn.apache.org/viewvc?rev=1151728&view=rev
Log:
VELTOOLS-146 absolute(uri) and friends no longer encode query strings or fragments

Modified:
velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
velocity/tools/branches/2.0.x/xdocs/changes.xml

Modified: velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/LinkTool.java
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/LinkTool.java?rev=1151728&r1=1151727&r2=1151728&view=diff
==============================================================================
--- velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/LinkTool.java (original)
+++ velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/LinkTool.java Thu Jul 28 04:12:16 2011
@@ -365,7 +365,7 @@ public class LinkTool extends SafeConfig
}
catch (NumberFormatException nfe)
{
- debug("Could convert '%s' to int", nfe, obj);
+ debug("Could not convert '%s' to int", nfe, obj);
this.port = -2; // use this to mean error
}
}
@@ -831,7 +831,9 @@ public class LinkTool extends SafeConfig
* host, port, path, query, and fragment all to their null-equivalent
* values. Otherwise, this will
* convert the specified object into a {@link URI}, then those same
- * values from the URI object to this instance.
+ * values from the URI object to this instance, when not null or empty.
+ * In other words, when given a URI this will only set values present
+ * in the URI.
*/
protected boolean setFromURI(Object obj)
{
@@ -853,27 +855,51 @@ public class LinkTool extends SafeConfig
{
return false;
}
- setScheme(uri.getScheme());
+ if (uri.getScheme() != null)
+ {
+ setScheme(uri.getScheme());
+ }
if (uri.isOpaque())
{
this.opaque = true;
- // path is used as scheme-specific part
- setPath(uri.getSchemeSpecificPart());
+ if (uri.getSchemeSpecificPart() != null)
+ {
+ // path is used as scheme-specific part
+ setPath(uri.getSchemeSpecificPart());
+ }
}
else
{
- setUserInfo(uri.getUserInfo());
- setHost(uri.getHost());
- setPort(uri.getPort());
+ if (uri.getUserInfo() != null)
+ {
+ setUserInfo(uri.getUserInfo());
+ }
+ if (uri.getHost() != null)
+ {
+ setHost(uri.getHost());
+ }
+ if (uri.getPort() > -1)
+ {
+ setPort(uri.getPort());
+ }
String pth = uri.getPath();
- if (pth.equals("/") || pth.length() == 0)
+ if (pth != null)
{
- pth = null;
+ if (pth.equals("/") || pth.length() == 0)
+ {
+ pth = null;
+ }
+ setPath(pth);
}
- setPath(pth);
+ }
+ if (uri.getQuery() != null)
+ {
setQuery(uri.getQuery());
}
- setFragment(uri.getFragment());
+ if (uri.getFragment() != null)
+ {
+ setFragment(uri.getFragment());
+ }
return true;
}

@@ -894,7 +920,7 @@ public class LinkTool extends SafeConfig
}
catch (Exception e)
{
- debug("Could convert '%s' to URI", e, obj);
+ debug("Could not convert '%s' to URI", e, obj);
return null;
}
}
@@ -1272,8 +1298,11 @@ public class LinkTool extends SafeConfig
{
pth = combinePath(getContextPath(), String.valueOf(obj));
}
- copy.setPath(pth);
- return copy;
+ if (copy.setFromURI(pth))
+ {
+ return copy;
+ }
+ return null;
}

/**
@@ -1340,52 +1369,25 @@ public class LinkTool extends SafeConfig
{
// assume it's just a path value to go with current scheme/host/port
LinkTool copy = absolute();
- String pth;
if (obj == null)
{
// just use the current directory path, if any
- pth = getDirectory();
+ copy.setPath(getDirectory());
}
else
{
- pth = String.valueOf(obj);
- if (pth.startsWith(DEFAULT_SCHEME))
+ String pth = String.valueOf(obj);
+ // paths that don't start with '/'
+ // are considered relative to the current directory
+ if (!pth.startsWith(DEFAULT_SCHEME) && !pth.startsWith("/"))
{
- // looks absolute already
- URI uri = toURI(pth);
- if (uri == null)
- {
- return null;
- }
- copy.setScheme(uri.getScheme());
- copy.setUserInfo(uri.getUserInfo());
- copy.setHost(uri.getHost());
- copy.setPort(uri.getPort());
- // handle path, query and fragment with care
- pth = uri.getPath();
- if (pth.equals("/") || pth.length() == 0)
- {
- pth = null;
- }
- copy.setPath(pth);
- if (uri.getQuery() != null)
- {
- copy.setQuery(uri.getQuery());
- }
- if (uri.getFragment() != null)
- {
- copy.setFragment(uri.getFragment());
- }
- return copy;
+ pth = combinePath(getDirectory(), pth);
}
- else if (!pth.startsWith("/"))
+ if (!copy.setFromURI(pth))
{
- // paths that don't start with '/'
- // are considered relative to the current directory
- pth = combinePath(getDirectory(), pth);
+ return null;
}
}
- copy.setPath(pth);
return copy;
}


Modified: velocity/tools/branches/2.0.x/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/velocity/tools/branches/2.0.x/xdocs/changes.xml?rev=1151728&r1=1151727&r2=1151728&view=diff
==============================================================================
--- velocity/tools/branches/2.0.x/xdocs/changes.xml (original)
+++ velocity/tools/branches/2.0.x/xdocs/changes.xml Thu Jul 28 04:12:16 2011
@@ -41,6 +41,7 @@
<li>fixed VELTOOLS-148 - fixed a LinkTool bug with parametersToIgnore management (schultz)</li>
<li>fixed VELTOOLS-149 - changed LinkTool.addRequestParams to accept Object[] (schultz)</li>
<li>Added StrutsLinkTool.action and StrutsLinkTool.forward methods as replacements for StrutsLinkTool.setAction ant StrutsLinkTool.setForward to match other new LinkTool methods like LinkTool.relative and LinkTool.absolute (schultz)
+ <li>fixed VELTOOLS-146 $link.absolute($uri) should not encode query strings in the argument</li>
</ul>
</subsection>
reply

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post

1 user in discussion


Notice: Undefined index: l in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 100

Notice: Undefined index: l in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 94

Notice: Undefined index: l in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 100

Notice: Undefined index: l in /home/whirl/sites/grokbase/root/www/data/inc/incl.us_privatize.php on line 94
Nbubna: 1 post