atg.repository.seo
Class UrlTemplate

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.repository.seo.UrlTemplate
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
DirectUrlTemplate, IndirectUrlTemplate

public abstract class UrlTemplate
extends GenericService

Abtract base class representing a template for a Url.

Users of this class can obtain a Url by cloning the UrlParameter array and populating the values of each of the parameters. The format method of this class can then be called which will use the MessageFormat object and the supplied parameter values to create the Url.

This class has 2 common sub classes: DirectUrlTemplate and IndirectUrlTemplate.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 java.util.List mExcludedBrowserTypes
           
protected  ApplicationLogging mLogger
           
protected  UrlParameterLookup[] mLookups
           
 int mMaxUrlLength
           
protected  java.text.MessageFormat mMessageFormat
           
 java.util.List mSupportedBrowserTypes
           
protected  UrlParameter[] mUrlParameters
           
 java.lang.String mUrlTemplateFormat
           
protected  boolean mUseDefaultWebApp
           
protected  WebApp mWebApp
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
UrlTemplate()
           
UrlTemplate(ApplicationLogging pLogger)
           
 
Method Summary
 UrlParameter[] cloneUrlParameters()
          Clones the parameters for this template to allow values to be set for this request.
 void doStartService()
          This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values.
 java.lang.String formatUrl(UrlParameter[] pUrlParams, WebApp pDefaultWebApp)
          Method to get a url String using this template with the given parameters.
 java.util.List getExcludedBrowserTypes()
          Getter method for list of excluded browser types.
 int getMaxUrlLength()
          Getter method for the max url length property.
 java.text.MessageFormat getMessageFormat()
          Returns the template MessageFormat object
 java.util.List getSupportedBrowserTypes()
          Getter method for list of supported browser types.
 java.lang.String getUrlTemplateFormat()
          Getter method for the url template format property.
protected  WebApp getWebApp()
          Getter method for the web application.
 WebAppRegistry getWebAppRegistry()
          Getter method for the web application registry.
protected abstract  void initialize()
          Abstract method to allow a template to be initialized.
 boolean isSupported(DynamoHttpServletRequest pRequest)
          Method to check whether the request browser type is supported by this template.
protected  void parseTemplate()
          Loops through all the characters in the template and pulls out the parameter names and whether they are escaped or not.
 void setExcludedBrowserTypes(java.util.List pExcludedBrowserTypes)
          Setter method for list of excluded browser types
 void setLookupMap(java.util.Map pLookupMap, UrlParameterLookup[] pSortedLookups)
          Associates types with each parameter.
 void setMaxUrlLength(int pMaxUrlLength)
          Setter method for the max url length property.
 void setSupportedBrowserTypes(java.util.List pSupportedBrowserTypes)
          Setter method for list of supported browser types
 void setUrlTemplateFormat(java.lang.String pUrlTemplateFormat)
          Setter method for the url template format property.
protected  void setUseDefaultWebApp(boolean pUseDefaultWebApp)
          Sets a flag to specify that the default web app should be used if available.
protected  void setWebApp(WebApp pWebApp)
          Setter method for web application.
 void setWebAppRegistry(WebAppRegistry pWebAppRegistry)
          Setter method for the web application registry.
 java.lang.String toString()
          Override toString() for meaningful logging
protected  boolean useDefaultWebApp()
           
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


mMessageFormat

protected java.text.MessageFormat mMessageFormat

mUrlParameters

protected UrlParameter[] mUrlParameters

mLookups

protected UrlParameterLookup[] mLookups

mWebApp

protected WebApp mWebApp

mUseDefaultWebApp

protected boolean mUseDefaultWebApp

mLogger

protected ApplicationLogging mLogger

mUrlTemplateFormat

public java.lang.String mUrlTemplateFormat

mMaxUrlLength

public int mMaxUrlLength

mSupportedBrowserTypes

public java.util.List mSupportedBrowserTypes

mExcludedBrowserTypes

public java.util.List mExcludedBrowserTypes
Constructor Detail

UrlTemplate

public UrlTemplate()

UrlTemplate

public UrlTemplate(ApplicationLogging pLogger)
Method Detail

getUrlTemplateFormat

public java.lang.String getUrlTemplateFormat()
Getter method for the url template format property.

Returns:
String Url template format

setUrlTemplateFormat

public void setUrlTemplateFormat(java.lang.String pUrlTemplateFormat)
Setter method for the url template format property.

Parameters:
pUrlTemplateFormat - String format of the url template

getMaxUrlLength

public int getMaxUrlLength()
Getter method for the max url length property.

Returns:
The maximum length of the generated URL

setMaxUrlLength

public void setMaxUrlLength(int pMaxUrlLength)
Setter method for the max url length property.

Parameters:
pMaxUrlLength - The maximum Url length to set.

getSupportedBrowserTypes

public java.util.List getSupportedBrowserTypes()
Getter method for list of supported browser types.

Returns:
List of supported browser types

setSupportedBrowserTypes

public void setSupportedBrowserTypes(java.util.List pSupportedBrowserTypes)
Setter method for list of supported browser types

Parameters:
pSupportedBrowserTypes - List of supported browser types

getExcludedBrowserTypes

public java.util.List getExcludedBrowserTypes()
Getter method for list of excluded browser types.

Returns:
List of excluded browser types

setExcludedBrowserTypes

public void setExcludedBrowserTypes(java.util.List pExcludedBrowserTypes)
Setter method for list of excluded browser types

Parameters:
pExcludedBrowserTypes - List of excluded browser types

getWebAppRegistry

public WebAppRegistry getWebAppRegistry()
Getter method for the web application registry.

Returns:
The web application registry.

setWebAppRegistry

public void setWebAppRegistry(WebAppRegistry pWebAppRegistry)
Setter method for the web application registry.

Parameters:
pWebAppRegistry - The web application registry to set.

doStartService

public void doStartService()
                    throws ServiceException
Description copied from class: GenericService
This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values. The Service should override this method to start any processes it requires.

Overrides:
doStartService in class GenericService
Throws:
ServiceException
See Also:
Initializes the template.

initialize

protected abstract void initialize()
                            throws atg.repository.seo.ItemLinkException
Abstract method to allow a template to be initialized.

Throws:
atg.repository.seo.ItemLinkException

getMessageFormat

public java.text.MessageFormat getMessageFormat()
Returns the template MessageFormat object

Returns:
the templates MessageFormat object

cloneUrlParameters

public UrlParameter[] cloneUrlParameters()
Clones the parameters for this template to allow values to be set for this request. Since the original parameters remain unaltered then this allows this template instance to be used by other requests.

Returns:
cloned array of UrlParameter in this template

formatUrl

public java.lang.String formatUrl(UrlParameter[] pUrlParams,
                                  WebApp pDefaultWebApp)
                           throws atg.repository.seo.ItemLinkException
Method to get a url String using this template with the given parameters. The Url may be cut is length if it is greater than the max length. If a web application is specified for this template then the context root will be prepended to the start of the formatted url string.

Parameters:
pUrlParam - UrlParameter array to use in the format
pDefaultWebApp - A default WebApp to use if one is required but none was specified
Returns:
String Url generated
Throws:
ItemLinkException

setWebApp

protected void setWebApp(WebApp pWebApp)
Setter method for web application.

Parameters:
pWebApp - WebApp object for the web application

getWebApp

protected WebApp getWebApp()
Getter method for the web application. The context path can be retrieved from this.

Returns:
the WebApp object for the web application.

setUseDefaultWebApp

protected void setUseDefaultWebApp(boolean pUseDefaultWebApp)
Sets a flag to specify that the default web app should be used if available.

Parameters:
pUseDefaultWebApp - true if the default web app should be used.

useDefaultWebApp

protected boolean useDefaultWebApp()
Returns:
true if the default web app should be used.

setLookupMap

public void setLookupMap(java.util.Map pLookupMap,
                         UrlParameterLookup[] pSortedLookups)
Associates types with each parameter. This allows other properties of item parameters to be referenced and also speeds up getting the value for a parameter. If a lookup matches the name of a parameter exactly then it is assigned to the parameter. Otherwise we loop through the lookup objects in descending name length order looking for a match on the start of the parameter name. e.g. If the parameter name is "item.parent.parent.displayName" and there are 2 lookup items "item" and "item.parent" then the "item.parent" will match first.

Parameters:
pLookupMap - Map of the UrlParameterLookup objects
pSortedLookups - array of the UrlParameterLookup objects sorted by name length

isSupported

public boolean isSupported(DynamoHttpServletRequest pRequest)
Method to check whether the request browser type is supported by this template. If the supported browser type list is not null or empty then it is used to check otherwise the excluded browser type list is checked.

Parameters:
pRequest - DynamoHttpServletRequest object
Returns:
true if this template supports the user agent in the request

parseTemplate

protected void parseTemplate()
                      throws atg.repository.seo.ItemLinkException

Loops through all the characters in the template and pulls out the parameter names and whether they are escaped or not. This allows us to create an array of UrlParameter and also a MessageFormat object.

Parameters wrapped in square brackets will not have their values encoded when embeded in the Url. Alternatively an 'encode=false' format type can be specified.

e.g. Either: "/[item.template.url]/"

or: "/{item.template.url, encode=false}/"

Other format types and styles can be used as per the java.text.MessageFormat class.

Also a web application name can be specified in the first part of the format string by ending it with a colon. e.g. "/PioneerCycling:/[item.template.url]" This would parse out the PioneerCycling and resolve it as a WebApp object in the web app registry. The ':' character would be discarded and everything after that would be part of the MessageFormat object.

e.g. Take the following template: "/jump/product/{item.displayName}/[item.template.url]" If item.displayName resolved to the String "DVD&Recorder" and item.template.url resolved to the String "ProductCatalog/products.jsp" then the resulting Url would be: "/jump/product/DVD%26Recorder/ProductCatalog/products.jsp"

Throws:
atg.repository.seo.ItemLinkException

toString

public java.lang.String toString()
Override toString() for meaningful logging

Overrides:
toString in class java.lang.Object
Returns:
String template format