1   /*
2    * Copyright 2000-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.apache.commons.fileupload;
17  
18  import java.util.Enumeration;
19  import java.util.Hashtable;
20  import javax.portlet.PortletContext;
21  import javax.portlet.PortletSession;
22  
23  /***
24   * A mock portlet session, useful for unit testing and offline utilities
25   * Note: currently doesn't support scoping
26   * 
27   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
28   * @version $Id: MockPortletSession.java 155417 2005-02-26 13:00:27Z dirkv $
29   */
30  public class MockPortletSession implements PortletSession
31  {
32      // Hashtable (not HashMap) makes enumerations easier to work with
33      Hashtable attributes = new Hashtable();
34  
35      public MockPortletSession()
36      {     
37      }
38      
39      
40      /* (non-Javadoc)
41       * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
42       */
43      public Object getAttribute(String name)
44      {
45          return attributes.get(name);
46      }
47      
48      /* (non-Javadoc)
49       * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
50       */
51      public Object getAttribute(String name, int scope)
52      {
53          return attributes.get(name);
54      }
55      
56      /* (non-Javadoc)
57       * @see javax.portlet.PortletSession#getAttributeNames(int)
58       */
59      public Enumeration getAttributeNames(int scope)
60      {
61          return attributes.keys();
62      }
63      
64      /* (non-Javadoc)
65       * @see javax.portlet.PortletSession#getCreationTime()
66       */
67      public long getCreationTime()
68      {
69          // TODO Auto-generated method stub
70          return 0;
71      }
72      
73      /* (non-Javadoc)
74       * @see javax.portlet.PortletSession#getId()
75       */
76      public String getId()
77      {
78          // TODO Auto-generated method stub
79          return null;
80      }
81      
82      /* (non-Javadoc)
83       * @see javax.portlet.PortletSession#getLastAccessedTime()
84       */
85      public long getLastAccessedTime()
86      {
87          // TODO Auto-generated method stub
88          return 0;
89      }
90      
91      /* (non-Javadoc)
92       * @see javax.portlet.PortletSession#getMaxInactiveInterval()
93       */
94      public int getMaxInactiveInterval()
95      {
96          // TODO Auto-generated method stub
97          return 0;
98      }
99      
100     /* (non-Javadoc)
101      * @see javax.portlet.PortletSession#invalidate()
102      */
103     public void invalidate()
104     {
105         // TODO Auto-generated method stub
106     }
107     
108     /* (non-Javadoc)
109      * @see javax.portlet.PortletSession#isNew()
110      */
111     public boolean isNew()
112     {
113         // TODO Auto-generated method stub
114         return false;
115     }
116     
117     /* (non-Javadoc)
118      * @see javax.portlet.PortletSession#removeAttribute(java.lang.String)
119      */
120     public void removeAttribute(String name)
121     {
122         attributes.remove(name);
123     }
124     
125     /* (non-Javadoc)
126      * @see javax.portlet.PortletSession#removeAttribute(java.lang.String, int)
127      */
128     public void removeAttribute(String name, int scope)
129     {
130         attributes.remove(name);
131     }
132     
133     /* (non-Javadoc)
134      * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object)
135      */
136     public void setAttribute(String name, Object value)
137     {
138         attributes.put(name, value);
139     }
140 
141     public Enumeration getAttributeNames()
142     {
143         return this.getAttributeNames(PortletSession.PORTLET_SCOPE);
144     }    
145     
146     
147     /* (non-Javadoc)
148      * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object, int)
149      */
150     public void setAttribute(String name, Object value, int scope)
151     {
152         attributes.put(name, value);
153     }
154     
155     /* (non-Javadoc)
156      * @see javax.portlet.PortletSession#setMaxInactiveInterval(int)
157      */
158     public void setMaxInactiveInterval(int interval)
159     {
160         // TODO Auto-generated method stub
161     }
162     /* (non-Javadoc)
163      * @see javax.portlet.PortletSession#getPortletContext()
164      */
165     public PortletContext getPortletContext()
166     {
167         // TODO Auto-generated method stub
168         return null;
169     }
170 }