2.14.2.2.1.  PortalURL

PortalURL plays a similar role at the portal level. Its main role is to abstract the creation of an URL for a resource managed by the portal.



public abstract class PortalURL<R, U extends PortalURL<U>>
{
   ...
}

The PortalURL declaration may seem a bit strange at first sight with two generic types: U and R.

A portal URL has various methods but certainly the most important method is the toString() method that generates an URL targeting to the resource. The remaining methods are getter and setter used to mutate the URL configuration, those options will affect the URL representation when it is generated.

Obtaining a PortalURL

PortalURL objects are obtained from RequestContext instance, such as the PortalRequestContext, or the PortletRequestContext. Usually, those are obtained thanks to the getCurrentInstance method of the RequestContext class:



RequestContext ctx = RequestContext.getCurrentInstance();

PortalURL are created via to the createURL method that takes an input as a resource type. The resource type is usually a constant and type-safe object that allows to retrieve the PortalURL subclasses:



RequestContext ctx = RequestContext.getCurrentInstance();
PortalURL<R, U> url = ctx.createURL(type);

In reality, you will use a concrete type constant and have instead more concrete code like:



RequestContext ctx = RequestContext.getCurrentInstance();
NodeURL url = ctx.createURL(NodeURL.TYPE);

Note

The NodeURL.TYPE is actually declared as new ResourceType<NavigationResource, NodeURL>() that can be described as a type-literal object emulated by a Java anonymous inner class. Such literal was introduced by Neil Gafter as Super Type Token and popularized by Google Guice as Type Literal. It is an interesting way to create a literal representing a kind of Java type.

Copyright ©2012. All rights reserved. eXo Platform SAS