Package org.apache.xmlgraphics.util
Class ClasspathResource
- java.lang.Object
-
- org.apache.xmlgraphics.util.ClasspathResource
-
public final class ClasspathResource extends java.lang.Object
A class to find resources in the classpath by their mime-type specified in the MANIFEST.This class searches for content entries in all META-INF/MANIFEST.MF files. It will find files with a given Content-Type: attribute. This allows to add arbitrary resources by content-type just by creating a JAR wrapper and adding them to the classpath.
Example:
Name: test.txt Content-Type: text/plain
-
-
Field Summary
Fields Modifier and Type Field Description private static ClasspathResource
classpathResource
private static java.lang.String
CONTENT_TYPE_KEY
private java.util.Map
contentMappings
Actual Type: Map<String,List<URL>>.private static java.lang.String
MANIFEST_PATH
-
Constructor Summary
Constructors Modifier Constructor Description private
ClasspathResource()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addToMapping(java.lang.String contentType, java.lang.String name, java.lang.ClassLoader classLoader)
private java.util.Set
getClassLoadersForResources()
static ClasspathResource
getInstance()
Retrieve the singleton instance of this class.java.util.List
listResourcesOfMimeType(java.lang.String mimeType)
Retrieve a list of resources known to have the given mime-type.private void
loadManifests()
-
-
-
Field Detail
-
contentMappings
private final java.util.Map contentMappings
Actual Type: Map<String,List<URL>>.
-
MANIFEST_PATH
private static final java.lang.String MANIFEST_PATH
- See Also:
- Constant Field Values
-
CONTENT_TYPE_KEY
private static final java.lang.String CONTENT_TYPE_KEY
- See Also:
- Constant Field Values
-
classpathResource
private static ClasspathResource classpathResource
-
-
Method Detail
-
getInstance
public static ClasspathResource getInstance()
Retrieve the singleton instance of this class.- Returns:
- the ClassPathResource instance.
-
getClassLoadersForResources
private java.util.Set getClassLoadersForResources()
-
loadManifests
private void loadManifests()
-
addToMapping
private void addToMapping(java.lang.String contentType, java.lang.String name, java.lang.ClassLoader classLoader)
-
listResourcesOfMimeType
public java.util.List listResourcesOfMimeType(java.lang.String mimeType)
Retrieve a list of resources known to have the given mime-type.- Parameters:
mimeType
- the mime-type to search for.- Returns:
- a List<URL>, guaranteed to be != null.
-
-