com.arsdigita.kernel
Class URLService

java.lang.Object
  extended bycom.arsdigita.kernel.URLService

public class URLService
extends Object

Supports generically locating a domain object on the site. The URLService can produce the path (relative to the root URL) to a page that displays the domain object identified by a given OID.

The service works by delegating to a URLFinder based on the object type of the given OID. A URLFinder must be registered with the URLService for the object type in question or one of its supertypes. That URLFinder dynamically produces a URL path by a process that potentially involves a few database queries.

The URLService is only intended for single-object lookups. On pages that display many objects (for example, a search results page), the URLs displayed for each object should not be obtained from the URLService (for performance reasons). Instead, a single "redirector page" should be the target of all those links. The user clicks on a link, which then uses the URLService to find the object's URL and redirect the user to the resulting URL. An example of this process is:

  1. User searches for objects based on keywords.
  2. Search page displays matching objects, with a link for each object. The targets of these links are all the same: .../display-result?id=:id&object_type=:object_type
  3. User clicks on one of those links.
  4. Display-result page uses the URLService to find the specified object's URL and redirect the user there.
The GenericURLFinder class provides a simple URLFinder that can be registered for many object types.

Author:
Oumi Mehrotra
See Also:
GenericURLFinder

Field Summary
static String versionId
           
 
Constructor Summary
URLService()
           
 
Method Summary
static URLFinder getFinder(ObjectType objectType)
          Gets the registered or inherited URLFinder for the specified object type.
static URLFinder getFinder(String objectType)
           
static URLFinder getRegisteredFinder(ObjectType objectType)
          Returns the URLFinder registered for the given object type.
static URLFinder getRegisteredFinder(String objectType)
          Returns the URLFinder registered for the given object type.
static String locate(OID oid)
          Returns a URL path to a page that displays the object identified by the given oid.
static String locate(OID oid, String context)
          Returns a URL path to a page that displays the object identified by the given oid.
static URLFinder registerFinder(ObjectType objectType, URLFinder finder)
          Registers a URLFinder for the specified data object type.
static URLFinder registerFinder(String objectType, URLFinder finder)
          Wrapper around registerFinder(ObjectType, URLFinder).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

URLService

public URLService()
Method Detail

locate

public static String locate(OID oid)
                     throws URLFinderNotFoundException,
                            NoValidURLException
Returns a URL path to a page that displays the object identified by the given oid. The URL path is relative to the server root. The URL is obtained by delgating to the registered or inherited URLFinder for the given oid's object type.

Throws:
URLFinderNotFoundException - when there is no URLFinder registered for the given oid's object type nor any of its supertypes.
NoValidURLException - when the URLFinder registered for the given oid's object type is unable to produce a valid non-null URL.

locate

public static String locate(OID oid,
                            String context)
                     throws URLFinderNotFoundException,
                            NoValidURLException
Returns a URL path to a page that displays the object identified by the given oid. The URL path is relative to the server root. The URL is obtained by delgating to the registered or inherited URLFinder for the given oid's object type.

Throws:
URLFinderNotFoundException - when there is no URLFinder registered for the given oid's object type nor any of its supertypes.
NoValidURLException - when the URLFinder registered for the given oid's object type is unable to produce a valid non-null URL.

registerFinder

public static URLFinder registerFinder(ObjectType objectType,
                                       URLFinder finder)
Registers a URLFinder for the specified data object type. The registered finder will be used by the locate method for OIDs whose type is equal to the specified type. That is, when locate(x) is executed, the specified finder will be used if the specified dataObjectType is equal to x.getObjectType().

Any object type that does not have a finder registered with this service is not supported by this service.

If another finder was already registered for the specified object type, the previous finder is replaced and returned.

Parameters:
objectType - the data object type for which to register the specified finder
finder - the URLFinder that will handle data objects of the specified data object type when the locate method is called
Returns:
the previous finder that was registered with this service for this object type.

registerFinder

public static URLFinder registerFinder(String objectType,
                                       URLFinder finder)
Wrapper around registerFinder(ObjectType, URLFinder).

See Also:
registerFinder(ObjectType, URLFinder)

getRegisteredFinder

public static URLFinder getRegisteredFinder(ObjectType objectType)
Returns the URLFinder registered for the given object type.


getRegisteredFinder

public static URLFinder getRegisteredFinder(String objectType)
Returns the URLFinder registered for the given object type.


getFinder

public static URLFinder getFinder(ObjectType objectType)
Gets the registered or inherited URLFinder for the specified object type. This is the URLFinder that is registered for the specified object type or its closest supertype that has a registered URLFinder. Returns null if there is no supertype that has a registered URLFinder.

Parameters:
objectType - the object type whose registered or inherited URLFinder is to be returned
Returns:
the registered or inherited URLFinder for the given object type. Returns null if no finder is registered for the given type or any of its supertypes.

getFinder

public static URLFinder getFinder(String objectType)
See Also:
getFinder(ObjectType)


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC