1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.sharepoint;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.model.User;
28  
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  /**
36   * <a href="SharepointRequest.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Bruno Farache
39   *
40   */
41  public class SharepointRequest {
42  
43      public SharepointRequest(String rootPath) {
44          _rootPath = rootPath;
45      }
46  
47      public SharepointRequest(
48          HttpServletRequest request, HttpServletResponse response, User user) {
49  
50          _request = request;
51          _response = response;
52          _user = user;
53  
54          _params.putAll(request.getParameterMap());
55      }
56  
57      public void addParam(String key, String value) {
58          _params.put(key, new String[] {value});
59      }
60  
61      public byte[] getBytes() {
62          return _bytes;
63      }
64  
65      public long getCompanyId() {
66          return _user.getCompanyId();
67      }
68  
69      public HttpServletRequest getHttpServletRequest() {
70          return _request;
71      }
72  
73      public HttpServletResponse getHttpServletResponse() {
74          return _response;
75      }
76  
77      public String getParameterValue(String name) {
78          String[] values = _params.get(name);
79  
80          if ((values != null) && (values.length > 0)) {
81              return GetterUtil.getString(_params.get(name)[0]);
82          }
83          else {
84              return StringPool.BLANK;
85          }
86      }
87  
88      public String getRootPath() {
89          return _rootPath;
90      }
91  
92      public SharepointStorage getSharepointStorage() {
93          return _storage;
94      }
95  
96      public User getUser() {
97          return _user;
98      }
99  
100     public long getUserId() {
101         return _user.getUserId();
102     }
103 
104     public void setBytes(byte[] bytes) {
105         _bytes = bytes;
106     }
107 
108     public void setRootPath(String rootPath) {
109         _rootPath = SharepointUtil.replaceBackSlashes(rootPath);
110     }
111 
112     public void setSharepointStorage(SharepointStorage storage) {
113         _storage = storage;
114     }
115 
116     private SharepointStorage _storage;
117     private HttpServletRequest _request;
118     private HttpServletResponse _response;
119     private String _rootPath = StringPool.BLANK;
120     private User _user;
121     private byte[] _bytes;
122     private Map<String, String[]> _params = new HashMap<String, String[]>();
123 
124 }