org.apache.turbine.util.uri
Class TurbineURI

java.lang.Object
  extended byorg.apache.turbine.util.uri.BaseURI
      extended byorg.apache.turbine.util.uri.TurbineURI
All Implemented Interfaces:
URI, URIConstants
Direct Known Subclasses:
TemplateURI

public class TurbineURI
extends BaseURI

This class allows you to keep all the information needed for a single link at one place. It keeps your query data, path info, the server scheme, name, port and the script path. If you must generate a Turbine Link, use this class.

Version:
$Id: TurbineURI.java 638205 2008-03-18 04:10:39Z seade $
Author:
Jon S. Stevens, Jason van Zyl, Henning P. Schmiedehausen

Field Summary
 
Fields inherited from interface org.apache.turbine.util.uri.URIConstants
CGI_ACTION_PARAM, CGI_SCREEN_PARAM, CGI_TEMPLATE_PARAM, EVENT_PREFIX, FTP_PORT, HTTP, HTTP_PORT, HTTPS, HTTPS_PORT, PATH_INFO, QUERY_DATA, URI_SCHEME_SEPARATOR
 
Constructor Summary
TurbineURI()
          Empty C'tor.
TurbineURI(RunData runData)
          Constructor with a RunData object.
TurbineURI(RunData runData, boolean redirect)
          Constructor, set explicit redirection.
TurbineURI(RunData runData, java.lang.String screen)
          Constructor, set Screen.
TurbineURI(RunData runData, java.lang.String screen, boolean redirect)
          Constructor, set Screen, set explicit redirection.
TurbineURI(RunData runData, java.lang.String screen, java.lang.String action)
          Constructor, set Screen and Action.
TurbineURI(RunData runData, java.lang.String screen, java.lang.String action, boolean redirect)
          Constructor, set Screen and Action, set explicit redirection.
TurbineURI(ServerData serverData)
          Constructor with a ServerData object.
TurbineURI(ServerData serverData, boolean redirect)
          Constructor, set explicit redirection.
TurbineURI(ServerData serverData, java.lang.String screen)
          Constructor, set Screen.
TurbineURI(ServerData serverData, java.lang.String screen, boolean redirect)
          Constructor, set Screen, set explicit redirection.
TurbineURI(ServerData serverData, java.lang.String screen, java.lang.String action)
          Constructor, set Screen and Action.
TurbineURI(ServerData serverData, java.lang.String screen, java.lang.String action, boolean redirect)
          Constructor, set Screen and Action, set explicit redirection.
TurbineURI(java.lang.String screen, java.lang.String action)
          Constructor, user Turbine.getDefaultServerData(), set Screen and Action.
 
Method Summary
protected  void add(int type, java.util.List list)
          Method for a quick way to add all the parameters in a List with URIParam objects.
protected  void add(int type, ParameterParser pp)
          Method for a quick way to add all the parameters in a ParameterParser.
protected  void add(int type, java.lang.String name, java.lang.String value)
          If the type is PATH_INFO, then add name/value to the pathInfo hashtable.
 void addPathInfo(java.util.List list)
          Adds an existing List of URIParam objects to the path_info string.
 void addPathInfo(ParameterParser pp)
          Adds a name=value pair for every entry in a ParameterParser object to the path_info string.
 void addPathInfo(java.lang.String name, double value)
          Adds a name=value pair to the path_info string.
 void addPathInfo(java.lang.String name, int value)
          Adds a name=value pair to the path_info string.
 void addPathInfo(java.lang.String name, long value)
          Adds a name=value pair to the path_info string.
 void addPathInfo(java.lang.String name, java.lang.Object value)
          Adds a name=value pair to the path_info string.
 void addPathInfo(java.lang.String name, java.lang.String value)
          Adds a name=value pair to the path_info string.
 void addQueryData(java.util.List list)
          Adds an existing List of URIParam objects to the query data.
 void addQueryData(ParameterParser pp)
          Adds a name=value pair for every entry in a ParameterParser object to the query string.
 void addQueryData(java.lang.String name, double value)
          Adds a name=value pair to the query string.
 void addQueryData(java.lang.String name, int value)
          Adds a name=value pair to the query string.
 void addQueryData(java.lang.String name, long value)
          Adds a name=value pair to the query string.
 void addQueryData(java.lang.String name, java.lang.Object value)
          Adds a name=value pair to the query string.
 void addQueryData(java.lang.String name, java.lang.String value)
          Adds a name=value pair to the query string.
 void clearAction()
          Clears the action= value for this URL.
 void clearResponse()
          Template Link and friends want to be able to turn the encoding of the servlet container off.
 void clearScreen()
          Clears the screen= value for this URL.
 java.lang.String getAbsoluteLink()
          Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl().
 java.util.List getPathInfo()
          Gets the current Query Data List.
 java.util.List getQueryData()
          Gets the current Query Data List.
 java.lang.String getRelativeLink()
          Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl().
 boolean hasPathInfo()
          Is Path Info data set in this URI?
 boolean hasQueryData()
          Is Query data set in this URI?
protected  void remove(int type, java.lang.String name)
          If the type is P (0), then remove name/value from the pathInfo hashtable.
 void removePathInfo()
          Removes all the path info elements.
 void removePathInfo(java.lang.String name)
          Removes a name=value pair from the path info.
 void removeQueryData()
          Removes all the query string elements.
 void removeQueryData(java.lang.String name)
          Removes a name=value pair from the query string.
 void setAction(java.lang.String action)
          Sets the action= value for this URL.
 void setActionEvent(java.lang.String action, java.lang.String event)
          Sets the action= and eventSubmit= values for this URL.
 void setEvent(java.lang.String event)
          Sets the fired eventSubmit= value for this URL.
 void setPathInfo(java.util.List pathInfo)
          Sets the Query Data List.
 void setQueryData(java.util.List queryData)
          Sets the Query Data List.
 void setScreen(java.lang.String screen)
          Sets the screen= value for this URL.
 java.lang.String toString()
          Simply calls getAbsoluteLink().
 
Methods inherited from class org.apache.turbine.util.uri.BaseURI
encodeResponse, getContextAndScript, getContextPath, getReference, getResponse, getSchemeAndPort, getScriptName, getServerName, getServerPort, getServerScheme, hasReference, isRedirect, setContextPath, setRedirect, setReference, setResponse, setScriptName, setSecure, setSecure, setServerName, setServerPort, setServerScheme
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TurbineURI

public TurbineURI()
Empty C'tor. Uses Turbine.getDefaultServerData().


TurbineURI

public TurbineURI(RunData runData)
Constructor with a RunData object.

Parameters:
runData - A RunData object

TurbineURI

public TurbineURI(RunData runData,
                  boolean redirect)
Constructor, set explicit redirection.

Parameters:
runData - A RunData object
redirect - True if redirection allowed.

TurbineURI

public TurbineURI(RunData runData,
                  java.lang.String screen)
Constructor, set Screen.

Parameters:
runData - A RunData object
screen - A Screen Name

TurbineURI

public TurbineURI(RunData runData,
                  java.lang.String screen,
                  boolean redirect)
Constructor, set Screen, set explicit redirection.

Parameters:
runData - A RunData object
screen - A Screen Name
redirect - True if redirection allowed.

TurbineURI

public TurbineURI(RunData runData,
                  java.lang.String screen,
                  java.lang.String action)
Constructor, set Screen and Action.

Parameters:
runData - A RunData object
screen - A Screen Name
action - An Action Name

TurbineURI

public TurbineURI(RunData runData,
                  java.lang.String screen,
                  java.lang.String action,
                  boolean redirect)
Constructor, set Screen and Action, set explicit redirection.

Parameters:
runData - A RunData object
screen - A Screen Name
action - An Action Name
redirect - True if redirection allowed.

TurbineURI

public TurbineURI(ServerData serverData)
Constructor with a ServerData object.

Parameters:
serverData - A ServerData object

TurbineURI

public TurbineURI(ServerData serverData,
                  boolean redirect)
Constructor, set explicit redirection.

Parameters:
serverData - A ServerData object
redirect - True if redirection allowed.

TurbineURI

public TurbineURI(ServerData serverData,
                  java.lang.String screen)
Constructor, set Screen.

Parameters:
serverData - A ServerData object
screen - A Screen Name

TurbineURI

public TurbineURI(ServerData serverData,
                  java.lang.String screen,
                  boolean redirect)
Constructor, set Screen, set explicit redirection.

Parameters:
serverData - A ServerData object
screen - A Screen Name
redirect - True if redirection allowed.

TurbineURI

public TurbineURI(ServerData serverData,
                  java.lang.String screen,
                  java.lang.String action)
Constructor, set Screen and Action.

Parameters:
serverData - A ServerData object
screen - A Screen Name
action - An Action Name

TurbineURI

public TurbineURI(ServerData serverData,
                  java.lang.String screen,
                  java.lang.String action,
                  boolean redirect)
Constructor, set Screen and Action, set explicit redirection.

Parameters:
serverData - A ServerData object
screen - A Screen Name
action - An Action Name
redirect - True if redirection allowed.

TurbineURI

public TurbineURI(java.lang.String screen,
                  java.lang.String action)
Constructor, user Turbine.getDefaultServerData(), set Screen and Action.

Parameters:
screen - A Screen Name
action - An Action Name
Method Detail

setAction

public void 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. An empty value (null or "") cleans out an existing value.

Parameters:
action - A String with the action value.

setEvent

public void setEvent(java.lang.String event)
Sets the fired eventSubmit= value for this URL.

Parameters:
event - The event to fire.

setActionEvent

public void 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. An empty value (null or "") for the action cleans out an existing value. An empty value (null or "") for the event has no effect.

Parameters:
action - A String with the action value.
event - A string with the event name.

clearAction

public void clearAction()
Clears the action= value for this URL.


setScreen

public void 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. An empty value (null or "") cleans out an existing value.

Parameters:
screen - A String with the screen value.

clearScreen

public void clearScreen()
Clears the screen= value for this URL.


addPathInfo

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

Parameters:
pp - A ParameterParser.

addPathInfo

public void addPathInfo(java.util.List list)
Adds an existing List of URIParam objects to the path_info string.

Parameters:
list - A list with URIParam objects.

addPathInfo

public void 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.

addPathInfo

public void 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.

addPathInfo

public void 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.

addPathInfo

public void 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.

addPathInfo

public void 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.

addQueryData

public void 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.

addQueryData

public void 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.

addQueryData

public void 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.

addQueryData

public void 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.

addQueryData

public void 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.

addQueryData

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

Parameters:
pp - A ParameterParser.

addQueryData

public void addQueryData(java.util.List list)
Adds an existing List of URIParam objects to the query data.

Parameters:
list - A list with URIParam objects.

hasPathInfo

public boolean hasPathInfo()
Is Path Info data set in this URI?

Returns:
true if Path Info has values

removePathInfo

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


removePathInfo

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

Parameters:
name - A String with the name to be removed.

hasQueryData

public boolean hasQueryData()
Is Query data set in this URI?

Returns:
true if Query data has values

removeQueryData

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


removeQueryData

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

Parameters:
name - A String with the name to be removed.

clearResponse

public void clearResponse()
Template Link and friends want to be able to turn the encoding of the servlet container off. After calling this method, the no encoding will happen any longer. If you think, that you need this outside a template context, think again.


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...

 TurbineURI tui = new TurbineURI (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

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.

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

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

Returns:
A String with the built URL.

getPathInfo

public java.util.List getPathInfo()
Gets the current Query Data List.

Returns:
A List which contains all query data keys. The keys are URIParam objects.

setPathInfo

public void setPathInfo(java.util.List pathInfo)
Sets the Query Data List. Replaces the current query data list with the one supplied. The list must contain only URIParam objects!

Parameters:
pathInfo - A List with new param objects.

getQueryData

public java.util.List getQueryData()
Gets the current Query Data List.

Returns:
A List which contains all query data keys. The keys are URIParam objects.

setQueryData

public void setQueryData(java.util.List queryData)
Sets the Query Data List. Replaces the current query data list with the one supplied. The list must contain only URIParam objects!

Parameters:
queryData - A List with new param objects.

toString

public java.lang.String toString()
Simply calls getAbsoluteLink(). You should not use this in your code unless you have to. Use getAbsoluteLink.

Returns:
This URI as a String

add

protected void add(int type,
                   java.lang.String name,
                   java.lang.String value)
If the type is PATH_INFO, then add name/value to the pathInfo hashtable.

If the type is QUERY_DATA, then add name/value to the queryData hashtable.

Parameters:
type - Type (PATH_INFO or QUERY_DATA) of insertion.
name - A String with the name to add.
value - A String with the value to add.

add

protected void add(int type,
                   ParameterParser pp)
Method for a quick way to add all the parameters in a ParameterParser.

If the type is P (0), then add name/value to the pathInfo hashtable.

If the type is Q (1), then add name/value to the queryData hashtable.

Parameters:
type - Type of insertion (@see #add(char type, String name, String value))
pp - A ParameterParser.

add

protected void add(int type,
                   java.util.List list)
Method for a quick way to add all the parameters in a List with URIParam objects.

If the type is P (0), then add name/value to the pathInfo hashtable.

If the type is Q (1), then add name/value to the queryData hashtable.

Parameters:
type - Type of insertion (@see #add(char type, String name, String value))
list - A List of URIParam objects

remove

protected void remove(int type,
                      java.lang.String name)
If the type is P (0), then remove name/value from the pathInfo hashtable.

If the type is Q (1), then remove name/value from the queryData hashtable.

Parameters:
type - Type (P or Q) of removal.
name - A String with the name to be removed.


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