org.apache.turbine.util
Class DynamicURI

java.lang.Object
  |
  +--org.apache.turbine.util.DynamicURI
Direct Known Subclasses:
ContentURI, JspLink, RelativeDynamicURI, TemplateLink

public class DynamicURI
extends java.lang.Object

This creates a Dynamic URI for use within the Turbine system

If you use this class to generate all of your href tags as well as all of your URI's, then you will not need to worry about having session data setup for you or using HttpServletRequest.encodeUrl() since this class does everything for you.

 DynamicURI dui = new DynamicURI (data, "UserScreen" );
 dui.setName("Click Here").addPathInfo("user","jon");
 dui.getA();
 
The above call to getA() would return the String: <A HREF="http://www.server.com:80/servlets/Turbine/screen=UserScreen&amp;user=jon">Click Here</A>

Version:
$Id$
Author:
Jon S. Stevens, Jason van Zyl

Field Summary
protected  RunData data
          The RunData object.
protected  boolean hasPathInfo
          Fast shortcut to determine if there is any data in the path info.
protected  boolean hasQueryData
          Fast shortcut to determine if there is any data in the query data.
static java.lang.String HTTP
          HTTP protocol.
static java.lang.String HTTPS
          HTTPS protocol.
protected static int PATH_INFO
          P = 0 for path info.
protected  java.util.Vector pathInfo
          A Vector that contains all the path info if any.
protected static int QUERY_DATA
          Q = 1 for query data.
protected  java.util.Vector queryData
          A Vectory that contains all the query data if any.
protected  boolean redirect
          Whether we want to redirect or not.
 javax.servlet.http.HttpServletResponse res
          Servlet response interface.
protected  java.lang.String scriptName
          /foo/Turbine.
protected  ServerData sd
          The ServerData object.
protected  java.lang.String serverName
          ie: www.foo.com.
protected  int serverPort
          ie: 80 or 443.
protected  java.lang.String serverScheme
          ie: http or https.
 
Constructor Summary
DynamicURI()
          Default constructor - one of the init methods must be called before use.
DynamicURI(RunData data)
          Constructor sets up some variables.
DynamicURI(RunData data, boolean redirect)
          Constructor sets up some variables.
DynamicURI(RunData data, java.lang.String screen)
          Constructor sets up some variables.
DynamicURI(RunData data, java.lang.String screen, boolean redirect)
          Constructor sets up some variables.
DynamicURI(RunData data, java.lang.String screen, java.lang.String action)
          Constructor sets up some variables.
DynamicURI(RunData data, java.lang.String screen, java.lang.String action, boolean redirect)
          Constructor sets up some variables.
DynamicURI(ServerData sd)
          Main constructor for DynamicURI.
DynamicURI(ServerData sd, boolean redirect)
          Main constructor for DynamicURI.
DynamicURI(ServerData sd, java.lang.String screen)
          Main constructor for DynamicURI.
DynamicURI(ServerData sd, java.lang.String screen, boolean redirect)
          Main constructor for DynamicURI.
DynamicURI(ServerData sd, java.lang.String screen, java.lang.String action)
          Main constructor for DynamicURI.
DynamicURI(ServerData sd, java.lang.String screen, java.lang.String action, boolean redirect)
          Main constructor for DynamicURI.
 
Method Summary
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 P (0), then add name/value to the pathInfo hashtable.
 DynamicURI addPathInfo(ParameterParser pp)
          Adds a name=value pair for every entry in a ParameterParser object to the path_info string.
 DynamicURI addPathInfo(java.lang.String name, double value)
          Adds a name=value pair to the path_info string.
 DynamicURI addPathInfo(java.lang.String name, int value)
          Adds a name=value pair to the path_info string.
 DynamicURI addPathInfo(java.lang.String name, long value)
          Adds a name=value pair to the path_info string.
 DynamicURI addPathInfo(java.lang.String name, java.lang.Object value)
          Adds a name=value pair to the path_info string.
 DynamicURI addPathInfo(java.lang.String name, java.lang.String value)
          Adds a name=value pair to the path_info string.
 DynamicURI addQueryData(ParameterParser pp)
          Adds a name=value pair for every entry in a ParameterParser object to the query string.
 DynamicURI addQueryData(java.lang.String name, double value)
          Adds a name=value pair to the query string.
 DynamicURI addQueryData(java.lang.String name, int value)
          Adds a name=value pair to the query string.
 DynamicURI addQueryData(java.lang.String name, long value)
          Adds a name=value pair to the query string.
 DynamicURI addQueryData(java.lang.String name, java.lang.Object value)
          Adds a name=value pair to the query string.
 DynamicURI addQueryData(java.lang.String name, java.lang.String value)
          Adds a name=value pair to the query string.
 java.lang.String getA(java.lang.String name)
          Create an anchor object.
 java.lang.String getScriptName()
          Gets the script name (/servlets/Turbine).
 ServerData getServerData()
          Returns the ServerData used to initialize this DynamicURI.
 java.lang.String getServerName()
          Gets the server name.
 int getServerPort()
          Gets the server port.
 java.lang.String getServerScheme()
          Gets the server scheme (HTTP or HTTPS).
protected  void init()
          Initializes some common variables.
 void init(RunData data)
          Initialize with a RunData object
 void init(ServerData sd)
          Initialize with a ServerData object.
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.
protected  java.lang.String renderPathInfo(java.util.Vector data)
          This method takes a Vector of key/value arrays and converts it into a URL encoded querystring format.
protected  java.lang.String renderQueryString(java.util.Vector data)
          This method takes a Vector of key/value arrays and converts it into a URL encoded querystring format.
 DynamicURI setAction(java.lang.String action)
          Sets the action= value for this URL.
 DynamicURI setScreen(java.lang.String screen)
          Sets the screen= value for this URL.
 DynamicURI setScriptName(java.lang.String name)
          Sets the script name (/servlets/Turbine).
 DynamicURI setSecure()
          Method to specify that a URI should use SSL.
 DynamicURI setSecure(int port)
          Method to specify that a URI should use SSL.
 void setServerData(ServerData sd)
          Sets the ServerData used to initialize this DynamicURI.
 DynamicURI setServerName(java.lang.String name)
          Sets the server name.
 DynamicURI setServerPort(int port)
          Sets the server port.
 DynamicURI setServerScheme(java.lang.String scheme)
          Sets the scheme (HTTP or HTTPS).
 java.lang.String toString()
          Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl().
static java.lang.String toString(RunData data)
          Given a RunData object, get a URI for the request.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

HTTP

public static final java.lang.String HTTP
HTTP protocol.

HTTPS

public static final java.lang.String HTTPS
HTTPS protocol.

sd

protected ServerData sd
The ServerData object.

data

protected RunData data
The RunData object.

serverScheme

protected java.lang.String serverScheme
ie: http or https.

serverName

protected java.lang.String serverName
ie: www.foo.com.

serverPort

protected int serverPort
ie: 80 or 443.

scriptName

protected java.lang.String scriptName
/foo/Turbine.

res

public javax.servlet.http.HttpServletResponse res
Servlet response interface.

pathInfo

protected java.util.Vector pathInfo
A Vector that contains all the path info if any.

queryData

protected java.util.Vector queryData
A Vectory that contains all the query data if any.

hasPathInfo

protected boolean hasPathInfo
Fast shortcut to determine if there is any data in the path info.

hasQueryData

protected boolean hasQueryData
Fast shortcut to determine if there is any data in the query data.

redirect

protected boolean redirect
Whether we want to redirect or not.

PATH_INFO

protected static final int PATH_INFO
P = 0 for path info.

QUERY_DATA

protected static final int QUERY_DATA
Q = 1 for query data.
Constructor Detail

DynamicURI

public DynamicURI(RunData data)
Constructor sets up some variables.
Parameters:
data - A Turbine RunData object.

DynamicURI

public DynamicURI()
Default constructor - one of the init methods must be called before use.

DynamicURI

public DynamicURI(RunData data,
                  java.lang.String screen)
Constructor sets up some variables.
Parameters:
data - A Turbine RunData object.
screen - A String with the name of a screen.

DynamicURI

public DynamicURI(RunData data,
                  java.lang.String screen,
                  java.lang.String action)
Constructor sets up some variables.
Parameters:
data - A Turbine RunData object.
screen - A String with the name of a screen.
action - A String with the name of an action.

DynamicURI

public DynamicURI(RunData data,
                  java.lang.String screen,
                  java.lang.String action,
                  boolean redirect)
Constructor sets up some variables.
Parameters:
data - A Turbine RunData object.
screen - A String with the name of a screen.
action - A String with the name of an action.
redirect - True if it should redirect.

DynamicURI

public DynamicURI(RunData data,
                  java.lang.String screen,
                  boolean redirect)
Constructor sets up some variables.
Parameters:
data - A Turbine RunData object.
screen - A String with the name of a screen.
redirect - True if it should redirect.

DynamicURI

public DynamicURI(RunData data,
                  boolean redirect)
Constructor sets up some variables.
Parameters:
data - A Turbine RunData object.
redirect - True if it should redirect.

DynamicURI

public DynamicURI(ServerData sd)
Main constructor for DynamicURI. Uses ServerData.
Parameters:
sd - A ServerData.

DynamicURI

public DynamicURI(ServerData sd,
                  java.lang.String screen)
Main constructor for DynamicURI. Uses ServerData.
Parameters:
sd - A ServerData.
screen - A String with the name of a screen.

DynamicURI

public DynamicURI(ServerData sd,
                  java.lang.String screen,
                  java.lang.String action)
Main constructor for DynamicURI. Uses ServerData.
Parameters:
sd - A ServerData.
screen - A String with the name of a screen.
action - A String with the name of an action.

DynamicURI

public DynamicURI(ServerData sd,
                  java.lang.String screen,
                  java.lang.String action,
                  boolean redirect)
Main constructor for DynamicURI. Uses ServerData.
Parameters:
sd - A ServerData.
screen - A String with the name of a screen.
action - A String with the name of an action.
redirect - True if it should redirect.

DynamicURI

public DynamicURI(ServerData sd,
                  java.lang.String screen,
                  boolean redirect)
Main constructor for DynamicURI. Uses ServerData.
Parameters:
sd - A ServerData.
screen - A String with the name of a screen.
redirect - True if it should redirect.

DynamicURI

public DynamicURI(ServerData sd,
                  boolean redirect)
Main constructor for DynamicURI. Uses ServerData.
Parameters:
sd - A ServerData.
redirect - True if it should redirect.
Method Detail

init

public void init(RunData data)
Initialize with a RunData object
Parameters:
RunData -  

init

public void init(ServerData sd)
Initialize with a ServerData object.
Parameters:
ServerData -  

add

protected void add(int type,
                   java.lang.String name,
                   java.lang.String value)

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 (P or Q) 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 (P or Q) of insertion.
pp - A ParameterParser.

addPathInfo

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

addPathInfo

public DynamicURI addPathInfo(ParameterParser pp)
Adds a name=value pair for every entry in a ParameterParser object to the path_info string.
Parameters:
pp - A ParameterParser.

addQueryData

public DynamicURI 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 DynamicURI 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 DynamicURI 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 DynamicURI 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 DynamicURI 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 DynamicURI addQueryData(ParameterParser pp)
Adds a name=value pair for every entry in a ParameterParser object to the query string.
Parameters:
pp - A ParameterParser.

getA

public java.lang.String getA(java.lang.String name)
Create an anchor object. This call to getA():
 DynamicURI dui = new DynamicURI (data, "UserScreen" );
 dui.setName("Click Here").addPathInfo("user","jon");
 dui.getA();
 
would return the String:

<A HREF="http://www.server.com:80/servlets/Turbine/screen=UserScreen&amp;user=jon">Click Here</A>

Parameters:
name - A String with the name for the anchor.
Returns:
The anchor as a <A HREF="">name</A>.

getScriptName

public java.lang.String getScriptName()
Gets the script name (/servlets/Turbine).
Returns:
A String with the script name.

getServerName

public java.lang.String getServerName()
Gets the server name.
Returns:
A String with the server name.

getServerPort

public int getServerPort()
Gets the server port.
Returns:
A String with the server port.

getServerScheme

public java.lang.String getServerScheme()
Gets the server scheme (HTTP or HTTPS).
Returns:
A String with the server scheme.

init

protected void init()
Initializes some common variables.

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.

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.

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.

renderPathInfo

protected java.lang.String renderPathInfo(java.util.Vector data)
This method takes a Vector of key/value arrays and converts it into a URL encoded querystring format.
Parameters:
data - A Vector of key/value arrays.
Returns:
A String with the URL encoded data.

renderQueryString

protected java.lang.String renderQueryString(java.util.Vector data)
This method takes a Vector of key/value arrays and converts it into a URL encoded querystring format.
Parameters:
data - A Vector of key/value arrays.
Returns:
A String with the URL encoded data.

setAction

public DynamicURI 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 DynamicURI (self).

setScreen

public DynamicURI 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:
action - A String with the screen value.
Returns:
A DynamicURI (self).

setScriptName

public DynamicURI setScriptName(java.lang.String name)
Sets the script name (/servlets/Turbine).
Parameters:
name - A String with the script name.
Returns:
A DynamicURI (self).

setServerName

public DynamicURI setServerName(java.lang.String name)
Sets the server name.
Parameters:
name - A String with the server name.
Returns:
A DynamicURI (self).

setServerPort

public DynamicURI setServerPort(int port)
Sets the server port.
Parameters:
port - An int with the port.
Returns:
A DynamicURI (self).

setSecure

public DynamicURI setSecure()
Method to specify that a URI should use SSL. Whether or not it does is determined from TurbineResources.properties. Port number is 443.
Returns:
A DynamicURI (self).

setSecure

public DynamicURI setSecure(int port)
Method to specify that a URI should use SSL. Whether or not it does is determined from TurbineResources.properties.
Parameters:
port - An int with the port number.
Returns:
A DynamicURI (self).

setServerScheme

public DynamicURI setServerScheme(java.lang.String scheme)
Sets the scheme (HTTP or HTTPS).
Parameters:
scheme - A String with the scheme.
Returns:
A DynamicURI (self).

toString

public java.lang.String toString()
Builds the URL with all of the data URL-encoded as well as encoded using HttpServletResponse.encodeUrl().

 DynamicURI dui = new DynamicURI (data, "UserScreen" );
 dui.addPathInfo("user","jon");
 dui.toString();
 
The above call to toString() would return the String:

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

Overrides:
toString in class java.lang.Object
Returns:
A String with the built URL.

toString

public static java.lang.String toString(RunData data)
Given a RunData object, get a URI for the request. This is necessary sometimes when you want the exact URL and don't want DynamicURI to be too smart and remove actions, screens, etc. This also returns the Query Data where DynamicURI normally would not.
Parameters:
data - A Turbine RunData object.
Returns:
A String with the URL representing the RunData.

getServerData

public ServerData getServerData()
Returns the ServerData used to initialize this DynamicURI.
Returns:
A ServerData used to initialize this DynamicURI.

setServerData

public void setServerData(ServerData sd)
Sets the ServerData used to initialize this DynamicURI.
Parameters:
sd - A ServerData used to initialize this DynamicURI.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.