How to get and modify Portal-URL

2 Comments »

import com.liferay.portal.kernel.util.HttpUtil; 
import com.liferay.portal.kernel.util.ParamUtil; 
import com.liferay.portal.util.PortalUtil;
 
// delivers url-path including parameters
String currentUrlPathWithParamters = PortalUtil.getCurrentURL( request );
// --> Example: /group/guest/home?foo=test

// delivers url-path without parameters
String currentUrlPath = HttpUtil.getPath(currentUrlPathWithParamters);
// --> Example: /group/guest/home

// delivers complete url
String currentUrl = PortalUtil.getPortalURL( request ) + currentUrlPath;
// --> Example: http://localhost:8080/group/guest/home

// adding parameters to url
String urlWithCustomParameter= HttpUtil.addParameter(currentUrl,"foo", "faa");
// --> Example: http://localhost:8080/group/guest/home?foo=faa