FileDocCategorySizeDatePackage
PortletRequestMap.javaAPI DocExample5462Mon Jul 23 13:26:40 BST 2007org.apache.struts2.portlet

PortletRequestMap

public class PortletRequestMap extends AbstractMap
A simple implementation of the {@link java.util.Map} interface to handle a collection of request attributes.

Fields Summary
private static final Log
LOG
private Set
entries
private javax.portlet.PortletRequest
request
Constructors Summary
public PortletRequestMap(javax.portlet.PortletRequest request)
Saves the request to use as the backing for getting and setting values

param
request the portlet request.


                           
       
        this.request = request;
        if(LOG.isDebugEnabled()) {
            LOG.debug("Dumping request parameters: ");
            Iterator params = request.getParameterMap().keySet().iterator();
            while(params.hasNext()) {
                String key = (String)params.next();
                String val = request.getParameter(key);
                LOG.debug(key + " = " + val);
            }
        }
    
Methods Summary
public voidclear()
Removes all attributes from the request as well as clears entries in this map.

        entries = null;
        Enumeration keys = request.getAttributeNames();

        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            request.removeAttribute(key);
        }
    
public java.util.SetentrySet()
Returns a Set of attributes from the portlet request.

return
a Set of attributes from the portlet request.

        if (entries == null) {
            entries = new HashSet<Object>();

            Enumeration enumeration = request.getAttributeNames();

            while (enumeration.hasMoreElements()) {
                final String key = enumeration.nextElement().toString();
                final Object value = request.getAttribute(key);
                entries.add(new Entry() {
                    public boolean equals(Object obj) {
                        Entry entry = (Entry) obj;

                        return ((key == null) ? (entry.getKey() == null) : key
                                .equals(entry.getKey()))
                                && ((value == null) ? (entry.getValue() == null)
                                        : value.equals(entry.getValue()));
                    }

                    public int hashCode() {
                        return ((key == null) ? 0 : key.hashCode())
                                ^ ((value == null) ? 0 : value.hashCode());
                    }

                    public Object getKey() {
                        return key;
                    }

                    public Object getValue() {
                        return value;
                    }

                    public Object setValue(Object obj) {
                        request.setAttribute(key, obj);

                        return value;
                    }
                });
            }
        }

        return entries;
    
public java.lang.Objectget(java.lang.Object key)
Returns the request attribute associated with the given key or null if it doesn't exist.

param
key the name of the request attribute.
return
the request attribute or null if it doesn't exist.

        return request.getAttribute(key.toString());
    
public java.lang.Objectput(java.lang.Object key, java.lang.Object value)
Saves an attribute in the request.

param
key the name of the request attribute.
param
value the value to set.
return
the object that was just set.

        entries = null;
        request.setAttribute(key.toString(), value);

        return get(key);
    
public java.lang.Objectremove(java.lang.Object key)
Removes the specified request attribute.

param
key the name of the attribute to remove.
return
the value that was removed or null if the value was not found (and hence, not removed).

        entries = null;

        Object value = get(key);
        request.removeAttribute(key.toString());

        return value;