1 5 package org.exoplatform.portal.session; 6 7 import javax.faces.context.FacesContext; 8 import javax.servlet.http.HttpServletRequest ; 9 import org.exoplatform.Constants; 10 import org.exoplatform.faces.context.PortletFacesContext; 11 17 public class RequestInfo { 18 final static public String PORTAL_VIEW_ID = "/portal.jsp"; 19 final static public String PAGE_VIEW_ID = "/page.jsp"; 20 21 final static public String PRIVATE_ACCESS = "private"; 22 final static public String PUBLIC_ACCESS = "public"; 23 final static public String ADMIN_ACCESS = "admin"; 24 25 private String portalOwner_ ; 26 private String pageName_ ; 27 private String portalAction_ ; 28 private String targetComponentId_ ; 29 private String portletWindowState_ ; 30 private String portletMode_ ; 31 private String portletActionType_ ; 32 private String lang_ ; 33 private String accessibility_ ; 34 private String contextPath_ ; 35 private String ownerURI_ ; 36 private String nodeURI_ ; 37 private String viewId_ ; 38 39 public RequestInfo() { 40 41 } 42 43 public RequestInfo(HttpServletRequest req, String accessibility) { 44 init(req, accessibility) ; 45 } 46 47 public void init(HttpServletRequest req, String accessibility) { 48 String pathInfo = req.getPathInfo() ; 50 int slashIndex = pathInfo.indexOf('/', 1) ; 51 if(slashIndex > 0) { 52 portalOwner_ = pathInfo.substring(1, slashIndex) ; 53 pageName_ = pathInfo.substring(slashIndex , pathInfo.length()) ; 54 } else { 55 portalOwner_ = pathInfo.substring(1, pathInfo.length()) ; 56 pageName_ = null ; 57 } 58 if("/page.jsp".equals(pathInfo)) viewId_ = PAGE_VIEW_ID ; 59 else viewId_ = PORTAL_VIEW_ID ; 60 portalAction_ = req.getParameter(Constants.PORTAL_ACTION) ; 61 targetComponentId_ = req.getParameter(Constants.COMPONENT_PARAMETER) ; 62 portletWindowState_ = req.getParameter(Constants.WINDOW_STATE_PARAMETER) ; 63 portletMode_ = req.getParameter(Constants.PORTLET_MODE_PARAMETER) ; 64 portletActionType_ = req.getParameter(Constants.TYPE_PARAMETER); 65 lang_ = req.getParameter(Constants.LANGUAGE_PARAMETER) ; 66 contextPath_ = req.getContextPath() ; 67 accessibility_ = accessibility ; 68 ownerURI_ = new StringBuffer ().append(contextPath_).append("/faces/"). 69 append(accessibility).append("/").append(portalOwner_).toString() ; 70 nodeURI_ = null ; 71 } 72 73 public String getPortalOwner() { return portalOwner_ ; } 74 public String getPageName() { return pageName_ ; } 75 76 public String getPortalAction() { return portalAction_ ; } 77 public String getTargetComponentId() { return targetComponentId_ ; } 78 public String getPortletWindowState() { return portletWindowState_ ; } 79 public String getPortletMode() { return portletMode_ ; } 80 public String getPortletActionType() { return portletActionType_ ; } 81 public String getLanguage() { return lang_ ; } 82 83 public String getContextPath() { return contextPath_ ; } 84 public String getAccessibility() { return accessibility_ ; } 85 86 public String getViewId() { return viewId_ ; } 87 88 public String getOwnerURI() { return ownerURI_ ; } 89 90 public String getPageURI() { 91 if(nodeURI_ == null) { 92 String pageName = pageName_ ; 93 if(pageName == null) { 94 pageName = getPortal().getSelectedNode().getUri() ; 95 } 96 nodeURI_ = ownerURI_ + pageName ; 97 } 98 return nodeURI_ ; 99 } 100 101 public ExoPortal getPortal() { 102 FacesContext portalContext = FacesContext.getCurrentInstance() ; 103 if (portalContext instanceof PortletFacesContext) { 104 portalContext = ((PortletFacesContext) portalContext).getPortalFacesContext() ; 105 } 106 return (ExoPortal) portalContext.getViewRoot().getChildren().get(0) ; 107 } 108 109 static public String getPortalOwner(HttpServletRequest req) { 110 String pathInfo = req.getPathInfo() ; 111 int slashIndex = pathInfo.indexOf('/', 1) ; 112 String owner = null ; 113 if(slashIndex > 0) { 114 owner = pathInfo.substring(1, slashIndex) ; 115 } else { 116 owner = pathInfo.substring(1, pathInfo.length()) ; 117 } 118 return owner ; 119 } 120 } | Popular Tags |