Di Liferay ada beberapa macam URL yang bisa dimanfaatkan untuk keperluan membuat Custom Portlet atau modifikasi lainnya. Berikut adalah contoh source code untuk mengambil / mendapatkan beberapa jenis URL di Liferay :
[code language=”java”]
HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);
String currentCompleteUrl = PortalUtil.getCurrentCompleteURL(servletRequest);
try {
String renderCurrentURL = PortalUtil.getCurrentURL(request);
String servletRequestCurrentURL = PortalUtil.getCurrentURL(servletRequest);
String canonicalURL = PortalUtil.getCanonicalURL(currentCompleteUrl, themeDisplay, themeDisplay.getLayout());
String homeURL = PortalUtil.getHomeURL(servletRequest);
String currentPageURL = PortalUtil.getPortalURL(themeDisplay)+themeDisplay.getLayout().getFriendlyURL();
String portalUrl = PortalUtil.getPortalURL(request);
String servletRequestPortalUrl = PortalUtil.getPortalURL(servletRequest);
String themedisplayPortalUrl = PortalUtil.getPortalURL(themeDisplay);
String themedisplaylayoutPortalUrl = PortalUtil.getPortalURL(themeDisplay.getLayout(), themeDisplay);
String portalWebDir = PortalUtil.getPortalWebDir();
String portalLibDir = PortalUtil.getPortalLibDir();
System.out.println("currentCompleteUrl: "+currentCompleteUrl);
System.out.println("renderCurrentURL: "+renderCurrentURL);
System.out.println("servletRequestCurrentURL: "+servletRequestCurrentURL);
System.out.println("canonicalURL: "+canonicalURL);
System.out.println("homeURL: "+homeURL);
System.out.println("currentPageURL: "+currentPageURL);
System.out.println("portalUrl: "+portalUrl);
System.out.println("servletRequestPortalUrl: "+servletRequestPortalUrl);
System.out.println("themedisplayPortalUrl: "+themedisplayPortalUrl);
System.out.println("themedisplaylayoutPortalUrl: "+themedisplaylayoutPortalUrl);
System.out.println("portalWebDir: "+portalWebDir);
System.out.println("portalLibDir: "+portalLibDir);
} catch (Exception e) {
e.printStackTrace();
}
[/code]
Source code java tersebut diatas silahkan dimasukkan ke dalam Package di environment development Liferay kalian. Dan jangan lupa mengganti atau menghapus System.out.println(); jika ingin deploy ke Liferay Portal kalian. Script tersebut hanya digunakan jika kalian perlu menampilkan langsung di console sebelum deploy ke server.
Berikut contoh hasil dari source diatas :
[code language=”java”]
/**
currentCompleteUrl: http://localhost:8080/organization?selectedCard=Organization&cardViewState=Listview
renderCurrentURL: /organization?selectedCard=Organization&cardViewState=Listview
servletRequestCurrentURL: /organization?selectedCard=Organization&cardViewState=Listview
canonicalURL: http://localhost:8080/organization?selectedCard=Organization&cardViewState=Listview
homeURL: http://localhost:8080/web/guest
currentPageURL: http://localhost:8080/organization
portalUrl: http://localhost:8080
servletRequestPortalUrl: http://localhost:8080
themedisplayPortalUrl: http://localhost:8080
themedisplaylayoutPortalUrl: http://localhost:8080
portalWebDir: /opt/liferay/tomcat-7.0.42/webapps/ROOT/
portalLibDir: /opt/liferay/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/
**/
[/code]
Semoga bermanfaat 🙂