bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject [35/51] [abbrv] bval git commit: permit quoted path keys without commons-lang3; bypass escape translation only
Date Fri, 03 Nov 2017 22:28:00 GMT
permit quoted path keys without commons-lang3; bypass escape translation only


Project: http://git-wip-us.apache.org/repos/asf/bval/repo
Commit: http://git-wip-us.apache.org/repos/asf/bval/commit/0356c9d3
Tree: http://git-wip-us.apache.org/repos/asf/bval/tree/0356c9d3
Diff: http://git-wip-us.apache.org/repos/asf/bval/diff/0356c9d3

Branch: refs/heads/master
Commit: 0356c9d349fd76b43fcd9d4ba164327d387d4934
Parents: 8d2d29a
Author: Matt Benson <mbenson@apache.org>
Authored: Tue Oct 25 18:44:34 2016 +0000
Committer: Matt Benson <mbenson@apache.org>
Committed: Tue Oct 25 18:44:34 2016 +0000

----------------------------------------------------------------------
 .../apache/bval/jsr/util/PathNavigation.java    | 42 ++++++++++++++------
 1 file changed, 30 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bval/blob/0356c9d3/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
----------------------------------------------------------------------
diff --git a/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java b/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
index 5a657fe..1641150 100644
--- a/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
+++ b/bval-jsr/src/main/java/org/apache/bval/jsr/util/PathNavigation.java
@@ -17,8 +17,12 @@
 package org.apache.bval.jsr.util;
 
 import javax.validation.ValidationException;
+
+import org.apache.commons.lang3.StringEscapeUtils;
+
 import java.io.StringWriter;
 import java.text.ParsePosition;
+import java.util.logging.Logger;
 
 /**
  * Defines a path navigation algorithm and a means of interacting with same.
@@ -79,6 +83,20 @@ public class PathNavigation {
         }
     }
 
+    private static final Logger LOG = Logger.getLogger(PathNavigation.class.getName());
+
+    private static final boolean COMMONS_LANG3_AVAILABLE;
+    static {
+        boolean b = true;
+        try {
+            new StringEscapeUtils();
+        } catch (Exception e) {
+            b = false;
+            LOG.warning("Apache commons-lang3 is not on the classpath; Java escaping in quotes
will not be available.");
+        }
+        COMMONS_LANG3_AVAILABLE = b;
+    }
+
     /**
      * Create a new PathNavigation instance.
      */
@@ -219,19 +237,19 @@ public class PathNavigation {
                     pos.next();
                     return w.toString();
                 }
-                try {
-                    int codePoints = org.apache.commons.lang3.StringEscapeUtils.UNESCAPE_JAVA.translate(path,
here, w);
-                    if (codePoints == 0) {
-                        w.write(Character.toChars(Character.codePointAt(path, here)));
-                        pos.next();
-                    } else {
-                        for (int i = 0; i < codePoints; i++) {
-                            pos.plus(Character.charCount(Character.codePointAt(path, pos.getIndex())));
-                        }
+                final int codePoints;
+                if (COMMONS_LANG3_AVAILABLE) {
+                    codePoints = StringEscapeUtils.UNESCAPE_JAVA.translate(path, here, w);
+                } else {
+                    codePoints = 0;                    
+                }
+                if (codePoints == 0) {
+                    w.write(Character.toChars(Character.codePointAt(path, here)));
+                    pos.next();
+                } else {
+                    for (int i = 0; i < codePoints; i++) {
+                        pos.plus(Character.charCount(Character.codePointAt(path, pos.getIndex())));
                     }
-                } catch (Exception e) {
-                    throw new RuntimeException(
-                        "Java escaping in quotes is only supported with Apache commons-lang3
on the classpath!");
                 }
             }
             // if reached, reset due to no ending quote found


Mime
View raw message