Skip to content
Permalink
Browse files

Improved: Use ‘HttpServletRequest#getParameterMap’ when possible

It is better to avoid using obsolete ‘Enumeration’ class when possible
so the calls to ‘HttpServletRequest#getParameterNames’ has been
replaced by ‘HttpServletRequest#getParameterMap’.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863404 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 19, 2019
1 parent 37b6edb commit e1d132a6b2fab9b356c05351ac87fcad56d1a900
@@ -22,7 +22,6 @@
import java.math.MathContext;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -311,13 +310,11 @@ public static String addToCart(HttpServletRequest request, HttpServletResponse r
if ("VV_FEATURETREE".equals(ProductWorker.getProductVirtualVariantMethod(delegator, productId))) {
// get the selected features.
List<String> selectedFeatures = new LinkedList<>();
Enumeration<String> paramNames = UtilGenerics.cast(request.getParameterNames());
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
if (paramName.startsWith("FT")) {
selectedFeatures.add(request.getParameterValues(paramName)[0]);
request.getParameterMap().forEach((name, values) -> {
if (name.startsWith("FT")) {
selectedFeatures.add(values[0]);
}
}
});

// check if features are selected
if (UtilValidate.isEmpty(selectedFeatures)) {
@@ -18,7 +18,6 @@
*******************************************************************************/
package org.apache.ofbiz.product.config;

import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
@@ -27,7 +26,6 @@
import javax.servlet.http.HttpServletRequest;

import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilHttp;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
@@ -151,13 +149,12 @@ public static void fillProductConfigWrapper(ProductConfigWrapper configWrapper,
if ("VV_FEATURETREE".equals(ProductWorker.getProductVirtualVariantMethod((Delegator)request.getAttribute("delegator"), selectedProductId))) {
// get the selected features
List<String> selectedFeatures = new LinkedList<>();
Enumeration<String> paramNames = UtilGenerics.cast(request.getParameterNames());
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
if (paramName.startsWith("FT" + k + "_" + cnt + "_" + variantIndex)) {
selectedFeatures.add(request.getParameterValues(paramName)[0]);
String prefix = "FT" + k + "_" + cnt + "_" + variantIndex;
request.getParameterMap().forEach((name, values) -> {
if (name.startsWith(prefix)) {
selectedFeatures.add(values[0]);
}
}
});

// check if features are selected
if (UtilValidate.isEmpty(selectedFeatures)) {
@@ -361,11 +361,9 @@ protected void logRequestInfo(HttpServletRequest request) {
if (Debug.verboseOn()) Debug.logVerbose("--- End Request Headers: ---", module);

if (Debug.verboseOn()) Debug.logVerbose("--- Start Request Parameters: ---", module);
Enumeration<String> paramNames = UtilGenerics.cast(request.getParameterNames());
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
Debug.logVerbose(paramName + ":" + request.getParameter(paramName), module);
}
request.getParameterMap().forEach((name, values) -> {
Debug.logVerbose(name + ":" + values, module);
});
if (Debug.verboseOn()) Debug.logVerbose("--- End Request Parameters: ---", module);

if (Debug.verboseOn()) Debug.logVerbose("--- Start Request Attributes: ---", module);

0 comments on commit e1d132a

Please sign in to comment.
You can’t perform that action at this time.