public class ClasspathContentResolver extends Object implements ContentResolver
ContentResolver
implementation to read content from the Classpath.
Uses the default ClassLoader: typically the thread context ClassLoader
see getClassLoader()
.
Optional Path Prefix is "classpath:".
Modifier and Type | Field and Description |
---|---|
static String |
CLASSPATH_URL_PREFIX
Pseudo URL prefix for loading from the class path: "classpath:".
|
Constructor and Description |
---|
ClasspathContentResolver() |
Modifier and Type | Method and Description |
---|---|
void |
addContentResolver(ContentResolver contentResolver)
Some Implementations of a
ContentResolver are delegating the functionality
to other ContentResolvers. |
static ClassLoader |
getClassLoader()
Return the default ClassLoader to use: typically the thread context ClassLoader, if available; the ClassLoader
that loaded the ClasspathContentResolver class will be used as fallback.
|
byte[] |
getContent(String key)
Reads the Content for the given Key or null if nothing where found.
|
static URL |
getResource(String key)
Method to get onlx the URL for the given Key.
|
public static final String CLASSPATH_URL_PREFIX
public void addContentResolver(ContentResolver contentResolver)
ContentResolver
are delegating the functionality
to other ContentResolvers.UnionContentResolver
-------------------------------------- <contentResolver name="DefaultContentResolver" class="org.settings4j.contentresolver.UnionContentResolver"> <contentResolver-ref ref="FSContentResolver" /> <contentResolver-ref ref="ClasspathContentResolver" /> </contentResolver> --------------------------------------
addContentResolver
in interface ContentResolver
contentResolver
- the original contentResolver to delegate.public byte[] getContent(String key)
getContent
in interface ContentResolver
key
- The keypublic static URL getResource(String key)
key
- the key (could have a 'classpath:' prefix or not)URL
, see ClassLoader.getResource(String)
.public static ClassLoader getClassLoader()
Call this method if you intend to use the thread context ClassLoader in a scenario where you absolutely need a
non-null ClassLoader reference: for example, for class path resource loading (but not necessarily for
Class.forName
, which accepts a null
ClassLoader reference as well).
null
)Thread.getContextClassLoader()
Copyright © 2008–2014. All rights reserved.