Obtain the plugin binary package from the Liferay Marketplace and deploy using the Liferay control panel Apps page in the usual way.

If you have pre-existing content in your portal, tiny URLs for them will be automatically generated during portal startup. This operation may take some time to complete, depending on how much content you have on your portal. The portal will not come up until it has finished.

From this point on, tiny URLs will be automatically generated when content is created or edited.

The resulting Tiny URLs have the format portal_url/t/xyzabc.

Optional portal property: setting

controls whether the user must be logged in before an attempt is made to display the resource corresponding to a tiny URL. (If not logged in, he will be prompted to log in.) The default is true, i.e. the user must be logged in. If set to false, the user's browser URL bar will show the decoded friendly URL of the resource corresponding to the tiny URL even if it is on a private page. This can result in undesired disclosure of privileged information contained in the friendly URL.


A typical scenario goes like this:

To display the tiny URL to users, a tool included in the plugin can be used. Most commonly, you would place a special web content article on the page.

Step 1: Create a web content structure. It does not need to have any fields.

Step 2: Create a template for the structure, such as the following Velocity code snippet:

#set ($tinyURLTools = $utilLocator.findUtil('tinyurl-portlet', 'org.hopeconsultants.portlet.tinyurl.util.TinyURLTools'))

#set ($friendly_url = $request.get('attributes').get('FRIENDLY_URL')) #set ($theme_display = $request.get('theme-display'))

#set ($tiny_url = $tinyURLTools.getTinyURL($!friendly_url, $theme_display))

<div> <label>Tiny URL for this article</label> <input onclick="Liferay.Util.selectAndCopy(this);" readonly="true" value="$!tiny_url" /> </div>

Step 3: Create a web content article using the template. It does not need to have any data.

Step 4: Use a web content display to show the article on the pages you wish.

Similar code can be used a JSP page. Note that the TinyURLTools class expects the flattened ThemeDisplay object available in a web content template, so we have to construct one:

Object tinyURLToolsBean = PortletBeanLocatorUtil.locate("tinyurl-portlet", "org.hopeconsultants.portlet.tinyurl.util.TinyURLTools");

MethodKey getTinyURLMethodKey = new MethodKey(tinyURLToolsBean.getClass(), "getTinyURL", String.class, Map.class);

MapflatThemeDisplay = new HashMap();

flatThemeDisplay.put("server-name", themeDisplay.getServerName()); flatThemeDisplay.put("plid", plid); flatThemeDisplay.put("url-portal", themeDisplay.getURLPortal());

String tinyURL = (String)getTinyURLMethodKey.getMethod().invoke(tinyURLToolsBean, DLUtil.getPreviewURL(fileEntry, null, null, StringPool.BLANK, false, true), flatThemeDisplay);

Usage Example

On a page, place the special web content display and an asset publisher with default settings (i.e. dynamic mode, showing all your assets as abstracts).

When first visiting the page, the tiny URL corresponds to the page. When a user enters the tiny URL into his browser, he will be taken to the same page with the asset publisher showing the abstracts.

If you now click on an asset to show its full content, the tiny URL changes to correspond to that asset. When a user enters this tiny URL into his browser, he will be taken to the same page with the asset publisher showing that asset as full content.


To clean up the tiny URL database table, deleting orphaned entries and creating missing entries, add the following line to and restart the portal.


Supported content types and portlets


1: Not all the weird and wonderful formats of friendly URL are supported, only those which the portal provides in the FRIENDLY_URL request attribute.

2: At present, Documents and Media and Documents and Media Display portlets are not supported. Use an Asset Publisher portlet instead.

3: At present only site scope is supported.