View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.webscripts.portlet;
20  
21  import java.util.Map;
22  
23  import javax.portlet.PortletRequest;
24  
25  import org.springframework.extensions.surf.util.Content;
26  import org.springframework.extensions.webscripts.Match;
27  import org.springframework.extensions.webscripts.Runtime;
28  import org.springframework.extensions.webscripts.WebScriptRequestURLImpl;
29  
30  
31  /**
32   * JSR-168 Web Script Request
33   * 
34   * @author davidc
35   */
36  public class WebScriptPortletRequest extends WebScriptRequestURLImpl
37  {
38      public static final String ALFPORTLETUSERNAME = "alfportletusername";
39      
40      /** Portlet Request */
41      private PortletRequest req;
42      
43      
44      /**
45       * Construct
46       * 
47       * @param req
48       * @param scriptUrl
49       * @param serviceMatch
50       */
51      public WebScriptPortletRequest(Runtime container, PortletRequest req, String scriptUrl, Match serviceMatch)
52      {
53          this(container, req, splitURL(scriptUrl), serviceMatch);
54      }
55      
56      /**
57       * Construct
58       * 
59       * @param req
60       * @param scriptUrlParts
61       * @param serviceMatch
62       */
63      public WebScriptPortletRequest(Runtime container, PortletRequest req, String[] scriptUrlParts, Match serviceMatch)
64      {
65          super(container, scriptUrlParts, serviceMatch);
66          this.req = req;
67          if (req != null)
68          {
69              // look for the user info map in the portlet request - populated by the portlet container
70              Map userInfo = (Map)req.getAttribute(PortletRequest.USER_INFO);
71              if (userInfo != null)
72              {
73                  // look for the special Liferay email (username) key
74                  String liferayUsername = (String)userInfo.get("user.home-info.online.email");
75                  if (liferayUsername != null)
76                  {
77                      // strip suffix from email address - we only need username part
78                      if (liferayUsername.indexOf('@') != -1)
79                      {
80                          liferayUsername = liferayUsername.substring(0, liferayUsername.indexOf('@'));
81                      }
82                      // save in session for use by alfresco portlet authenticator
83                      this.req.getPortletSession().setAttribute(ALFPORTLETUSERNAME, liferayUsername);
84                  }
85              }
86          }
87      }
88  
89      /**
90       * Gets the Portlet Request
91       * 
92       * @return  Portlet Request
93       */
94      public PortletRequest getPortletRequest()
95      {
96          return req;
97      }
98      
99      /* (non-Javadoc)
100      * @see org.alfresco.web.scripts.WebScriptRequest#getServerPath()
101      */
102     public String getServerPath()
103     {
104         return req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
105     }
106 
107     /* (non-Javadoc)
108      * @see org.alfresco.web.scripts.WebScriptRequest#getAgent()
109      */
110     public String getAgent()
111     {
112         // NOTE: rely on default agent mappings
113         return null;
114     }
115 
116     /* (non-Javadoc)
117      * @see org.alfresco.web.scripts.WebScriptRequest#getHeaderNames()
118      */
119     public String[] getHeaderNames()
120     {
121         return new String[] {};
122     }
123 
124     /* (non-Javadoc)
125      * @see org.alfresco.web.scripts.WebScriptRequest#getHeader(java.lang.String)
126      */
127     public String getHeader(String name)
128     {
129         return null;
130     }
131 
132     /* (non-Javadoc)
133      * @see org.alfresco.web.scripts.WebScriptRequest#getHeaderValues(java.lang.String)
134      */
135     public String[] getHeaderValues(String name)
136     {
137         return null;
138     }
139     
140     /* (non-Javadoc)
141      * @see org.alfresco.web.scripts.WebScriptRequest#getContent()
142      */
143     public Content getContent()
144     {
145         return null;
146     }
147 
148 }