You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2006/03/11 19:41:41 UTC
svn commit: r385124 -
/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/tools/LinkTool.java
Author: nbubna
Date: Sat Mar 11 10:41:39 2006
New Revision: 385124
URL: http://svn.apache.org/viewcvs?rev=385124&view=rev
Log:
remove ViewTool interface and add setAbsolute() methods
Modified:
jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/tools/LinkTool.java
Modified: jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/tools/LinkTool.java
URL: http://svn.apache.org/viewcvs/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/tools/LinkTool.java?rev=385124&r1=385123&r2=385124&view=diff
==============================================================================
--- jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/tools/LinkTool.java (original)
+++ jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/tools/LinkTool.java Sat Mar 11 10:41:39 2006
@@ -28,7 +28,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.tools.view.context.ViewContext;
-import org.apache.velocity.tools.view.tools.ViewTool;
/**
* View tool to make building URIs pleasant and fun!
@@ -53,7 +52,7 @@
* @since VelocityTools 1.0
* @version $Id$
*/
-public class LinkTool implements ViewTool, Cloneable
+public class LinkTool implements Cloneable
{
protected static final Log LOG = LogFactory.getLog(LinkTool.class);
@@ -234,8 +233,6 @@
}
- // --------------------------------------------- ViewTool Interface -------
-
/**
* Initializes this tool.
*
@@ -341,6 +338,58 @@
public LinkTool relative(String uri)
{
return setRelative(uri);
+ }
+
+
+ /**
+ * <p>Returns a copy of the link with the specified URI reference
+ * either used as or converted to an absolute (non-relative)
+ * URI reference. This method will overwrite any previous URI
+ * reference settings but will copy the query string.</p>
+ *
+ * Example:<br>
+ * <code><a href='$link.setAbsolute("/templates/login/index.vm")'>Login Page</a></code><br>
+ * produces something like<br/>
+ * <code><a href="http://myserver.net/myapp/templates/login/index.vm">Login Page</a></code><br>
+ * and<br>
+ * <code><a href='$link.setAbsolute("http://theirserver.com/index.jsp")'>Their, Inc.</a></code><br>
+ * produces something like<br/>
+ * <code><a href="http://theirserver.net/index.jsp">Their, Inc.</a></code><br>
+ *
+ * @param uri A context-relative URI reference or absolute URL.
+ * @return a new instance of LinkTool with the specified URI
+ * @since VelocityTools 1.3
+ */
+ public LinkTool setAbsolute(String uri)
+ {
+ // if they're creating a url for a separate site
+ if (uri.startsWith("http"))
+ {
+ // just set the URI
+ return setURI(uri);
+ }
+ else
+ {
+ // otherwise, prepend this webapp's context url
+ String fullCtx = getContextURL();
+ if (uri.startsWith("/"))
+ {
+ return copyWith(fullCtx + uri);
+ }
+ else
+ {
+ return copyWith(fullCtx + '/' + uri);
+ }
+ }
+ }
+
+ /**
+ * Convenience method equivalent to {@link #setAbsolute}.
+ * @since VelocityTools 1.3
+ */
+ public LinkTool absolute(String uri)
+ {
+ return setAbsolute(uri);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org