View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.mockobjects.request;
18  
19  import java.security.Principal;
20  import java.util.HashMap;
21  import java.util.Locale;
22  import java.util.Map;
23  
24  import javax.security.auth.Subject;
25  import javax.servlet.ServletConfig;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  import org.apache.jetspeed.aggregator.ContentDispatcher;
30  import org.apache.jetspeed.capabilities.CapabilityMap;
31  import org.apache.jetspeed.container.state.NavigationalState;
32  import org.apache.jetspeed.container.url.PortalURL;
33  import org.apache.jetspeed.mockobjects.MockHttpServletRequest;
34  import org.apache.jetspeed.om.page.ContentPage;
35  import org.apache.jetspeed.pipeline.Pipeline;
36  import org.apache.jetspeed.profiler.Profiler;
37  import org.apache.jetspeed.request.RequestContext;
38  import org.apache.pluto.om.common.Language;
39  import org.apache.pluto.om.common.ObjectID;
40  import org.apache.pluto.om.portlet.PortletDefinition;
41  import org.apache.pluto.om.window.PortletWindow;
42  
43  
44  
45  /***
46   * MockRequestContext
47   * 
48   * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
49   * @version $Id: MockRequestContext.java,v 1.1.2.1 2004/04/20 19:40:40 weaver
50   *          Exp $
51   */
52  public class MockRequestContext implements RequestContext
53  {
54      private Map requestParameters = new HashMap();
55      private Map requestAttributes = new HashMap();
56      private Map sessionAttributes = new HashMap();
57      private String path;
58      private Map locators;
59      private Subject subject;
60      private Locale locale;
61      private String mediaType;
62      private String mimeType;
63      private ContentPage page;
64      private HttpServletRequest request;
65      private HttpServletResponse response;
66      private Object session;
67      private Pipeline pipeline;
68      private Map objects;
69      
70      /* (non-Javadoc)
71       * @see org.apache.jetspeed.request.RequestContext#getUserInfoMap(org.apache.pluto.om.common.ObjectID)
72       */
73      public Map getUserInfoMap( ObjectID oid )
74      {
75          // TODO Auto-generated method stub
76          return null;
77      }
78      public MockRequestContext(HttpServletRequest request, HttpServletResponse response)
79      {
80          this.request = request;
81          this.response = response;
82      }
83  
84      /*
85       * (non-Javadoc)
86       * 
87       * @see org.apache.jetspeed.request.RequestContext#getActionWindow()
88       */
89      public PortletWindow getActionWindow()
90      {
91          // TODO Auto-generated method stub
92          return null;
93      }
94      
95  
96      public MockRequestContext()
97      {
98         //  WebMockObjectFactory mockFactory = new WebMockObjectFactory();
99          this.request = new MockHttpServletRequest();
100        //  this.response = mockFactory.getMockResponse();
101         // this.session = mockFactory.getSession();
102     }
103 
104     public MockRequestContext( String path )
105     {
106         // super(null, null, null, null);
107         this.path = path;
108     }
109 
110     /*
111      * (non-Javadoc)
112      * 
113      * @see org.apache.jetspeed.request.RequestContext#getCapabilityMap()
114      */
115     public CapabilityMap getCapabilityMap()
116     {
117         // TODO Auto-generated method stub
118         return null;
119     }
120 
121     /*
122      * (non-Javadoc)
123      * 
124      * @see org.apache.jetspeed.request.RequestContext#getCharacterEncoding()
125      */
126     public String getCharacterEncoding()
127     {
128         // TODO Auto-generated method stub
129         return null;
130     }
131 
132     /*
133      * (non-Javadoc)
134      * 
135      * @see org.apache.jetspeed.request.RequestContext#getConfig()
136      */
137     public ServletConfig getConfig()
138     {
139         // TODO Auto-generated method stub
140         return null;
141     }
142 
143     /*
144      * (non-Javadoc)
145      * 
146      * @see org.apache.jetspeed.request.RequestContext#getContentDispatcher()
147      */
148     public ContentDispatcher getContentDispatcher()
149     {
150         // TODO Auto-generated method stub
151         return null;
152     }
153 
154     /*
155      * (non-Javadoc)
156      * 
157      * @see org.apache.jetspeed.request.RequestContext#getLocale()
158      */
159     public Locale getLocale()
160     {
161         return this.locale;
162     }
163 
164     /*
165      * (non-Javadoc)
166      * 
167      * @see org.apache.jetspeed.request.RequestContext#getMediaType()
168      */
169     public String getMediaType()
170     {
171         return this.mediaType;
172     }
173 
174     /*
175      * (non-Javadoc)
176      * 
177      * @see org.apache.jetspeed.request.RequestContext#getMimeType()
178      */
179     public String getMimeType()
180     {
181 
182         return this.mimeType;
183     }
184 
185     /*
186      * (non-Javadoc)
187      * 
188      * @see org.apache.jetspeed.request.RequestContext#getNavigationalState()
189      */
190     public NavigationalState getNavigationalState()
191     {
192         // TODO Auto-generated method stub
193         return null;
194     }
195 
196     /*
197      * (non-Javadoc)
198      * 
199      * @see org.apache.jetspeed.request.RequestContext#getPage()
200      */
201     public ContentPage getPage()
202     {
203         // TODO Auto-generated method stub
204         return this.page;
205     }
206 
207     /*
208      * (non-Javadoc)
209      * 
210      * @see org.apache.jetspeed.request.RequestContext#getPortalURL()
211      */
212     public PortalURL getPortalURL()
213     {
214         // TODO Auto-generated method stub
215         return null;
216     }
217 
218     public void setPortalURL(PortalURL url)
219     {        
220     }
221     
222     /*
223      * (non-Javadoc)
224      * 
225      * @see org.apache.jetspeed.request.RequestContext#getProfileLocators()
226      */
227     public Map getProfileLocators()
228     {
229         return locators;
230     }
231 
232     /*
233      * (non-Javadoc)
234      * 
235      * @see org.apache.jetspeed.request.RequestContext#getRequest()
236      */
237     public HttpServletRequest getRequest()
238     {
239         // TODO Auto-generated method stub
240         return this.request;
241     }
242 
243     /*
244      * (non-Javadoc)
245      * 
246      * @see org.apache.jetspeed.request.RequestContext#getRequestForWindow(org.apache.pluto.om.window.PortletWindow)
247      */
248     public HttpServletRequest getRequestForWindow( PortletWindow window )
249     {
250         // TODO Auto-generated method stub
251         return null;
252     }
253 
254     /*
255      * (non-Javadoc)
256      * 
257      * @see org.apache.jetspeed.request.RequestContext#getResponse()
258      */
259     public HttpServletResponse getResponse()
260     {
261         // TODO Auto-generated method stub
262         return null;
263     }
264 
265     /*
266      * (non-Javadoc)
267      * 
268      * @see org.apache.jetspeed.request.RequestContext#getResponseForWindow(org.apache.pluto.om.window.PortletWindow)
269      */
270     public HttpServletResponse getResponseForWindow( PortletWindow window )
271     {
272         // TODO Auto-generated method stub
273         return null;
274     }
275 
276     /*
277      * (non-Javadoc)
278      * 
279      * @see org.apache.jetspeed.request.RequestContext#getSubject()
280      */
281     public Subject getSubject()
282     {
283         return subject;
284     }
285     
286     public Principal getUserPrincipal()
287     {
288         return request.getUserPrincipal();
289     }
290 
291     /*
292      * (non-Javadoc)
293      * 
294      * @see org.apache.jetspeed.request.RequestContext#setActionWindow(org.apache.pluto.om.window.PortletWindow)
295      */
296     public void setActionWindow( PortletWindow window )
297     {
298         // TODO Auto-generated method stub
299 
300     }
301 
302     /*
303      * (non-Javadoc)
304      * 
305      * @see org.apache.jetspeed.request.RequestContext#setCapabilityMap(org.apache.jetspeed.capability.CapabilityMap)
306      */
307     public void setCapabilityMap( CapabilityMap map )
308     {
309         // TODO Auto-generated method stub
310 
311     }
312 
313     /*
314      * (non-Javadoc)
315      * 
316      * @see org.apache.jetspeed.request.RequestContext#setCharacterEncoding(java.lang.String)
317      */
318     public void setCharacterEncoding( String enc )
319     {
320         // TODO Auto-generated method stub
321 
322     }
323 
324     /*
325      * (non-Javadoc)
326      * 
327      * @see org.apache.jetspeed.request.RequestContext#setContentDispatcher(org.apache.jetspeed.aggregator.ContentDispatcher)
328      */
329     public void setContentDispatcher( ContentDispatcher dispatcher )
330     {
331         // TODO Auto-generated method stub
332 
333     }
334 
335     /*
336      * (non-Javadoc)
337      * 
338      * @see org.apache.jetspeed.request.RequestContext#setLocale(java.util.Locale)
339      */
340     public void setLocale( Locale locale )
341     {
342         this.locale = locale;
343 
344     }
345 
346     /*
347      * (non-Javadoc)
348      * 
349      * @see org.apache.jetspeed.request.RequestContext#setMediaType(java.lang.String)
350      */
351     public void setMediaType( String mediaType )
352     {
353         this.mediaType = mediaType;
354 
355     }
356 
357     /*
358      * (non-Javadoc)
359      * 
360      * @see org.apache.jetspeed.request.RequestContext#setMimeType(java.lang.String)
361      */
362     public void setMimeType( String mimeType )
363     {
364        this.mimeType = mimeType;
365 
366     }
367 
368     /*
369      * (non-Javadoc)
370      * 
371      * @see org.apache.jetspeed.request.RequestContext#setPage(org.apache.jetspeed.om.page.Page)
372      */
373     public void setPage( ContentPage page )
374     {
375         this.page = page;
376 
377     }
378 
379     /*
380      * (non-Javadoc)
381      * 
382      * @see org.apache.jetspeed.request.RequestContext#setProfileLocators(java.util.Map)
383      */
384     public void setProfileLocators( Map locators )
385     {
386         this.locators = locators;
387 
388     }
389 
390     /*
391      * (non-Javadoc)
392      * 
393      * @see org.apache.jetspeed.request.RequestContext#setSubject(javax.security.auth.Subject)
394      */
395     public void setSubject( Subject subject )
396     {
397         this.subject = subject;
398 
399     }
400 
401 
402     /*
403      * (non-Javadoc)
404      * 
405      * @see org.apache.jetspeed.request.RequestContext#getRequestParameter(java.lang.String)
406      */
407     public String getRequestParameter( String key )
408     {
409         return (String) requestParameters.get(key);
410     }
411 
412     /*
413      * (non-Javadoc)
414      * 
415      * @see org.apache.jetspeed.request.RequestContext#getParameterMap()
416      */
417     public Map getParameterMap()
418     {
419         return requestParameters;
420     }
421 
422     /*
423      * (non-Javadoc)
424      * 
425      * @see org.apache.jetspeed.request.RequestContext#setSessionAttribute(java.lang.String,
426      *      java.lang.Object)
427      */
428     public void setSessionAttribute( String key, Object value )
429     {
430         this.sessionAttributes.put(key, value);
431     }
432 
433     /*
434      * (non-Javadoc)
435      * 
436      * @see org.apache.jetspeed.request.RequestContext#getSessionAttribute(java.lang.String)
437      */
438     public Object getSessionAttribute( String key )
439     {
440         return this.sessionAttributes.get(key);
441     }
442 
443     /*
444      * (non-Javadoc)
445      * 
446      * @see org.apache.jetspeed.request.RequestContext#setAttribute(java.lang.String,
447      *      java.lang.Object)
448      */
449     public void setAttribute( String key, Object value )
450     {
451         requestAttributes.put(key, value);
452     }
453 
454     /*
455      * (non-Javadoc)
456      * 
457      * @see org.apache.jetspeed.request.RequestContext#getAttribute(java.lang.String)
458      */
459     public Object getAttribute( String key )
460     {
461         return requestAttributes.get(key);
462     }
463 
464     /*
465      * (non-Javadoc)
466      * 
467      * @see org.apache.jetspeed.request.RequestContext#getPath()
468      */
469     public String getPath()
470     {
471         return path;
472     }
473 
474     /***
475      * <p>
476      * getPreferedLanguage
477      * </p>
478      *
479      * @see org.apache.jetspeed.request.RequestContext#getPreferedLanguage(org.apache.pluto.om.portlet.PortletDefinition)
480      * @param portlet
481      * @return
482      */
483     public Language getPreferedLanguage( PortletDefinition portlet )
484     {
485         // TODO Auto-generated method stub
486         return null;
487     }
488     /***
489      * <p>
490      * setPath
491      * </p>
492      *
493      * @see org.apache.jetspeed.request.RequestContext#setPath(java.lang.String)
494      * @param path
495      */
496     public void setPath( String path )
497     {
498         this.path = path;
499     }
500     
501 
502     /* (non-Javadoc)
503      * @see org.apache.jetspeed.request.RequestContext#popActionFailure(org.apache.pluto.om.window.PortletWindow)
504      */
505     public Throwable popActionFailure(PortletWindow window)
506     {
507         // TODO Auto-generated method stub
508         return null;
509     }
510     /* (non-Javadoc)
511      * @see org.apache.jetspeed.request.RequestContext#setActionFailure(org.apache.pluto.om.window.PortletWindow, java.lang.Throwable)
512      */
513     public void setActionFailure(PortletWindow window, Throwable actionFailure)
514     {
515         // TODO Auto-generated method stub
516         
517     }
518 
519     /***
520      * Get the current executing pipeline
521      * 
522      * @return Pipeline
523      */
524     public Pipeline getPipeline()
525     {
526         return pipeline;
527     }
528     
529     
530     /***
531      * Set the current pipeline
532      * @param pipeline
533      */
534     public void setPipeline(Pipeline pipeline)
535     {
536         this.pipeline = pipeline;
537     }
538 
539     /***
540      * @param request The request to set.
541      */
542     public void setRequest(HttpServletRequest request)
543     {
544         this.request = request;
545     }
546     
547     /***
548      * @param response The request to set.
549      */
550     public void setResponse(HttpServletResponse response)
551     {
552         this.response = response;
553     }
554 
555     public ContentPage locatePage(Profiler profiler, String nonProfiledPath)
556     {
557         return null;
558     }
559     
560     public Map getObjects()
561     {
562         return objects;
563     }
564     
565     public void setObjects(Map objects)
566     {
567         this.objects = objects;
568     }
569 }