001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.fileupload;
018    
019    import java.util.Enumeration;
020    import java.util.Hashtable;
021    import javax.portlet.PortletContext;
022    import javax.portlet.PortletSession;
023    
024    /**
025     * A mock portlet session, useful for unit testing and offline utilities
026     * Note: currently doesn't support scoping
027     * 
028     * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
029     * @version $Id: MockPortletSession.java 479262 2006-11-26 03:09:24Z niallp $
030     */
031    public class MockPortletSession implements PortletSession
032    {
033        // Hashtable (not HashMap) makes enumerations easier to work with
034        Hashtable attributes = new Hashtable();
035    
036        public MockPortletSession()
037        {     
038        }
039        
040        
041        /* (non-Javadoc)
042         * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
043         */
044        public Object getAttribute(String name)
045        {
046            return attributes.get(name);
047        }
048        
049        /* (non-Javadoc)
050         * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
051         */
052        public Object getAttribute(String name, int scope)
053        {
054            return attributes.get(name);
055        }
056        
057        /* (non-Javadoc)
058         * @see javax.portlet.PortletSession#getAttributeNames(int)
059         */
060        public Enumeration getAttributeNames(int scope)
061        {
062            return attributes.keys();
063        }
064        
065        /* (non-Javadoc)
066         * @see javax.portlet.PortletSession#getCreationTime()
067         */
068        public long getCreationTime()
069        {
070            // TODO Auto-generated method stub
071            return 0;
072        }
073        
074        /* (non-Javadoc)
075         * @see javax.portlet.PortletSession#getId()
076         */
077        public String getId()
078        {
079            // TODO Auto-generated method stub
080            return null;
081        }
082        
083        /* (non-Javadoc)
084         * @see javax.portlet.PortletSession#getLastAccessedTime()
085         */
086        public long getLastAccessedTime()
087        {
088            // TODO Auto-generated method stub
089            return 0;
090        }
091        
092        /* (non-Javadoc)
093         * @see javax.portlet.PortletSession#getMaxInactiveInterval()
094         */
095        public int getMaxInactiveInterval()
096        {
097            // TODO Auto-generated method stub
098            return 0;
099        }
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    }