KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > mocks > portlet > MockPortletExternalContext


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.portlet;
6
7 import java.util.ResourceBundle JavaDoc;
8
9 import javax.portlet.* ;
10 import javax.servlet.http.*;
11 import org.apache.commons.lang.StringUtils;
12 import org.exoplatform.faces.context.*;
13 import org.exoplatform.test.mocks.jsf.*;
14
15 /**
16  * Apr 25, 2004
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $Id: MockPortletExternalContext.java,v 1.1 2004/10/11 23:27:26 tuan08 Exp $
20  **/

21 public class MockPortletExternalContext
22   extends MockExternalContext implements PortletExternalContext {
23   private MockPortletConfig portletConfig_ ;
24   private MockPortletContext portletContext_ ;
25   private MockPortletRequest portletRequest_ ;
26     
27   public MockPortletExternalContext() {
28     portletContext_ = new MockPortletContext() ;
29     portletConfig_ = new MockPortletConfig(portletContext_) ;
30     portletRequest_ = new MockPortletRequest() ;
31   }
32   
33   public void init(HttpServletRequest request, HttpServletResponse response) {
34     super.init(request, response) ;
35   }
36   
37   public PortletPreferences getPortletPreferences() {
38     return portletRequest_.getPreferences() ;
39   }
40   
41   public Object JavaDoc getRequest() { return portletRequest_ ; }
42   
43   public MockPortletConfig getMockPortletConfig() {
44     return portletConfig_ ;
45   }
46   
47   public MockPortletContext getMockPortletContext() {
48     return portletContext_ ;
49   }
50   
51   public String JavaDoc encodeActionURL( String JavaDoc s ) {
52     if (s == null || s.length() == 0) {
53       s = request_.getRequestURI() ;
54       if(s.indexOf("?") < 0) s += "?junk=junk" ;
55         return s ;
56     }else if ("http://".startsWith(s)) {
57       return s ;
58     } else {
59         String JavaDoc baseURL = request_.getRequestURI() ;
60       //s = StringUtils.replace(s, "&", "?" , 1) ;
61
return baseURL + "?viewId=" + s ;
62     }
63   }
64   
65   public PortletConfig getConfig() { return portletConfig_ ; }
66   public ResourceBundle JavaDoc getApplicationResourceBundle() { return null ; }
67 }
Popular Tags