You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2017/09/20 22:22:09 UTC

[myfaces-tobago] 04/04: TOBAGO-1782: Clean up * removing dependency to commons-beanutils

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit f7d01d768853b31b0015b4ac60923160b21030b7
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Thu Sep 21 00:21:56 2017 +0200

    TOBAGO-1782: Clean up
    * removing dependency to commons-beanutils
---
 pom.xml                                            |  4 +++
 tobago-core/pom.xml                                |  1 +
 .../myfaces/tobago/facelets/AttributeHandler.java  |  9 ++----
 .../myfaces/tobago/internal/util/PartUtils.java    | 36 ++++++++++++++++++++--
 .../apache/myfaces/tobago/util/BeanComparator.java | 14 ++++-----
 .../tobago/util/ValueExpressionComparator.java     |  3 ++
 6 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/pom.xml b/pom.xml
index da02063..5e1c964 100644
--- a/pom.xml
+++ b/pom.xml
@@ -966,6 +966,10 @@
           <artifactId>animal-sniffer-maven-plugin</artifactId>
           <version>1.14</version>
         </plugin>
+        <!--
+        usage: $ mvn versions:display-dependency-updates
+        usage: $ mvn versions:display-plugin-updates
+        -->
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>versions-maven-plugin</artifactId>
diff --git a/tobago-core/pom.xml b/tobago-core/pom.xml
index c019dd9..25cf576 100644
--- a/tobago-core/pom.xml
+++ b/tobago-core/pom.xml
@@ -155,6 +155,7 @@
     <dependency>
       <groupId>commons-beanutils</groupId>
       <artifactId>commons-beanutils</artifactId>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.myfaces.tobago</groupId>
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
index 36c408c..1efa65a 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
@@ -25,6 +25,8 @@ import org.apache.myfaces.tobago.context.Markup;
 import org.apache.myfaces.tobago.el.ConstantMethodExpression;
 import org.apache.myfaces.tobago.internal.util.StringUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.el.ELException;
 import javax.el.ExpressionFactory;
@@ -49,10 +51,6 @@ import javax.faces.view.facelets.TagHandler;
 import java.beans.IntrospectionException;
 import java.beans.PropertyDescriptor;
 
-import org.apache.commons.beanutils.PropertyUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 public final class AttributeHandler extends TagHandler {
 
   private static final Logger LOG = LoggerFactory.getLogger(AttributeHandler.class);
@@ -317,8 +315,7 @@ public final class AttributeHandler extends TagHandler {
       final String attributeName) {
     Class type = Object.class;
     try {
-      type = PropertyUtils.getReadMethod(
-          new PropertyDescriptor(attributeName, parent.getClass())).getReturnType();
+      type = new PropertyDescriptor(attributeName, parent.getClass()).getReadMethod().getReturnType();
     } catch (final IntrospectionException e) {
       LOG.warn("Can't determine expected type", e);
     }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/PartUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/PartUtils.java
index f397262..51a8a41 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/PartUtils.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/PartUtils.java
@@ -19,21 +19,46 @@
 
 package org.apache.myfaces.tobago.internal.util;
 
-import org.apache.commons.beanutils.PropertyUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.servlet.http.Part;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 
 /**
  * Only needed for Servlet 3.0. Not needed for Servlet 3.1 or higher.
- *
+ * <p>
  * Basically taken from Apache Tomcat 8
  */
 public final class PartUtils {
 
+  private static final Logger LOG = LoggerFactory.getLogger(PartUtils.class);
+
+  private static final Method submittedFileNameMethod = findSubmittedFileNameMethod();
+
   private PartUtils() {
+    // to prevent instantiation
+  }
+
+  private static Method findSubmittedFileNameMethod() {
+    try { // try to call the Servlet 3.1 function
+      for (final PropertyDescriptor pd : Introspector.getBeanInfo(Part.class).getPropertyDescriptors()) {
+        if ("submittedFileName".equals(pd.getName())) {
+          final Method readMethod = pd.getReadMethod();
+          if (readMethod != null) {
+            return readMethod;
+          }
+        }
+      }
+    } catch (Exception e) {
+      // ignore
+    }
+    return null;
   }
 
   /**
@@ -45,7 +70,11 @@ public final class PartUtils {
   public static String getSubmittedFileName(Part part) {
 
     try { // try to call the Servlet 3.1 function
-      return (String) PropertyUtils.getProperty(part, "submittedFileName");
+      if (submittedFileNameMethod != null) {
+        final String fileName = (String) submittedFileNameMethod.invoke(part);
+        LOG.debug("Upload file name = '{}'", fileName);
+        return fileName;
+      }
     } catch (Exception e) {
       // ignore
     }
@@ -75,6 +104,7 @@ public final class PartUtils {
         }
       }
     }
+    LOG.debug("Upload file name = '{}'", fileName);
     return fileName;
   }
 
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/BeanComparator.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/BeanComparator.java
index 284c51b..98b07cd 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/BeanComparator.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/BeanComparator.java
@@ -19,12 +19,12 @@
 
 package org.apache.myfaces.tobago.util;
 
-import org.apache.commons.beanutils.PropertyUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Comparator;
+import java.beans.PropertyDescriptor;
 import java.io.Serializable;
+import java.util.Comparator;
 
 public class BeanComparator extends ComparatorBase implements Serializable {
 
@@ -34,15 +34,18 @@ public class BeanComparator extends ComparatorBase implements Serializable {
 
   private String property;
 
+  @Deprecated
   public BeanComparator(final String property) {
     this.property = property;
   }
 
+  @Deprecated
   public BeanComparator(final String property, final boolean reverse) {
     super(reverse);
     this.property = property;
   }
 
+  @Deprecated
   public BeanComparator(final String property, final Comparator comparator) {
     super(comparator);
     this.property = property;
@@ -71,16 +74,13 @@ public class BeanComparator extends ComparatorBase implements Serializable {
     return result;
   }
 
-  // implementation of java.util.Comparator interface
-
   @Override
   public int compare(final Object param1, final Object param2) {
     final Object obj1;
     final Object obj2;
     try {
-      obj1 = PropertyUtils.getProperty(param1, property);
-      obj2 = PropertyUtils.getProperty(param2, property);
-
+      obj1 = new PropertyDescriptor(property, param1.getClass()).getReadMethod().invoke(param1);
+      obj2 = new PropertyDescriptor(property, param1.getClass()).getReadMethod().invoke(param2);
     } catch (final Exception e) {
       LOG.error(e.getMessage(), e);
       return 0;
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ValueExpressionComparator.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ValueExpressionComparator.java
index 68a7bf0..5f44e0a 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ValueExpressionComparator.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/util/ValueExpressionComparator.java
@@ -37,6 +37,7 @@ public class ValueExpressionComparator extends ComparatorBase {
 
   private ValueExpression valueExpression;
 
+  @Deprecated
   public ValueExpressionComparator(
       final FacesContext facesContext, final String var, final ValueExpression valueExpression) {
     this.facesContext = facesContext;
@@ -44,6 +45,7 @@ public class ValueExpressionComparator extends ComparatorBase {
     this.valueExpression = valueExpression;
   }
 
+  @Deprecated
   public ValueExpressionComparator(
       final FacesContext facesContext, final String var, final ValueExpression valueExpression,
       final boolean reverse) {
@@ -53,6 +55,7 @@ public class ValueExpressionComparator extends ComparatorBase {
     this.valueExpression = valueExpression;
   }
 
+  @Deprecated
   public ValueExpressionComparator(
       final FacesContext facesContext, final String var,
       final ValueExpression valueExpression, final Comparator comparator) {

-- 
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.