1 5 package com.dotmarketing.util; 6 7 import java.util.Map ; 8 import java.util.StringTokenizer ; 9 10 import javax.portlet.ActionRequest; 11 import javax.portlet.WindowState; 12 import javax.servlet.http.HttpServletRequest ; 13 14 import com.liferay.portal.model.Layout; 15 import com.liferay.portal.util.WebKeys; 16 import com.liferay.portlet.ActionRequestImpl; 17 import com.liferay.portlet.PortletConfigImpl; 18 import com.liferay.portlet.RenderRequestImpl; 19 import com.liferay.util.Validator; 20 21 25 public class PortletURLUtil { 26 27 public static String getActionURL(ActionRequest req, String _windowState, Map _params) { 28 29 ActionRequestImpl reqImpl = (ActionRequestImpl) req; 31 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 32 33 return com.dotmarketing.util.PortletURLUtil.getActionURL(httpReq, _windowState, _params); 34 } 35 36 public static String getActionURL(HttpServletRequest req, String _windowState, Map _params) { 37 RenderRequestImpl renderRequest = (RenderRequestImpl) req.getAttribute(WebKeys.JAVAX_PORTLET_REQUEST); 38 39 PortletConfigImpl portletConfig = (PortletConfigImpl) req.getAttribute(WebKeys.JAVAX_PORTLET_CONFIG); 40 41 String portletName = portletConfig.getPortletId(); 42 Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT); 43 44 com.liferay.portlet.PortletURLImpl portletURL = new com.liferay.portlet.PortletURLImpl(renderRequest, portletName, layout.getLayoutId(), true); 45 46 try { 47 if (Validator.isNotNull(_windowState)) { 48 portletURL.setWindowState(new WindowState(_windowState)); 49 } else { 50 portletURL.setWindowState(renderRequest.getWindowState()); 51 } 52 53 portletURL.setPortletMode(renderRequest.getPortletMode()); 58 60 portletURL.setSecure(req.isSecure()); 65 67 if (_params != null) { 68 Logger.debug(Config.class, "Setting params=" + _params); 69 portletURL.setParameters(_params); 70 } 71 72 73 } catch (Exception e) { 74 Logger.warn(PortletURLUtil.class, e.toString(), e); 75 } 76 77 return stripProtocolAndHost(portletURL.toString()); 78 } 79 80 public PortletURLUtil() { 81 } 83 84 public static String getRenderURL(HttpServletRequest req, String _windowState, Map _params) { 85 RenderRequestImpl renderRequest = (RenderRequestImpl) req.getAttribute(WebKeys.JAVAX_PORTLET_REQUEST); 86 87 PortletConfigImpl portletConfig = (PortletConfigImpl) req.getAttribute(WebKeys.JAVAX_PORTLET_CONFIG); 88 89 String portletName = portletConfig.getPortletId(); 90 Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT); 91 92 com.liferay.portlet.PortletURLImpl portletURL = new com.liferay.portlet.PortletURLImpl(renderRequest, portletName, layout.getLayoutId(), 93 false); 94 95 try { 96 if (Validator.isNotNull(_windowState)) { 97 portletURL.setWindowState(new WindowState(_windowState)); 98 } else { 99 portletURL.setWindowState(renderRequest.getWindowState()); 100 } 101 102 portletURL.setPortletMode(renderRequest.getPortletMode()); 103 portletURL.setSecure(req.isSecure()); 104 105 if (_params != null) { 106 Logger.debug(PortletURLUtil.class, "Setting params=" + _params); 107 portletURL.setParameters(_params); 108 } 109 } catch (Exception e) { 110 Logger.error(PortletURLUtil.class, e.toString(), e); 111 } 112 return stripProtocolAndHost(portletURL.toString()); 113 } 114 115 120 121 122 private static String stripProtocolAndHost(String url){ 123 124 if(url.indexOf("://")<0){ 125 return url; 126 } 127 StringTokenizer st = new StringTokenizer (url, "/"); 128 StringBuffer sb = new StringBuffer (); 129 int i = 0; 130 131 while (st.hasMoreTokens()) { 132 String _y = st.nextToken(); 133 if (i > 1) { 134 sb.append("/"); 135 sb.append(_y); 136 } 137 i++; 138 } 139 return sb.toString(); 141 142 143 } 144 145 146 147 } 148
| Popular Tags
|