diff --git a/src/main/java/org/webjars/WebJarVersionLocator.java b/src/main/java/org/webjars/WebJarVersionLocator.java index 5812718..1122d94 100644 --- a/src/main/java/org/webjars/WebJarVersionLocator.java +++ b/src/main/java/org/webjars/WebJarVersionLocator.java @@ -67,6 +67,23 @@ public String fullPath(final String webJarName, final String exactPath) { } } + /** + * + * @param webJarName The name of the WebJar, i.e. bootstrap + * @param exactPath The path to the file within the WebJar, i.e. js/bootstrap.js + * @return The path to the file in the standard WebJar classpath location, including the version, i.e. bootstrap/3.1.1/js/bootstrap.js + */ + @Nullable + public String path(final String webJarName, final String exactPath) { + String maybeFullPath = fullPath(webJarName, exactPath); + if (maybeFullPath != null) { + return maybeFullPath.replace(WEBJARS_PATH_PREFIX + "/", ""); + } + else { + return null; + } + } + /** * @param webJarName The name of the WebJar, i.e. bootstrap * @return The version of the WebJar, i.e 3.1.1 diff --git a/src/test/java/org/webjars/WebJarVersionLocatorTest.java b/src/test/java/org/webjars/WebJarVersionLocatorTest.java index 03a6a16..d04baec 100644 --- a/src/test/java/org/webjars/WebJarVersionLocatorTest.java +++ b/src/test/java/org/webjars/WebJarVersionLocatorTest.java @@ -29,6 +29,11 @@ public void full_path_exists_version_not_supplied() { assertEquals(WebJarVersionLocator.WEBJARS_PATH_PREFIX + "/bootstrap/3.1.1/js/bootstrap.js", new WebJarVersionLocator().fullPath("bootstrap", "js/bootstrap.js")); } + @Test + public void path_exists_version_not_supplied() { + assertEquals("bootstrap/3.1.1/js/bootstrap.js", new WebJarVersionLocator().path("bootstrap", "js/bootstrap.js")); + } + @Test public void full_path_exists_version_supplied() { assertEquals(WebJarVersionLocator.WEBJARS_PATH_PREFIX + "/bootstrap/3.1.1/js/bootstrap.js", new WebJarVersionLocator().fullPath("bootstrap", "3.1.1/js/bootstrap.js"));