Return-Path: X-Original-To: apmail-myfaces-commits-archive@www.apache.org Delivered-To: apmail-myfaces-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8041E104BD for ; Wed, 8 May 2013 17:36:09 +0000 (UTC) Received: (qmail 82565 invoked by uid 500); 8 May 2013 17:36:09 -0000 Delivered-To: apmail-myfaces-commits-archive@myfaces.apache.org Received: (qmail 82499 invoked by uid 500); 8 May 2013 17:36:09 -0000 Mailing-List: contact commits-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list commits@myfaces.apache.org Received: (qmail 82492 invoked by uid 99); 8 May 2013 17:36:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 May 2013 17:36:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 May 2013 17:36:08 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id EC68323888EA; Wed, 8 May 2013 17:35:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1480373 - /myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/BridgeEventRequestWrapper.java Date: Wed, 08 May 2013 17:35:47 -0000 To: commits@myfaces.apache.org From: mfreedman@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130508173547.EC68323888EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mfreedman Date: Wed May 8 17:35:47 2013 New Revision: 1480373 URL: http://svn.apache.org/r1480373 Log: Added file I originally forgot/missed when I created the project. Added: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/BridgeEventRequestWrapper.java Added: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/BridgeEventRequestWrapper.java URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/BridgeEventRequestWrapper.java?rev=1480373&view=auto ============================================================================== --- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/BridgeEventRequestWrapper.java (added) +++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/BridgeEventRequestWrapper.java Wed May 8 17:35:47 2013 @@ -0,0 +1,200 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.myfaces.portlet.faces.bridge.wrapper; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.LinkedHashMap; +import java.util.Map; + +import javax.portlet.EventRequest; +import javax.portlet.PortletRequest; +import javax.portlet.RenderRequest; +import javax.portlet.filter.EventRequestWrapper; +import javax.portlet.filter.RenderRequestWrapper; + +public class BridgeEventRequestWrapper extends EventRequestWrapper +{ + private Map mActionParams = null; + private Map mCombinedParamMap = null; + private boolean mCombineParams = true; + + public BridgeEventRequestWrapper(EventRequest request, + Map actionParams) + throws IllegalArgumentException + { + this(request, actionParams, true); + } + + public BridgeEventRequestWrapper(EventRequest request, + Map actionParams, + boolean combineParams) + throws IllegalArgumentException + { + super(request); + + mActionParams = actionParams; + mCombineParams = combineParams; + } + + /** + * Returns the value of a request parameter as a String, or null if + * the parameter does not exist. Request parameters are extra information sent with the request. + * The returned parameter are "x-www-form-urlencoded" decoded. + *

+ * Only parameters targeted to the current portlet are accessible. + *

+ * This method should only be used if the parameter has only one value. If the parameter might + * have more than one value, use {@link #getParameterValues}. + *

+ * If this method is used with a multivalued parameter, the value returned is equal to the first + * value in the array returned by getParameterValues. + * + * + * + * @param name + * a String specifying the name of the parameter + * + * @return a String representing the single value of the parameter + * + * @see #getParameterValues + * + * @exception java.lang.IllegalArgumentException + * if name is null. + * + */ + @Override + public String getParameter(String name) + { + String[] params = getParameterValues(name); + if (params != null && params.length > 0) + { + return params[0]; + } + else + { + return null; + } + } + + /** + * + * Returns an Enumeration of String objects containing the names of + * the parameters contained in this request. If the request has no parameters, the method returns + * an empty Enumeration. + *

+ * Only parameters targeted to the current portlet are returned. + * + * + * @return an Enumeration of String objects, each + * String containing the name of a request parameter; or an empty + * Enumeration if the request has no parameters. + */ + @Override + public Enumeration getParameterNames() + { + return Collections.enumeration(getParameterMap().keySet()); + } + + /** + * Returns an array of String objects containing all of the values the given + * request parameter has, or null if the parameter does not exist. The returned + * parameters are "x-www-form-urlencoded" decoded. + *

+ * If the parameter has a single value, the array has a length of 1. + * + * + * @param name + * a String containing the name of the parameter the value of which is + * requested + * + * @return an array of String objects containing the parameter values. + * + * @see #getParameter + * + * @exception java.lang.IllegalArgumentException + * if name is null. + * + */ + @Override + public String[] getParameterValues(String name) + { + if (name == null) + { + throw new IllegalArgumentException(); + } + + return getParameterMap().get(name); + + } + + /** + * Returns a Map of the parameters of this request. Request parameters are extra + * information sent with the request. The returned parameters are "x-www-form-urlencoded" decoded. + *

+ * The values in the returned Map are from type String array (String[]). + *

+ * If no parameters exist this method returns an empty Map. + * + * @return an immutable Map containing parameter names as keys and parameter values + * as map values, or an empty Map if no parameters exist. The keys in the + * parameter map are of type String. The values in the parameter map are of type String + * array (String[]). + */ + @SuppressWarnings("unchecked") + @Override + public Map getParameterMap() + { + if (!mCombineParams) + { + return mActionParams; + } + else if (mActionParams == null || mActionParams.isEmpty()) + { + return super.getParameterMap(); + } + else if (mCombinedParamMap != null) + { + return mCombinedParamMap; + } + else + { + // Combine the two Maps + mCombinedParamMap = new LinkedHashMap(super.getParameterMap()); + + // now walk through the actionParams adding those that aren't + // already in the ParameterMap + for (Map.Entry entry : mActionParams.entrySet()) + { + String key = entry.getKey(); + if (!mCombinedParamMap.containsKey(key)) + { + mCombinedParamMap.put(key, entry.getValue()); + } + } + + // now make this an immutable Map + mCombinedParamMap = Collections.unmodifiableMap(mCombinedParamMap); + + return mCombinedParamMap; + } + } + +}