Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright © 2000, 2008, Oracle and/or its affiliates. All rights reserved.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.bea.portlet
Class GenericURL

    java.lang.Object
      com.bea.portlet.GenericURL

All Implemented Interfaces
  Cloneable

Direct Known Subclasses:
  DesktopURL, PostbackURL, ResourceURL

    public class GenericURL

extends Object
implements Cloneable

The `GenericURL` helps portal applications create URLs to resources within the portal.

To obtain an instance of `GenericURL` an application must supply valid `HttpServletRequest` and `HttpServletResponse` objects. This class derives certain default attributes from the request/response.

A `GenericURL` could be populated with the following attributes:

Attribute | Purpose | Notes
--- | --- | ---
Scheme | Scheme. Valid values are "http" and "https". | If not specified, uses the scheme that was used to make the request.
Domain | Server domain. | If not specified, uses the domain that was used to make the request. If requests are made via a proxy, specify the domain of the proxy server.
Port | Server port. | If not specified, uses the port from the request. If requests are made via a proxy, specify the port of the proxy server for the scheme used.
Secure port | Secure server port. | If not specified, uses the default secure server port. If requests are made via a proxy, specify the port of the proxy server for the scheme used.
Path prefix | Path prefix. | No default.
path | path is the relative path to the resource (typically used for static/dynamic resources such as files, images, etc.). If the webapp name should be added before the path, use `contextualPath`. | Defaults to the path used in the current request.
contextualPath | contextualPath is the relative path to the resource, excluding the webAppName (typically used for static/dynamic resources such as files, images, etc.). The webAppName will be added to the URL before the contextualPath. | No default.
Encode session | Encodes the URL to include session ID. | Defaults to `true`
Parameter | Query parameters. | These parameters will be appended in the query string of the URL. This implementation preserves the order of parameters. If a parameter has multiple values, all values will be added at the first occurrence.

In order to specify web-app wide defaults for the above attributes, named URL templates may be specified. A URL template is a parameterized fully-qualified URL string. Each URL template has a name. URL templates should be specified in "beehive-url-template-config.xml" file in WEB-INF directory of the webapp.

An example of a URL template (with name "mytemplate") is:
`http://my.domain.com/{url:prefix}/{url:path}?{url:queryString}&myParam1=myValue1`

In these templates, parameters are enclosed in {}s, and are replaced by attributes set on the URL object.

The parameters "url:path" and "url:queryString" are reserved and should be present in every template.

A URL object could be created using the template example above as follows:

          GenericURL url = GenericURL.createGenericURL(request, response);
          url.setTemplate("mytemplate");
          url.setPathPrefix("myproxypath");

In this example, since scheme, domain and port are not parameterized in the template, setting these attributes on the URL object will have no affect on the URL rendered.

If a template name is not specified on the GenericURL object, the template named "default" is used.

The templating mechanism recognizes the following parameters in URL templates:

Template Parameter | Description | Usage
--- | --- | ---
url:scheme | Scheme | May be set
url:domain | Domain | May be set
url:port | Port | May be set
url:securePort | Secure port | May be set
url:prefix | Purpose | May be set
url:path | Extra path information | Reserved, must be present in a template.
url:contextualPath | Relative path to the resource, excluding the webAppName. | No default, may be set in template.
url:queryString | Reserved query parameters | Reserved, must be present in a template.
url:currentPage | Current page parameter | May be set
url:compression | The presence of this parameter indicates that the URL should be compressed after it has been created. | May be set

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

Field Summary
`static String` | `COMMUNITY_ADMIN_FLAG_PARAM` Name of the param used to provide a hint that the user wants to retrieve the admin view of a community resource - as opposed to their customized view.
`static String` | `COMMUNITY_DESKTOP` Communities standalone portlet flag query parameter.
`static String` | `CONTROL_STATE_PARAM` Control state parameter (reserved).
`static String` | `CURRENT_PAGE`
`protected String` | `domain` Server domain.
`static String` | `DOMAIN` Template parameter: domain.
`static String` | `EVENT_NAME_PARAM` Custom event name query parameter (reserved).
`protected javax.servlet.http.HttpServletRequest` | `httpRequest` HTTP request.
`protected javax.servlet.http.HttpServletResponse` | `httpResponse` HTTP response.
`protected String` | `httpsDomain` Server https domain.
`static String` | `LOADSTATE_PARAM` Load state request query parameter (reserved).
`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` | `PATH` Template parameter: path.
`static String` | `PORT` Template parameter: port.
`static String` | `PORTLET_SUB_INSTANCE_ID` subInstanceId param: denotes a subInstanceId that is to be used for a Portlet
`static String` | `POSTBACK_PARAM` Postback request query parameter (reserved).
`static String` | `PREFIX` Template parameter: prefix.
`static String` | `QUERY_STRING` Template parameter: queryString.
`static String` | `SCHEME` Template parameter: scheme.
`static String` | `SECURE_PORT` Template parameter: securePort.
`static String` | `STATE_PARAM` Window state query parameter (reserved).
`static String` | `TREE_OPTIMIZATION_PARAM` Tree Optimization request query parameter (reserved).
`static String` | `URL_COMPRESSION`
`static String` | `WINDOW_LABEL_PARAM` Window label query parameter (reserved).

Constructor Summary
`protected` | `GenericURL(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Constructs a `GenericURL`.

Method Summary
`protected void` | `addAjaxNoRewriteParam()`
`void` | `addParameter(String name, String value)` Adds a query parameter to the URL.
`void` | `addParameter(String name, String value, boolean encode)` Adds a query parameter to the URL.
`void` | `addParameter(String name, String value, boolean encodeName, boolean encodeValue)` Add a query parameter to the URL.
`protected static StringBuffer` | `appendEnsureSeparator(StringBuffer buf, String token)` Deprecated As of 9.2 SP2, replaced by `appendEnsureSeparator`
`protected static StringBuilder` | `appendEnsureSeparator(StringBuilder buf, String token)`
`Object` | `clone()` Returns a deep copy of the URL object.
`static GenericURL` | `createGenericURL(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Constructs a `GenericURL` object with default values.
`protected StringBuffer` | `createQueryString()` Deprecated As of 9.2 SP2, replaced by `createQueryStringBuilder`
`protected StringBuilder` | `createQueryStringBuilder()` Creates a query string with the parameters set so far.
`String` | `getAmpForm()` Returns the ampersand entity form used for this URL.
`String` | `getContextualPath()` Returns the contextualPath, if previously set using the setContextualPath() method.
`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` | `getPath()` Returns the value previously set with `setPath()`.
`String` | `getPathPrefix()` Returns the path prefix, if one has been set.
`int` | `getPort()` Returns the port.
`protected String` | `getResolvedTemplate()` Returns the template used for generating the URL string.
`String` | `getScheme()` Returns the protocol scheme.
`int` | `getSecurePort()` Returns the secure port.
`String` | `getTemplate()` Returns the current template.
`String` | `getUrlType()` Returns the type of this URL.
`void` | `removeParameter(String name)` Removes the given query parameter.
`void` | `setContextualPath(String contextualPath)` Sets contextual path.
`void` | `setDomain(String domain)` Sets the domain.
`void` | `setEncodeSession(boolean encodeSession)` Enables URL rewriting for encoding a session ID in the URL.
`void` | `setForcedAmpForm(boolean useAmpEntity)` Forces the form of query separators used for this URL.
`void` | `setPath(String path)` Sets the path.
`void` | `setPathPrefix(String pathPrefix)` Sets a path prefix.
`void` | `setPort(int port)` Sets a port.
`void` | `setScheme(String scheme)` Sets the protocol scheme.
`void` | `setSecurePort(int securePort)` Sets a secure port.
`void` | `setTemplate(String templateName)` Sets a URL template for this URL by the template name.
`String` | `toString()` Returns a string form (fully-qualified) of this URL removing any unset template parameters.
`String` | `toString(boolean removeUnsetParams)` Returns a string form (fully-qualified) of this URL.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### LOADSTATE_PARAM

    public static final String LOADSTATE_PARAM

  Load state request query parameter (reserved).

  See Also
    Constants Summary

### POSTBACK_PARAM

    public static final String POSTBACK_PARAM

  Postback request query parameter (reserved).

  See Also
    Constants Summary

### COMMUNITY_DESKTOP

    public static final String COMMUNITY_DESKTOP

  Communities standalone portlet flag query parameter.

  See Also
    Constants Summary

### TREE_OPTIMIZATION_PARAM

    public static final String TREE_OPTIMIZATION_PARAM

  Tree Optimization request query parameter (reserved).

  See Also
    Constants Summary

### WINDOW_LABEL_PARAM

    public static final String WINDOW_LABEL_PARAM

  Window label query parameter (reserved).

  See Also
    Constants Summary

### STATE_PARAM

    public static final String STATE_PARAM

  Window state query parameter (reserved).

  See Also
    Constants Summary

### MODE_PARAM

    public static final String MODE_PARAM

  Window mode query parameter (reserved).

  See Also
    Constants Summary

### PAGE_LABEL_PARAM

    public static final String PAGE_LABEL_PARAM

  Page label query parameter (reserved).

  See Also
    Constants Summary

### EVENT_NAME_PARAM

    public static final String EVENT_NAME_PARAM

  Custom event name query parameter (reserved).

  See Also
    Constants Summary

### CONTROL_STATE_PARAM

    public static final String CONTROL_STATE_PARAM

  Control state parameter (reserved).

  See Also
    Constants Summary

### PORTLET_SUB_INSTANCE_ID

    public static final String PORTLET_SUB_INSTANCE_ID

  subInstanceId param: denotes a subInstanceId that is to be used for a Portlet

  See Also
    Constants Summary

### COMMUNITY_ADMIN_FLAG_PARAM

    public static final String COMMUNITY_ADMIN_FLAG_PARAM

  Name of the param used to provide a hint that the user wants to retrieve the admin view of a community resource - as opposed to their customized view.

  See Also
    Constants Summary

### SCHEME

    public static final String SCHEME

  Template parameter: scheme.

  See Also
    Constants Summary

### DOMAIN

    public static final String DOMAIN

  Template parameter: domain.

  See Also
    Constants Summary

### PORT

    public static final String PORT

  Template parameter: port.

  See Also
    Constants Summary

### SECURE_PORT

    public static final String SECURE_PORT

  Template parameter: securePort.

  See Also
    Constants Summary

### PREFIX

    public static final String PREFIX

  Template parameter: prefix.

  See Also
    Constants Summary

### PATH

    public static final String PATH

  Template parameter: path.

  See Also
    Constants Summary

### QUERY_STRING

    public static final String QUERY_STRING

  Template parameter: queryString.

  See Also
    Constants Summary

### CURRENT_PAGE

    public static final String CURRENT_PAGE

See Also
  Constants Summary

### URL_COMPRESSION

    public static final String URL_COMPRESSION

See Also
  Constants Summary

### httpRequest

    protected javax.servlet.http.HttpServletRequest httpRequest

  HTTP request.

### httpResponse

    protected javax.servlet.http.HttpServletResponse httpResponse

  HTTP response.

### domain

    protected String domain

  Server domain.

### httpsDomain

    protected String httpsDomain

  Server https domain.

### params

    protected LinkedHashMap params

  Query parameters

Constructor Detail

### GenericURL

    protected GenericURL(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)

  Constructs a `GenericURL`.

  Parameters
    `request` - HTTP request
    `response` - HTTP response

Method Detail

### createGenericURL

    public static GenericURL createGenericURL(javax.servlet.http.HttpServletRequest request,
                                              javax.servlet.http.HttpServletResponse response)

  Constructs a `GenericURL` object with default values.

  Parameters
    `request` - HTTP request
    `response` - HTTP response

### setTemplate

    public void setTemplate(String templateName)

  Sets a URL template for this URL by the template name.

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

### getTemplate

    public String getTemplate()

  Returns the current template. This is the template value, not the template name as may have been passed into setTemplate(String).

  Returns
    URL template value.

### getResolvedTemplate

    protected String getResolvedTemplate()

  Returns the template used for generating the URL string.

  This method returns the same value as does the `getTemplate()` method if the set template exists. If not, this method returns the default template named "default".

### 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- must be either "http" or "https".

### 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 from the request will be used.

  Parameters
    `port` - port

### getPort

    public int getPort()

  Returns the port. If no port was previously set, returns the port from the request.

  Returns
    port

### setSecurePort

    public void setSecurePort(int securePort)

  Sets a secure port. If a port is not specified, the default server secure port will be used.

  Parameters
    `securePort` - secure port

### getSecurePort

    public int getSecurePort()

  Returns the secure port. If no port was previously set, returns the default secure server port.

  Returns
    secure 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 the path. If no path is specified using this setPath() method or the setContextualPath() method, the requestURI from the HttpServletRequest will be used as the path.

  Parameters
    `path` - path

### getPath

    public String getPath()

  Returns the value previously set with `setPath()`.

  If no calls to setPath() or setContextualPath() are made, the requestURI from the HttpServletRequest is used as the path.

  Returns
    The previously set path, or `null` if no previous call to `setPath()` has been performed.
  See Also
    `setPath(String)`

### getContextualPath

    public String getContextualPath()

  Returns the contextualPath, if previously set using the setContextualPath() method.

  If no calls to setPath() or setContextualPath() are made, the requestURI from the HttpServletRequest is used as the path.

  Returns
    the contextualPath previously set using the setContextualPath() method, or `null` if setContextualPath() has not been called previously.

### setContextualPath

    public void setContextualPath(String contextualPath)

  Sets contextual path.

  If no calls to setPath() or setContextualPath() are made, the requestURI from the HttpServletRequest is used as the path.

  Parameters
    `contextualPath` -

### setPathPrefix

    public void setPathPrefix(String pathPrefix)

  Sets a path prefix.

  Parameters
    `pathPrefix` - path prefix

### getPathPrefix

    public String getPathPrefix()

  Returns the path prefix, if one has been set.

  Returns
    path prefix

### setEncodeSession

    public void setEncodeSession(boolean encodeSession)

  Enables URL rewriting for encoding a session ID in the URL. If set to `true`, the session ID will be encoded in the URL. Default is `true`.

  Parameters
    `encodeSession` - `true` if the session ID is to be encoded in the URL, `false` if it is not.

### getEncodeSession

    public boolean getEncodeSession()

  Returns `true` if URL rewriting is enabled.

  Returns
    boolean

### addParameter

    public void addParameter(String name,
                             String value)

  Adds a query parameter to the URL. Multiple values for the same parameter can be set by calling this method multiple times with the same name.

  This method URL encodes the parameter name and value.

  Parameters
    `name` - the name of the query parameter.
    `value` - the value of the query parameter.

### addParameter

    public void addParameter(String name,
                             String value,
                             boolean encode)

  Adds a query parameter to the URL. Multiple values for the same parameter can be set by calling this method multiple times with the same name.

  If the boolean argument is true, this method URL encodes the parameter name and value.

  Parameters
    `name` - the name of the query parameter.
    `value` - the value of the query parameter.
    `encode` - if `true`, the name and value of the query parameter are URL-encoded before being added to the URL. If `false`, the name and value of the query parameter are not URL-encoded.

### addParameter

    public void addParameter(String name,
                             String value,
                             boolean encodeName,
                             boolean encodeValue)

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

  If the encodeName boolean argument is true, this method URL encodes the parameter name. If the encodeValue boolean argument is true, this method URL encodes the parameter value.

  Parameters
    `name` - the name of the query parameter.
    `value` - the value of the query parameter.
    `encodeName` - if `true`, the name of the query parameter is URL-encoded before being added to the URL. If `false`, the name of the query parameter is not URL-encoded.
    `encodeValue` - if `true`, the value of the query parameter is URL-encoded before being added to the URL. If `false`, the value of the query parameter is not URL-encoded.

### removeParameter

    public void removeParameter(String name)

  Removes the given query parameter. If multiple values for the parameter exist, they are all removed.

  Parameters
    `name` - the name of the parameter to remove.

### 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 of the URL object.

  Overrides:
    `clone` in class `Object`
  Returns
    a deep copy of the URL object.

### appendEnsureSeparator

    @Deprecated
    protected static StringBuffer appendEnsureSeparator(StringBuffer buf,
                                                                   String token)

  Deprecated As of 9.2 SP2, replaced by `appendEnsureSeparator`

### appendEnsureSeparator

    protected static StringBuilder appendEnsureSeparator(StringBuilder buf,
                                                         String token)

### getUrlType

    public String getUrlType()

  Returns the type of this URL.

  Returns
    the type of this URL: `URLTemplatesFactory.SECURE_ACTION_TEMPLATE` for a secure URL, `URLTemplatesFactory.ACTION_TEMPLATE` for an insecure URL.

### toString

    public String toString()

  Returns a string form (fully-qualified) of this URL removing any unset template parameters.

  Overrides:
    `toString` in class `Object`
  Returns
    string

### toString

    public String toString(boolean removeUnsetParams)

  Returns a string form (fully-qualified) of this URL. If the boolean argument is `true`, removes unset template parameters.

  Parameters
    `removeUnsetParams` - if `true`, unset template parameters will be removed.
  Returns
    a string representation of the URL.

### addAjaxNoRewriteParam

    protected void addAjaxNoRewriteParam()

### createQueryString

    @Deprecated
    protected StringBuffer createQueryString()

  Deprecated As of 9.2 SP2, replaced by `createQueryStringBuilder`

  Creates a query string with the parameters set so far.

### createQueryStringBuilder

    protected StringBuilder createQueryStringBuilder()

  Creates a query string with the parameters set so far.

  Returns
    query string

### setForcedAmpForm

    public void setForcedAmpForm(boolean useAmpEntity)

  Forces the form of query separators used for this URL. Calls to this method override the configured mechanisms for determining ampersand entity (`&amp;`) vs. character (`&`) usage including:

  - Skeleton RenderFormat
  - Beehive configuration
  - internal default

  The algorithm for determining ampersand form (absent calls to this method) is roughly as follows: If the skeleton RenderFormat specifies XHTML the ampersand form will be entity (`&amp;`), otherwise Beehive configuration will be used. In the absence of Beehive configuration, the internal default ampersand form will be character (`&`).

  Note: This method has no effect if URL compression is enabled.

  Parameters
    `useAmpEntity` - true if this url should be forced to use ampersand entities (`&amp;`); false if this url should be forced to use ampersand characters (`&`)
  See Also
    `RenderFormat`, Beehive Configuration

### getAmpForm

    public String getAmpForm()

  Returns the ampersand entity form used for this URL.

  Returns
    the ampersand entity form used for this URL.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000, 2008, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.