1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.fileupload;
18
19 import java.util.Enumeration;
20 import java.util.Hashtable;
21 import javax.portlet.PortletContext;
22 import javax.portlet.PortletSession;
23
24 /**
25 * A mock portlet session, useful for unit testing and offline utilities
26 * Note: currently doesn't support scoping
27 *
28 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
29 * @version $Id: MockPortletSession.java 479262 2006-11-26 03:09:24Z niallp $
30 */
31 public class MockPortletSession implements PortletSession
32 {
33 // Hashtable (not HashMap) makes enumerations easier to work with
34 Hashtable attributes = new Hashtable();
35
36 public MockPortletSession()
37 {
38 }
39
40
41 /* (non-Javadoc)
42 * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
43 */
44 public Object getAttribute(String name)
45 {
46 return attributes.get(name);
47 }
48
49 /* (non-Javadoc)
50 * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
51 */
52 public Object getAttribute(String name, int scope)
53 {
54 return attributes.get(name);
55 }
56
57 /* (non-Javadoc)
58 * @see javax.portlet.PortletSession#getAttributeNames(int)
59 */
60 public Enumeration getAttributeNames(int scope)
61 {
62 return attributes.keys();
63 }
64
65 /* (non-Javadoc)
66 * @see javax.portlet.PortletSession#getCreationTime()
67 */
68 public long getCreationTime()
69 {
70 // TODO Auto-generated method stub
71 return 0;
72 }
73
74 /* (non-Javadoc)
75 * @see javax.portlet.PortletSession#getId()
76 */
77 public String getId()
78 {
79 // TODO Auto-generated method stub
80 return null;
81 }
82
83 /* (non-Javadoc)
84 * @see javax.portlet.PortletSession#getLastAccessedTime()
85 */
86 public long getLastAccessedTime()
87 {
88 // TODO Auto-generated method stub
89 return 0;
90 }
91
92 /* (non-Javadoc)
93 * @see javax.portlet.PortletSession#getMaxInactiveInterval()
94 */
95 public int getMaxInactiveInterval()
96 {
97 // TODO Auto-generated method stub
98 return 0;
99 }
100
101 /* (non-Javadoc)
102 * @see javax.portlet.PortletSession#invalidate()
103 */
104 public void invalidate()
105 {
106 // TODO Auto-generated method stub
107 }
108
109 /* (non-Javadoc)
110 * @see javax.portlet.PortletSession#isNew()
111 */
112 public boolean isNew()
113 {
114 // TODO Auto-generated method stub
115 return false;
116 }
117
118 /* (non-Javadoc)
119 * @see javax.portlet.PortletSession#removeAttribute(java.lang.String)
120 */
121 public void removeAttribute(String name)
122 {
123 attributes.remove(name);
124 }
125
126 /* (non-Javadoc)
127 * @see javax.portlet.PortletSession#removeAttribute(java.lang.String, int)
128 */
129 public void removeAttribute(String name, int scope)
130 {
131 attributes.remove(name);
132 }
133
134 /* (non-Javadoc)
135 * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object)
136 */
137 public void setAttribute(String name, Object value)
138 {
139 attributes.put(name, value);
140 }
141
142 public Enumeration getAttributeNames()
143 {
144 return this.getAttributeNames(PortletSession.PORTLET_SCOPE);
145 }
146
147
148 /* (non-Javadoc)
149 * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object, int)
150 */
151 public void setAttribute(String name, Object value, int scope)
152 {
153 attributes.put(name, value);
154 }
155
156 /* (non-Javadoc)
157 * @see javax.portlet.PortletSession#setMaxInactiveInterval(int)
158 */
159 public void setMaxInactiveInterval(int interval)
160 {
161 // TODO Auto-generated method stub
162 }
163 /* (non-Javadoc)
164 * @see javax.portlet.PortletSession#getPortletContext()
165 */
166 public PortletContext getPortletContext()
167 {
168 // TODO Auto-generated method stub
169 return null;
170 }
171 }