KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > mocks > jsf > MockExternalContext


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.test.mocks.jsf;
6
7 import java.util.*;
8 import java.io.IOException JavaDoc;
9 import java.io.InputStream JavaDoc;
10 import java.net.MalformedURLException JavaDoc;
11 import java.net.URL JavaDoc;
12 import javax.faces.context.ExternalContext;
13 import javax.servlet.http.*;
14 import org.exoplatform.commons.map.*;
15
16
17 public class MockExternalContext extends ExternalContext {
18 protected HttpServletRequest request_ ;
19   protected HttpServletResponse response_ ;
20   protected Map requestMap_ ;
21   protected Map requestParameterMap_ ;
22   
23   public void init(HttpServletRequest request, HttpServletResponse response) {
24     request_ = request ;
25     response_ = response ;
26     requestMap_ = null ;
27     requestParameterMap_ = null ;
28   }
29
30   public Object JavaDoc getSession( boolean create ) { return request_.getSession(create) ; }
31
32   public Object JavaDoc getContext() { return null ; }
33
34   public Object JavaDoc getRequest() { return request_ ; }
35
36   public Object JavaDoc getResponse() { return response_ ; }
37   
38   public ResourceBundle getApplicationResourceBundle() { return null ; }
39
40   public String JavaDoc getInitParameter( String JavaDoc s ) { return null ; }
41
42   public Map getInitParameterMap() { return null ; }
43
44   public Map getApplicationMap() { return null ; }
45
46   public Map getSessionMap() { return null ; }
47
48   public Map getRequestMap() {
49     if(requestMap_ == null ) requestMap_ = new RequestMap(request_) ;
50     return requestMap_ ;
51   }
52
53   public Map getRequestParameterMap() {
54     if(requestParameterMap_ == null ) requestParameterMap_ = new RequestParameterMap(request_) ;
55     return requestParameterMap_ ;
56   }
57
58   public Map getRequestParameterValuesMap() { return null ; }
59
60   public Iterator getRequestParameterNames() { return null ; }
61
62   public Map getRequestHeaderMap() { return null ; }
63
64   public Map getRequestHeaderValuesMap() { return null ; }
65
66   public Map getRequestCookieMap() { return null ; }
67
68   public Locale getRequestLocale() { return null ; }
69   public Iterator getRequestLocales() { return null ; }
70
71   public String JavaDoc getRequestContextPath() { return null ; }
72
73   public String JavaDoc getRequestPathInfo() { return request_.getRequestURI() ; }
74
75   public Cookie[] getRequestCookies() { return null ; }
76
77   public Set getResourcePaths( String JavaDoc s ) { return null ; }
78   public InputStream JavaDoc getResourceAsStream( String JavaDoc s ) { return null ; }
79   
80   public URL JavaDoc getResource( String JavaDoc s ) throws MalformedURLException JavaDoc {
81     return null ;
82   }
83
84   public String JavaDoc encodeActionURL( String JavaDoc s ) { return s ; }
85
86   public String JavaDoc encodeResourceURL( String JavaDoc s ) { return s; }
87
88   public String JavaDoc encodeURL( String JavaDoc s ) { return s ; }
89
90   public String JavaDoc encodeNamespace( String JavaDoc s ) { return s; }
91
92   public void dispatch( String JavaDoc requestURI ) throws IOException JavaDoc {
93   }
94
95   public void redirect( String JavaDoc sI ) throws IOException JavaDoc {
96   }
97   
98   public void log(String JavaDoc message) {
99     System.out.println(message);
100   }
101   
102   public void log(String JavaDoc message, Throwable JavaDoc throwable) {
103     System.out.println(message);
104     throwable.printStackTrace() ;
105   }
106   
107   public String JavaDoc getRequestServletPath() {
108     throw new UnsupportedOperationException JavaDoc();
109   }
110   
111   public java.lang.String JavaDoc getAuthType() { return null ; }
112   
113   public java.lang.String JavaDoc getRemoteUser() { return "anonymous" ; }
114   
115   final public java.security.Principal JavaDoc getUserPrincipal() { return null ; }
116
117   final public boolean isUserInRole(java.lang.String JavaDoc role) { return false ; }
118   
119   public void reset() {
120   }
121 }
122
Popular Tags