org.apache.beehive.netui.pageflow.util
Class TemplateHelper

Object
  extended by TemplateHelper
All Implemented Interfaces:
Cloneable

public class TemplateHelper
extends Object
implements Cloneable

Class for creating URLs from parameterized templates. This mechanism recognizes the following parameters in URL templates:

If one or more parameters of a template are not set at runtime, the implementation will use defaults if appropriate.


url:scheme Scheme Usage
url:domain Domain May be set
url:port Port May be set
url:path Extra path information Reserved, must be present in a template.
url:queryString Reserved query parameters Reserved, must be present in a template.
Field Summary
static String CONTROL_STATE_PARAM
          Control state parameter (reserved).
protected  HttpServletRequest httpRequest
          HTTP request.
protected  HttpServletResponse httpResponse
          HTTP response<.
static String MODE_PARAM
          Window mode query parameter (reserved).
static String PAGE_LABEL_PARAM
          Page label query parameter (reserved).
protected  LinkedHashMap params
          Query parameters
static String POSTBACK_PARAM
          Postback request query parameter (reserved).
static String STATE_PARAM
          Window state query parameter (reserved).
static String WINDOW_LABEL_PARAM
          Window label query parameter (reserved).
 
Constructor Summary
TemplateHelper(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
          Constructs a GenericURL.
 
Method Summary
 void addParameter(String name, String value)
          Add a parameter.
 Object clone()
          Returns a deep copy.
 String getDomain()
          Returns the domain.
 boolean getEncodeSession()
          Returns true if URL rewriting is enabled.
 String getParameter(String name)
          Returns the value of the parameter.
 List getParameters(String name)
          Returns the values of the given parameter.
 String getPathPrefix()
          Returns the path prefix.
 int getPort()
          Returns the port.
 String getQueryString()
           
 String getScheme()
          Returns the protocol scheme.
 URLTemplate getTemplate()
          Returns the current template.
 String getTemplateName(String templateRef)
           
 boolean hasTemplateRef(String templateRef)
           
 void removeParameter(String name)
          Removes the given parameter.
 void setDomain(String domain)
          Sets the domain.
 void setEncodeSession(boolean encodeSession)
          Enables URL rewriting for encoding a session ID in the URL.
 void setPath(String path)
          Sets path.
 void setPathPrefix(String pathPrefix)
          Sets a path prefix.
 void setPort(int port)
          Sets a port.
 void setQueryString(String queryString)
           
 void setScheme(String scheme)
          Sets the protocol scheme.
 void setTemplate(String templateName)
          Sets a URL template for this URL.
protected  void setTemplate(URLTemplate urlTemplate)
           
 void setUrl(String url)
           
 String toString()
          Returns a string form (fully-quanlfied) of this URL.
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

POSTBACK_PARAM

public static final String POSTBACK_PARAM

Postback request query parameter (reserved).

See Also:
Constant Field Values

WINDOW_LABEL_PARAM

public static final String WINDOW_LABEL_PARAM

Window label query parameter (reserved).

See Also:
Constant Field Values

STATE_PARAM

public static final String STATE_PARAM

Window state query parameter (reserved).

See Also:
Constant Field Values

MODE_PARAM

public static final String MODE_PARAM

Window mode query parameter (reserved).

See Also:
Constant Field Values

PAGE_LABEL_PARAM

public static final String PAGE_LABEL_PARAM

Page label query parameter (reserved).

See Also:
Constant Field Values

CONTROL_STATE_PARAM

public static final String CONTROL_STATE_PARAM

Control state parameter (reserved).

See Also:
Constant Field Values

httpRequest

protected HttpServletRequest httpRequest

HTTP request.


httpResponse

protected HttpServletResponse httpResponse

HTTP response<./p>


params

protected LinkedHashMap params

Query parameters

Constructor Detail

TemplateHelper

public TemplateHelper(HttpServletRequest httpRequest,
                      HttpServletResponse httpResponse)

Constructs a GenericURL.

Parameters:
httpRequest - HTTP request
httpResponse - HTTP response
Method Detail

hasTemplateRef

public boolean hasTemplateRef(String templateRef)

getTemplateName

public String getTemplateName(String templateRef)

setTemplate

public void setTemplate(String templateName)

Sets a URL template for this URL.

Parameters:
templateName - name of the url template
Throws:
IllegalArgumentException - thrown if the named template does not exist or if the template is not valid

setTemplate

protected void setTemplate(URLTemplate urlTemplate)

getTemplate

public URLTemplate getTemplate()

Returns the current template.

Returns:
URL template

setScheme

public void setScheme(String scheme)

Sets the protocol scheme. Should be one of "HTTP" or "HTTPS". If a protocol is not specified, the protocol that was used to make the current request will be used.

Parameters:
scheme - protocol scheme

getScheme

public String getScheme()

Returns the protocol scheme. If no protocol was previously set, returns the protocol that was used to make the current request.

Returns:
protocol scheme

setPort

public void setPort(int port)

Sets a port. If a port is not specified, the port that was used to make the current request will be used.

Parameters:
port - port

getPort

public int getPort()

Returns the port. If no port was previously set, returns the port that was used to make the current request.

Returns:
port

setDomain

public void setDomain(String domain)

Sets the domain. If a domain is not specified, the domain that was used to make the current request will be used.

Parameters:
domain - domain

getDomain

public String getDomain()

Returns the domain. If no domain was previously set, returns the domain that was used to make the current request.

Returns:
domain

setPath

public void setPath(String path)

Sets path.

Parameters:
path - path

getQueryString

public String getQueryString()

setQueryString

public void setQueryString(String queryString)

setPathPrefix

public void setPathPrefix(String pathPrefix)

Sets a path prefix.

Parameters:
pathPrefix - path prefix

getPathPrefix

public String getPathPrefix()

Returns the path prefix.

Returns:
path prefix

setEncodeSession

public void setEncodeSession(boolean encodeSession)

Enables URL rewriting for encoding a session ID in the URL. If not set to true, does not encode the URL with the session ID. Default is true.

Parameters:
encodeSession - boolean

getEncodeSession

public boolean getEncodeSession()

Returns true if URL rewriting is enabled.

Returns:
boolean

setUrl

public void setUrl(String url)

addParameter

public void addParameter(String name,
                         String value)

Add a parameter. Multiple values for the same parameter can be set by calling this method multiple times with the same name.

Parameters:
name - name
value - value

removeParameter

public void removeParameter(String name)

Removes the given parameter.

Parameters:
name - name

getParameter

public String getParameter(String name)

Returns the value of the parameter. If the parameter has several values, returns the first value.

Parameters:
name - name of the parameter
Returns:
value value of the parameter

getParameters

public List getParameters(String name)

Returns the values of the given parameter.

Parameters:
name - name of the parameter
Returns:
values of the parameter

clone

public Object clone()

Returns a deep copy.

Overrides:
clone in class Object
Returns:
clone

toString

public String toString()

Returns a string form (fully-quanlfied) of this URL.

Overrides:
toString in class Object
Returns:
string