KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > portlet > MockPortletResponse


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.mock.web.portlet;
18
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import javax.portlet.PortalContext;
23 import javax.portlet.PortletResponse;
24
25 import org.springframework.core.CollectionFactory;
26 import org.springframework.util.Assert;
27
28 /**
29  * Mock implementation of the {@link javax.portlet.PortletResponse} interface.
30  *
31  * @author John A. Lewis
32  * @author Juergen Hoeller
33  * @since 2.0
34  */

35 public class MockPortletResponse implements PortletResponse {
36
37     private final PortalContext portalContext;
38
39     private final Map JavaDoc properties = CollectionFactory.createLinkedMapIfPossible(16);
40
41
42     /**
43      * Create a new MockPortletResponse with a default {@link MockPortalContext}.
44      * @see MockPortalContext
45      */

46     public MockPortletResponse() {
47         this(null);
48     }
49
50     /**
51      * Create a new MockPortletResponse.
52      * @param portalContext the PortalContext defining the supported
53      * PortletModes and WindowStates
54      */

55     public MockPortletResponse(PortalContext portalContext) {
56         this.portalContext = (portalContext != null ? portalContext : new MockPortalContext());
57     }
58
59     /**
60      * Return the PortalContext that this MockPortletResponse runs in,
61      * defining the supported PortletModes and WindowStates.
62      */

63     public PortalContext getPortalContext() {
64         return portalContext;
65     }
66
67
68     //---------------------------------------------------------------------
69
// PortletResponse methods
70
//---------------------------------------------------------------------
71

72     public void addProperty(String JavaDoc key, String JavaDoc value) {
73         Assert.notNull(key, "Property key must not be null");
74         String JavaDoc[] oldArr = (String JavaDoc[]) this.properties.get(key);
75         if (oldArr != null) {
76             String JavaDoc[] newArr = new String JavaDoc[oldArr.length + 1];
77             System.arraycopy(oldArr, 0, newArr, 0, oldArr.length);
78             newArr[oldArr.length] = value;
79             this.properties.put(key, newArr);
80         }
81         else {
82             this.properties.put(key, new String JavaDoc[] {value});
83         }
84     }
85
86     public void setProperty(String JavaDoc key, String JavaDoc value) {
87         Assert.notNull(key, "Property key must not be null");
88         this.properties.put(key, new String JavaDoc[] {value});
89     }
90
91     public Set JavaDoc getPropertyNames() {
92         return this.properties.keySet();
93     }
94
95     public String JavaDoc getProperty(String JavaDoc key) {
96         Assert.notNull(key, "Property key must not be null");
97         String JavaDoc[] arr = (String JavaDoc[]) this.properties.get(key);
98         return (arr != null && arr.length > 0 ? arr[0] : null);
99     }
100
101     public String JavaDoc[] getProperties(String JavaDoc key) {
102         Assert.notNull(key, "Property key must not be null");
103         return (String JavaDoc[]) this.properties.get(key);
104     }
105
106     public String JavaDoc encodeURL(String JavaDoc path) {
107         return path;
108     }
109
110 }
111
Popular Tags