001: package org.wings.portlet;
002:
003: import java.util.EventObject;
004: import java.util.HashSet;
005: import java.util.Iterator;
006: import java.util.Map;
007: import java.util.Set;
008:
009: /**
010: * Event for portlet parameters, from this event you can get all the parameters
011: * from a PortletURL or a SPortletAnchor, see {@link PortletParameterProvider}
012: *
013: * @author Marc Musch
014: *
015: */
016: public class PortletParameterEvent extends EventObject {
017:
018: private Map<String, String[]> portletParameters;
019:
020: /**
021: * @param source -
022: * the source of the event
023: * @param windowState -
024: * the new window state
025: */
026: public PortletParameterEvent(Object source,
027: Map<String, String[]> portletParameters) {
028: super (source);
029: this .portletParameters = portletParameters;
030:
031: }
032:
033: /**
034: * {@link javax.portlet.PortletRequest#getParameter(String)}
035: *
036: * @param name -
037: * a String specifying the name of the parameter
038: * @return a String representing the single value of the parameter
039: * @throws java.lang.IllegalArgumentException -
040: * if name is null.
041: * @see javax.portlet.PortletRequest#getParameter(String)
042: */
043: public String getParameter(String name) {
044: if (name == null) {
045: throw new IllegalArgumentException(
046: "parameter name must not be null");
047: }
048: if (portletParameters != null
049: && portletParameters.containsKey(name)) {
050: return portletParameters.get(name)[0];
051: }
052: return null;
053: }
054:
055: /**
056: * {@link javax.portlet.PortletRequest#getParameterValues(String)}
057: *
058: * @param name -
059: * a String containing the name of the parameter the value of
060: * which is requested
061: * @return an array of String objects containing the parameter values.
062: * @throws java.lang.IllegalArgumentException -
063: * if name is null.
064: * @see javax.portlet.PortletRequest#getParameterValues(String)
065: */
066: public String[] getParameterValues(String name) {
067: if (name == null) {
068: throw new IllegalArgumentException(
069: "parameter name must not be null");
070: }
071: if (portletParameters != null
072: && portletParameters.containsKey(name)) {
073: String[] values = portletParameters.get(name);
074: return values;
075: }
076: return null;
077: }
078:
079: /**
080: *
081: * {@link javax.portlet.PortletRequest#getParameterNames()}
082: *
083: * @return a Iterator of String objects, each String containing the name of
084: * a request parameter; or an empty Iterator if the request has no
085: * parameters.
086: * @see javax.portlet.PortletRequest#getParameterNames()
087: */
088: public Iterator<String> getParameterNames() {
089: if (portletParameters == null) {
090: return new HashSet<String>().iterator();
091: }
092: Set<String> names = portletParameters.keySet();
093: return names.iterator();
094:
095: }
096:
097: /**
098: *
099: * {@link javax.portlet.PortletRequest#getParameterMap()}
100: *
101: * @return an immutable Map containing parameter names as keys and parameter
102: * values as map values, or an empty Map if no parameters exist. The
103: * keys in the parameter map are of type String. The values in the
104: * parameter map are of type String array (String[]).
105: * @see javax.portlet.PortletRequest#getParameterMap()
106: *
107: */
108: public Map<String, String[]> getParameterMap() {
109: return this.portletParameters;
110: }
111:
112: }
|