KickJava   Java API By Example, From Geeks To Geeks.

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


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.Enumeration JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.util.Properties JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24
25 import javax.portlet.PortletConfig;
26 import javax.portlet.PortletContext;
27
28 import org.springframework.util.Assert;
29
30 /**
31  * Mock implementation of the {@link javax.portlet.PortletConfig} interface.
32  *
33  * @author John A. Lewis
34  * @author Juergen Hoeller
35  * @since 2.0
36  */

37 public class MockPortletConfig implements PortletConfig {
38
39     private final PortletContext portletContext;
40
41     private final String JavaDoc portletName;
42     
43     private final HashMap JavaDoc resourceBundles = new HashMap JavaDoc();
44     
45     private final Properties JavaDoc initParameters = new Properties JavaDoc();
46
47
48     /**
49      * Create new MockPortletConfig with empty String as name.
50      * @param portletContext the PortletContext that the portlet runs in
51      */

52     public MockPortletConfig(PortletContext portletContext) {
53         this(portletContext, "");
54     }
55
56     /**
57      * Create new MockPortletConfig.
58      * @param portletContext the PortletContext that the portlet runs in
59      * @param portletName the name of the portlet
60      */

61     public MockPortletConfig(PortletContext portletContext, String JavaDoc portletName) {
62         this.portletContext = (portletContext != null ? portletContext : new MockPortletContext());
63         this.portletName = portletName;
64     }
65
66     
67     public String JavaDoc getPortletName() {
68         return portletName;
69     }
70     
71     public PortletContext getPortletContext() {
72         return portletContext;
73     }
74     
75     public void setResourceBundle(Locale JavaDoc locale, ResourceBundle JavaDoc resourceBundle) {
76         Assert.notNull(locale, "Locale must not be null");
77         this.resourceBundles.put(locale, resourceBundle);
78     }
79
80     public ResourceBundle JavaDoc getResourceBundle(Locale JavaDoc locale) {
81         Assert.notNull(locale, "Locale must not be null");
82         return (ResourceBundle JavaDoc) this.resourceBundles.get(locale);
83     }
84
85     public void addInitParameter(String JavaDoc name, String JavaDoc value) {
86         Assert.notNull(name, "Parameter name must not be null");
87         this.initParameters.setProperty(name, value);
88     }
89
90     public String JavaDoc getInitParameter(String JavaDoc name) {
91         Assert.notNull(name, "Parameter name must not be null");
92         return this.initParameters.getProperty(name);
93     }
94
95     public Enumeration JavaDoc getInitParameterNames() {
96         return this.initParameters.keys();
97     }
98
99 }
100
Popular Tags