KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > session > RequestInfo


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portal.session;
6
7 import javax.faces.context.FacesContext;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import org.exoplatform.Constants;
10 import org.exoplatform.faces.context.PortletFacesContext;
11 /**
12  * Apr 12, 2004
13  * @author: Tuan Nguyen
14  * @email: tuan08@users.sourceforge.net
15  * @version: $Id: PortalRequestParameters.java,v 1.6 2004/09/27 03:01:18 tuan08 Exp $
16  **/

17 public class RequestInfo {
18   final static public String JavaDoc PORTAL_VIEW_ID = "/portal.jsp";
19   final static public String JavaDoc PAGE_VIEW_ID = "/page.jsp";
20   
21   final static public String JavaDoc PRIVATE_ACCESS = "private";
22   final static public String JavaDoc PUBLIC_ACCESS = "public";
23   final static public String JavaDoc ADMIN_ACCESS = "admin";
24   
25   private String JavaDoc portalOwner_ ;
26   private String JavaDoc pageName_ ;
27   private String JavaDoc portalAction_ ;
28   private String JavaDoc targetComponentId_ ;
29   private String JavaDoc portletWindowState_ ;
30   private String JavaDoc portletMode_ ;
31   private String JavaDoc portletActionType_ ;
32   private String JavaDoc lang_ ;
33   private String JavaDoc accessibility_ ;
34   private String JavaDoc contextPath_ ;
35   private String JavaDoc ownerURI_ ;
36   private String JavaDoc nodeURI_ ;
37   private String JavaDoc viewId_ ;
38   
39   public RequestInfo() {
40     
41   }
42   
43   public RequestInfo(HttpServletRequest JavaDoc req, String JavaDoc accessibility) {
44     init(req, accessibility) ;
45   }
46   
47   public void init(HttpServletRequest JavaDoc req, String JavaDoc accessibility) {
48     //parse uri ;
49
String JavaDoc 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 JavaDoc().append(contextPath_).append("/faces/").
69                  append(accessibility).append("/").append(portalOwner_).toString() ;
70     nodeURI_ = null ;
71   }
72   
73   public String JavaDoc getPortalOwner() { return portalOwner_ ; }
74   public String JavaDoc getPageName() { return pageName_ ; }
75   
76   public String JavaDoc getPortalAction() { return portalAction_ ; }
77   public String JavaDoc getTargetComponentId() { return targetComponentId_ ; }
78   public String JavaDoc getPortletWindowState() { return portletWindowState_ ; }
79   public String JavaDoc getPortletMode() { return portletMode_ ; }
80   public String JavaDoc getPortletActionType() { return portletActionType_ ; }
81   public String JavaDoc getLanguage() { return lang_ ; }
82   
83   public String JavaDoc getContextPath() { return contextPath_ ; }
84   public String JavaDoc getAccessibility() { return accessibility_ ; }
85   
86   public String JavaDoc getViewId() { return viewId_ ; }
87   
88   public String JavaDoc getOwnerURI() { return ownerURI_ ; }
89   
90   public String JavaDoc getPageURI() {
91     if(nodeURI_ == null) {
92       String JavaDoc 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 JavaDoc getPortalOwner(HttpServletRequest JavaDoc req) {
110     String JavaDoc pathInfo = req.getPathInfo() ;
111     int slashIndex = pathInfo.indexOf('/', 1) ;
112     String JavaDoc 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