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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e17141  CAMEL-15110: camel-core - ResourceHelper to have method to 
tell if the resource is classpath or not
3e17141 is described below

commit 3e17141d88983a0830dc21135bec536a53513b6b
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue May 26 09:34:44 2020 +0200

    CAMEL-15110: camel-core - ResourceHelper to have method to tell if the 
resource is classpath or not
---
 .../java/org/apache/camel/util/ResourceHelperTest.java   | 12 ++++++++++++
 .../java/org/apache/camel/support/ResourceHelper.java    | 16 +++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/util/ResourceHelperTest.java 
b/core/camel-core/src/test/java/org/apache/camel/util/ResourceHelperTest.java
index 31b0869..bef5a3b 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/util/ResourceHelperTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/util/ResourceHelperTest.java
@@ -320,6 +320,18 @@ public class ResourceHelperTest extends TestSupport {
     }
 
     @Test
+    public void testIsClasspath() throws Exception {
+        assertFalse(ResourceHelper.isClasspathUri("direct:foo"));
+        assertFalse(ResourceHelper.isClasspathUri("file:foo/bar.properties"));
+        assertFalse(ResourceHelper.isClasspathUri("http://camel.apache.org";));
+        assertFalse(ResourceHelper.isClasspathUri(""));
+        assertFalse(ResourceHelper.isClasspathUri(null));
+
+        
assertTrue(ResourceHelper.isClasspathUri("classpath:foo/bar.properties"));
+        assertTrue(ResourceHelper.isClasspathUri("foo/bar.properties"));
+    }
+
+    @Test
     public void testGetScheme() throws Exception {
         assertEquals("file:", ResourceHelper.getScheme("file:myfile.txt"));
         assertEquals("classpath:", 
ResourceHelper.getScheme("classpath:myfile.txt"));
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java 
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
index 8046832..960a7cd 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/ResourceHelper.java
@@ -42,6 +42,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.util.AntPathMatcher;
 import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.URISupport;
 import org.slf4j.Logger;
@@ -249,13 +250,26 @@ public final class ResourceHelper {
     }
 
     /**
+     * Is the given uri a classpath uri?
+     *
+     * @param uri the uri
+     * @return <tt>true</tt> if the uri starts with <tt>classpath:</tt> or has 
no scheme and therefore would otherwise be loaded from classpath by default.
+     */
+    public static boolean isClasspathUri(String uri) {
+        if (ObjectHelper.isEmpty(uri)) {
+            return false;
+        }
+        return uri.startsWith("classpath:") || uri.indexOf(':') == -1;
+    }
+
+    /**
      * Is the given uri a http uri?
      *
      * @param uri the uri
      * @return <tt>true</tt> if the uri starts with <tt>http:</tt> or 
<tt>https:</tt>
      */
     public static boolean isHttpUri(String uri) {
-        if (uri == null) {
+        if (ObjectHelper.isEmpty(uri)) {
             return false;
         }
         return uri.startsWith("http:") || uri.startsWith("https:");

Reply via email to