Top Description Inners Fields Constructors Methods
org.webjars

public Class WebJarAssetLocator

extends Object
Class Inheritance
Static Imports
java.util.Objects.requireNonNull

Locate WebJar assets. The class is thread safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
protected final Map<String, WebJarAssetLocator.WebJarInfo>
private static final Pattern
public static final String
WEBJARS_PACKAGE

The webjar package name.

public static final String
WEBJARS_PATH_PREFIX

The path to where webjar resources live.

Constructor Summary

AccessConstructor and Description
public
public
WebJarAssetLocator(final ClassLoader classLoader)

public
WebJarAssetLocator(final String... whitelistPaths)

public
WebJarAssetLocator(final ClassLoader classLoader, final String... whitelistPaths)

public
public

Method Summary

Modifier and TypeMethod and Description
private static Optional<MavenProperties>
findMavenInfo(final URI classpathElementURI)

protected static Map<String, WebJarAssetLocator.WebJarInfo>
findWebJars(ScanResult scanResult)

public Map<String, WebJarAssetLocator.WebJarInfo>
public String

Returns:

a fully qualified path to the resource.
getFullPath
(final String
the path to return e.g. "jquery.js" or "abc/someother.js". This must be a distinct path within the index passed in (not null or empty).
partialPath
)

Given a distinct path within the WebJar index passed in return the full path of the resource.

public String

Returns:

a fully qualified path to the resource
getFullPath
(final String
The id of the WebJar to search (not null
webjar
,
final String
The partial path to look for (not null
partialPath
)

Returns the full path of an asset within a specific WebJar

public String

Returns:

a fully qualified path to the resource of null if WebJar not found
getFullPathExact
(final String
The id of the WebJar to search (must not be null
webJarName
,
final String
The exact path of the file within the WebJar (may be null for legacy reasons)
exactPath
)

Returns the full path of an asset within a specific WebJar

public static Map.Entry<String, String>

Returns:

A WebJar tuple (Entry) with key = id and value = version or null if not a legal WebJar file format
getWebJar
(CharSequence
The full WebJar path (not null)
path
)

public Map<String, String>

Returns:

A map of the WebJars based on the files in the CLASSPATH where the key is the artifactId and the value is the version
getWebJars
()

public String

Returns:

the Group ID for the WebJar or null if it can't be determined
groupId
(final String
the fullPath to the asset in a WebJar, i.e. META-INF/resources/webjars/jquery/2.1.0/jquery.js
fullPath
)

Gets the Group ID given a fullPath

private static boolean
public Set<String>
public Set<String>

Returns:

a set of folder paths that match.
listAssets
(final String
the root path to the folder.
folderPath
)

List assets within a folder.

private static Map<String, WebJarAssetLocator.WebJarInfo>
private static void
throwMultipleMatchesException(final String partialPath, final List<String> matches)

private static void
throwNotFoundException(final String partialPath)

protected static ResourceList
webJarResources(final String webJarName, final ResourceList resources)

protected static String
webJarVersion(final String webJarName, final ResourceList resources)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allWebJarsback to summary
protected final Map<String, WebJarAssetLocator.WebJarInfo> allWebJars
WEBJAR_EXTRACTOR_PATTERNback to summary
private static final Pattern WEBJAR_EXTRACTOR_PATTERN
WEBJARS_PACKAGEback to summary
public static final String WEBJARS_PACKAGE

The webjar package name.

WEBJARS_PATH_PREFIXback to summary
public static final String WEBJARS_PATH_PREFIX

The path to where webjar resources live.

Constructor Detail

WebJarAssetLocatorback to summary
public WebJarAssetLocator()
WebJarAssetLocatorback to summary
public WebJarAssetLocator(final ClassLoader classLoader)
WebJarAssetLocatorback to summary
public WebJarAssetLocator(final String... whitelistPaths)
WebJarAssetLocatorback to summary
public WebJarAssetLocator(final ClassLoader classLoader, final String... whitelistPaths)
WebJarAssetLocatorback to summary
public WebJarAssetLocator(ClassGraph classGraph)
WebJarAssetLocatorback to summary
public WebJarAssetLocator(final Map<String, WebJarAssetLocator.WebJarInfo> allWebJars)

Method Detail

findMavenInfoback to summary
private static Optional<MavenProperties> findMavenInfo(final URI classpathElementURI)
findWebJarsback to summary
protected static Map<String, WebJarAssetLocator.WebJarInfo> findWebJars(ScanResult scanResult)
Annotations
@Nonnull
getAllWebJarsback to summary
public Map<String, WebJarAssetLocator.WebJarInfo> getAllWebJars()
getFullPathback to summary
public String getFullPath(final String partialPath)

Given a distinct path within the WebJar index passed in return the full path of the resource.

Parameters
partialPath:String

the path to return e.g. "jquery.js" or "abc/someother.js". This must be a distinct path within the index passed in (not null or empty).

Returns:String

a fully qualified path to the resource.

Annotations
@Nonnull
getFullPathback to summary
public String getFullPath(final String webjar, final String partialPath)

Returns the full path of an asset within a specific WebJar

Parameters
webjar:String

The id of the WebJar to search (not null

partialPath:String

The partial path to look for (not null

Returns:String

a fully qualified path to the resource

Annotations
@Nonnull
Exceptions
NotFoundException:
if webjar or path not found
getFullPathExactback to summary
public String getFullPathExact(final String webJarName, final String exactPath)

Returns the full path of an asset within a specific WebJar

Parameters
webJarName:String

The id of the WebJar to search (must not be null

exactPath:String

The exact path of the file within the WebJar (may be null for legacy reasons)

Returns:String

a fully qualified path to the resource of null if WebJar not found

Annotations
@Nullable
getWebJarback to summary
public static Map.Entry<String, String> getWebJar(CharSequence path)
Parameters
path:CharSequence

The full WebJar path (not null)

Returns:Map.Entry<String, String>

A WebJar tuple (Entry) with key = id and value = version or null if not a legal WebJar file format

Annotations
@Nullable
getWebJarsback to summary
public Map<String, String> getWebJars()
Returns:Map<String, String>

A map of the WebJars based on the files in the CLASSPATH where the key is the artifactId and the value is the version

Annotations
@Nonnull
groupIdback to summary
public String groupId(final String fullPath)

Gets the Group ID given a fullPath

Parameters
fullPath:String

the fullPath to the asset in a WebJar, i.e. META-INF/resources/webjars/jquery/2.1.0/jquery.js

Returns:String

the Group ID for the WebJar or null if it can't be determined

Annotations
@Nullable
isEmptyback to summary
private static boolean isEmpty(String str)
listAssetsback to summary
public Set<String> listAssets()
Annotations
@Nonnull
listAssetsback to summary
public Set<String> listAssets(final String folderPath)

List assets within a folder.

Parameters
folderPath:String

the root path to the folder.

Returns:Set<String>

a set of folder paths that match.

Annotations
@Nonnull
scanForWebJarsback to summary
private static Map<String, WebJarAssetLocator.WebJarInfo> scanForWebJars(ClassGraph classGraph)
Annotations
@Nonnull
throwMultipleMatchesExceptionback to summary
private static void throwMultipleMatchesException(final String partialPath, final List<String> matches)
throwNotFoundExceptionback to summary
private static void throwNotFoundException(final String partialPath)
webJarResourcesback to summary
protected static ResourceList webJarResources(final String webJarName, final ResourceList resources)
Annotations
@Nonnull
webJarVersionback to summary
protected static String webJarVersion(final String webJarName, final ResourceList resources)
Annotations
@Nullable
org.webjars back to summary

public Class WebJarAssetLocator.WebJarInfo

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final String
pack-priv final Collection<String>
pack-priv final String
pack-priv final URI
pack-priv final String

Constructor Summary

AccessConstructor and Description
pack-priv
WebJarInfo(final String version, Optional<MavenProperties> mavenProperties, final URI uri, final Collection<String> contents)

Method Summary

Modifier and TypeMethod and Description
public String
public Collection<String>

Returns:

an immutable list of resources.
getContents
()

public String
public URI
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

artifactIdback to summary
pack-priv final String artifactId
contentsback to summary
pack-priv final Collection<String> contents
groupIdback to summary
pack-priv final String groupId
uriback to summary
pack-priv final URI uri
versionback to summary
pack-priv final String version

Constructor Detail

WebJarInfoback to summary
pack-priv WebJarInfo(final String version, Optional<MavenProperties> mavenProperties, final URI uri, final Collection<String> contents)

Method Detail

getArtifactIdback to summary
public String getArtifactId()
Annotations
@Nullable
getContentsback to summary
public Collection<String> getContents()
Returns:Collection<String>

an immutable list of resources.

Annotations
@Nonnull
getGroupIdback to summary
public String getGroupId()
Annotations
@Nullable
getUriback to summary
public URI getUri()
getVersionback to summary
public String getVersion()
Annotations
@Nullable