org.apache.turbine.services.pull.tools
Class TemplateLink

java.lang.Object
  extended byorg.apache.turbine.services.pull.tools.TemplateLink
All Implemented Interfaces:
ApplicationTool

public class TemplateLink
extends java.lang.Object
implements ApplicationTool

This is a pull to to be used in Templates to convert links in Templates into the correct references. The pull service might insert this tool into the Context. in templates. Here's an example of its Velocity use:

$link.setPage("index.vm").addPathInfo("hello","world") This would return: http://foo.com/Turbine/template/index.vm/hello/world

This is an application pull tool for the template system. You should not use it in a normal application!

Version:
$Id: TemplateLink.java 544066 2007-06-04 06:21:13Z hoffmann $
Author:
Dave Bryson, Jon S. Stevens, Henning P. Schmiedehausen, Quinton McCombs

Field Summary
static java.lang.String TEMPLATE_LINK_PREFIX
          Prefix for Parameters for this tool
static boolean TEMPLATE_LINK_RELATIVE_DEFAULT
          Default Value for TEMPLATE_LINK_RELATIVE_KEY
static java.lang.String TEMPLATE_LINK_RELATIVE_KEY
          Should this tool return relative URIs or absolute?
protected  TemplateURI templateURI
          TemplateURI used as backend for this object
 
Constructor Summary
TemplateLink()
          Default constructor The init method must be called before use.
 
Method Summary
 TemplateLink addPathInfo(ParameterParser pp)
          Adds a name=value pair for every entry in a ParameterParser object to the path_info string.
 TemplateLink addPathInfo(java.lang.String name, double value)
          Adds a name=value pair to the path_info string.
 TemplateLink addPathInfo(java.lang.String name, int value)
          Adds a name=value pair to the path_info string.
 TemplateLink addPathInfo(java.lang.String name, long value)
          Adds a name=value pair to the path_info string.
 TemplateLink addPathInfo(java.lang.String name, java.lang.Object value)
          Adds a name=value pair to the path_info string.
 TemplateLink addPathInfo(java.lang.String name, java.lang.String value)
          Adds a name=value pair to the path_info string.
 TemplateLink addQueryData(ParameterParser pp)
          Adds a name=value pair for every entry in a ParameterParser object to the query string.
 TemplateLink addQueryData(java.lang.String name, double value)
          Adds a name=value pair to the query string.
 TemplateLink addQueryData(java.lang.String name, int value)
          Adds a name=value pair to the query string.
 TemplateLink addQueryData(java.lang.String name, long value)
          Adds a name=value pair to the query string.
 TemplateLink addQueryData(java.lang.String name, java.lang.Object value)
          Adds a name=value pair to the query string.
 TemplateLink addQueryData(java.lang.String name, java.lang.String value)
          Adds a name=value pair to the query string.
 java.lang.String getAbsoluteLink()
          Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl().
 java.lang.String getAbsoluteURI()
          Returns the absolute URI leaving the source intact.
 java.lang.String getLink()
          Returns the URI.
 java.lang.String getPage()
          Gets the template variable used by the Template Service.
 java.lang.String getReference()
          Returns the current reference anchor.
 java.lang.String getRelativeLink()
          Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl().
 java.lang.String getRelativeURI()
          Returns the relative URI leaving the source intact.
 java.lang.String getURI()
          Returns the relative URI leaving the source intact.
 void init(java.lang.Object data)
          This will initialise a TemplateLink object that was constructed with the default constructor (ApplicationTool method).
 void refresh()
          Refresh method - does nothing
 TemplateLink removePathInfo()
          Removes all the path info elements.
 TemplateLink removePathInfo(java.lang.String name)
          Removes a name=value pair from the path info.
 TemplateLink removeQueryData()
          Removes all the query string elements.
 TemplateLink removeQueryData(java.lang.String name)
          Removes a name=value pair from the query string.
 TemplateLink setAction(java.lang.String action)
          Sets the action= value for this URL.
 TemplateLink setActionEvent(java.lang.String action, java.lang.String event)
          Sets the action= and eventSubmit= values for this URL.
 TemplateLink setEncodeURLOff()
          This will turn off the execution of res.encodeURL() by making res == null.
 TemplateLink setEvent(java.lang.String action)
          Sets the eventSubmit_= value for this URL.
 TemplateLink setPage(java.lang.String template)
          Sets the template variable used by the Template Service.
 TemplateLink setReference(java.lang.String reference)
          Sets a reference anchor (#ref).
 TemplateLink setScreen(java.lang.String screen)
          Sets the screen= value for this URL.
 java.lang.String toString()
          Same as getLink().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEMPLATE_LINK_PREFIX

public static final java.lang.String TEMPLATE_LINK_PREFIX
Prefix for Parameters for this tool

See Also:
Constant Field Values

TEMPLATE_LINK_RELATIVE_KEY

public static final java.lang.String TEMPLATE_LINK_RELATIVE_KEY
Should this tool return relative URIs or absolute? Default: Absolute.

See Also:
Constant Field Values

TEMPLATE_LINK_RELATIVE_DEFAULT

public static final boolean TEMPLATE_LINK_RELATIVE_DEFAULT
Default Value for TEMPLATE_LINK_RELATIVE_KEY

See Also:
Constant Field Values

templateURI

protected TemplateURI templateURI
TemplateURI used as backend for this object

Constructor Detail

TemplateLink

public TemplateLink()
Default constructor

The init method must be called before use.

Method Detail

init

public void init(java.lang.Object data)
This will initialise a TemplateLink object that was constructed with the default constructor (ApplicationTool method).

Specified by:
init in interface ApplicationTool
Parameters:
data - assumed to be a RunData object

refresh

public void refresh()
Refresh method - does nothing

Specified by:
refresh in interface ApplicationTool

setEncodeURLOff

public TemplateLink setEncodeURLOff()
This will turn off the execution of res.encodeURL() by making res == null. This is a hack for cases where you don't want to see the session information

Returns:
A TemplateLink (self).

setPage

public TemplateLink setPage(java.lang.String template)
Sets the template variable used by the Template Service.

Parameters:
template - A String with the template name.
Returns:
A TemplateLink.

getPage

public java.lang.String getPage()
Gets the template variable used by the Template Service. It is only available after setPage() has been called.

Returns:
The template name.

setAction

public TemplateLink setAction(java.lang.String action)
Sets the action= value for this URL. By default it adds the information to the path_info instead of the query data.

Parameters:
action - A String with the action value.
Returns:
A TemplateLink (self).

setActionEvent

public TemplateLink setActionEvent(java.lang.String action,
                                   java.lang.String event)
Sets the action= and eventSubmit= values for this URL. By default it adds the information to the path_info instead of the query data.

Parameters:
action - A String with the action value.
event - A string with the event name.
Returns:
A TemplateLink (self).

setEvent

public TemplateLink setEvent(java.lang.String action)
Sets the eventSubmit_= value for this URL. By default it adds the information to the path_info instead of the query data.

Parameters:
action - A String with the event value.
Returns:
A TemplateLink (self).

setScreen

public TemplateLink setScreen(java.lang.String screen)
Sets the screen= value for this URL. By default it adds the information to the path_info instead of the query data.

Parameters:
screen - A String with the screen value.
Returns:
A TemplateLink (self).

setReference

public TemplateLink setReference(java.lang.String reference)
Sets a reference anchor (#ref).

Parameters:
reference - A String containing the reference.
Returns:
A TemplateLink (self).

getReference

public java.lang.String getReference()
Returns the current reference anchor.

Returns:
A String containing the reference.

addPathInfo

public TemplateLink addPathInfo(ParameterParser pp)
Adds a name=value pair for every entry in a ParameterParser object to the path_info string.

Parameters:
pp - A ParameterParser.
Returns:
A TemplateLink (self).

addPathInfo

public TemplateLink addPathInfo(java.lang.String name,
                                java.lang.Object value)
Adds a name=value pair to the path_info string.

Parameters:
name - A String with the name to add.
value - An Object with the value to add.
Returns:
A TemplateLink (self).

addPathInfo

public TemplateLink addPathInfo(java.lang.String name,
                                java.lang.String value)
Adds a name=value pair to the path_info string.

Parameters:
name - A String with the name to add.
value - A String with the value to add.
Returns:
A TemplateLink (self).

addPathInfo

public TemplateLink addPathInfo(java.lang.String name,
                                double value)
Adds a name=value pair to the path_info string.

Parameters:
name - A String with the name to add.
value - A double with the value to add.
Returns:
A TemplateLink (self).

addPathInfo

public TemplateLink addPathInfo(java.lang.String name,
                                int value)
Adds a name=value pair to the path_info string.

Parameters:
name - A String with the name to add.
value - An int with the value to add.
Returns:
A TemplateLink (self).

addPathInfo

public TemplateLink addPathInfo(java.lang.String name,
                                long value)
Adds a name=value pair to the path_info string.

Parameters:
name - A String with the name to add.
value - A long with the value to add.
Returns:
A TemplateLink (self).

addQueryData

public TemplateLink addQueryData(java.lang.String name,
                                 java.lang.Object value)
Adds a name=value pair to the query string.

Parameters:
name - A String with the name to add.
value - An Object with the value to add.
Returns:
A TemplateLink (self).

addQueryData

public TemplateLink addQueryData(java.lang.String name,
                                 java.lang.String value)
Adds a name=value pair to the query string.

Parameters:
name - A String with the name to add.
value - A String with the value to add.
Returns:
A TemplateLink (self).

addQueryData

public TemplateLink addQueryData(java.lang.String name,
                                 double value)
Adds a name=value pair to the query string.

Parameters:
name - A String with the name to add.
value - A double with the value to add.
Returns:
A TemplateLink (self).

addQueryData

public TemplateLink addQueryData(java.lang.String name,
                                 int value)
Adds a name=value pair to the query string.

Parameters:
name - A String with the name to add.
value - An int with the value to add.
Returns:
A TemplateLink (self).

addQueryData

public TemplateLink addQueryData(java.lang.String name,
                                 long value)
Adds a name=value pair to the query string.

Parameters:
name - A String with the name to add.
value - A long with the value to add.
Returns:
A TemplateLink (self).

addQueryData

public TemplateLink addQueryData(ParameterParser pp)
Adds a name=value pair for every entry in a ParameterParser object to the query string.

Parameters:
pp - A ParameterParser.
Returns:
A TemplateLink (self).

removePathInfo

public TemplateLink removePathInfo()
Removes all the path info elements.

Returns:
A TemplateLink (self).

removePathInfo

public TemplateLink removePathInfo(java.lang.String name)
Removes a name=value pair from the path info.

Parameters:
name - A String with the name to be removed.
Returns:
A TemplateLink (self).

removeQueryData

public TemplateLink removeQueryData()
Removes all the query string elements.

Returns:
A TemplateLink (self).

removeQueryData

public TemplateLink removeQueryData(java.lang.String name)
Removes a name=value pair from the query string.

Parameters:
name - A String with the name to be removed.
Returns:
A TemplateLink (self).

getAbsoluteLink

public java.lang.String getAbsoluteLink()
Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl(). The resulting URL is absolute; it starts with http/https...

 TemplateURI tui = new TemplateURI (data, "UserScreen");
 tui.addPathInfo("user","jon");
 tui.getAbsoluteLink();
 
The above call to absoluteLink() would return the String:

http://www.server.com/servlets/Turbine/screen/UserScreen/user/jon

After rendering the URI, it clears the pathInfo and QueryString portions of the TemplateURI. So you can use the $link reference multiple times on a page and start over with a fresh object every time.

Returns:
A String with the built URL.

getRelativeLink

public java.lang.String getRelativeLink()
Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl(). The resulting URL is relative to the webserver root.

 TemplateURI tui = new TemplateURI (data, "UserScreen");
 tui.addPathInfo("user","jon");
 tui.getRelativeLink();
 
The above call to absoluteLink() would return the String:

/servlets/Turbine/screen/UserScreen/user/jon

After rendering the URI, it clears the pathInfo and QueryString portions of the TemplateURI. So you can use the $link reference multiple times on a page and start over with a fresh object every time.

Returns:
A String with the built URL.

getLink

public java.lang.String getLink()
Returns the URI. After rendering the URI, it clears the pathInfo and QueryString portions of the TemplateURI.

Returns:
A String with the URI in the form http://foo.com/Turbine/template/index.wm/hello/world

getURI

public java.lang.String getURI()
Returns the relative URI leaving the source intact. Use this if you need the path_info and query data multiple times. This is equivalent to $link.Link or just $link, but does not reset the path_info and query data.

Returns:
A String with the URI in the form http://foo.com/Turbine/template/index.wm/hello/world

getAbsoluteURI

public java.lang.String getAbsoluteURI()
Returns the absolute URI leaving the source intact. Use this if you need the path_info and query data multiple times. This is equivalent to $link.AbsoluteLink but does not reset the path_info and query data.

Returns:
A String with the URI in the form http://foo.com/Turbine/template/index.wm/hello/world

getRelativeURI

public java.lang.String getRelativeURI()
Returns the relative URI leaving the source intact. Use this if you need the path_info and query data multiple times. This is equivalent to $link.RelativeLink but does not reset the path_info and query data.

Returns:
A String with the URI in the form http://foo.com/Turbine/template/index.wm/hello/world

toString

public java.lang.String toString()
Same as getLink().

Returns:
A String with the URI represented by this object.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.