1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
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  package org.portletbridge.mock;
17  
18  import java.io.IOException;
19  import java.util.Enumeration;
20  import java.util.Hashtable;
21  import java.util.Map;
22  
23  import javax.portlet.PortletPreferences;
24  import javax.portlet.ReadOnlyException;
25  import javax.portlet.ValidatorException;
26  
27  /***
28   * @author jmccrindle
29   */
30  public class MockPortletPreferences implements PortletPreferences {
31  
32      private Hashtable preferences = new Hashtable();
33      
34      /***
35       * 
36       */
37      public MockPortletPreferences() {
38          super();
39      }
40  
41      /* (non-Javadoc)
42       * @see javax.portlet.PortletPreferences#isReadOnly(java.lang.String)
43       */
44      public boolean isReadOnly(String arg0) {
45          // TODO Auto-generated method stub
46          return false;
47      }
48  
49      /* (non-Javadoc)
50       * @see javax.portlet.PortletPreferences#getValue(java.lang.String, java.lang.String)
51       */
52      public String getValue(String name, String defaultValue) {
53          String[] values = getValues(name, null);
54          if(values == null ||  values.length == 0) {
55              return defaultValue;
56          }
57          return values[0];
58      }
59  
60      /* (non-Javadoc)
61       * @see javax.portlet.PortletPreferences#getValues(java.lang.String, java.lang.String[])
62       */
63      public String[] getValues(String name, String[] defaultValue) {
64          String[] values = (String[]) preferences.get(name);
65          if(values == null) {
66              return defaultValue;
67          }
68          return values;
69      }
70  
71      /* (non-Javadoc)
72       * @see javax.portlet.PortletPreferences#setValue(java.lang.String, java.lang.String)
73       */
74      public void setValue(String name, String value) throws ReadOnlyException {
75          preferences.put(name, new String[] {value});
76      }
77  
78      /* (non-Javadoc)
79       * @see javax.portlet.PortletPreferences#setValues(java.lang.String, java.lang.String[])
80       */
81      public void setValues(String name, String[] value) throws ReadOnlyException {
82          preferences.put(name, value);
83      }
84  
85      /* (non-Javadoc)
86       * @see javax.portlet.PortletPreferences#getNames()
87       */
88      public Enumeration getNames() {
89          return preferences.keys();
90      }
91  
92      /* (non-Javadoc)
93       * @see javax.portlet.PortletPreferences#getMap()
94       */
95      public Map getMap() {
96          return preferences;
97      }
98  
99      /* (non-Javadoc)
100      * @see javax.portlet.PortletPreferences#reset(java.lang.String)
101      */
102     public void reset(String name) throws ReadOnlyException {
103         // TODO Auto-generated method stub
104         
105     }
106 
107     /* (non-Javadoc)
108      * @see javax.portlet.PortletPreferences#store()
109      */
110     public void store() throws IOException, ValidatorException {
111         // TODO Auto-generated method stub
112         
113     }
114 
115 }