public class OsgiBundleResource
extends org.springframework.core.io.AbstractResource
implements org.springframework.core.io.ContextResource
osgibundle:/
BUNDLE_URL_PREFIX prefix is being used or none is specified. This
space cotnains the bundle jar and its attached fragments.osgibundlejar:/
BUNDLE_JAR_URL_PREFIX is specified. This space contains just the
bundle jar.ResourceUtils.CLASSPATH_URL_PREFIX is
encountered. This space contains the bundle classpath, namely the bundle jar,
its attached fragments and imported packages.bundleentry: and
bundleresource:under Equinox, bundle: under
Knopflefish and Felix, etc..) are supported. Resources outside the OSGi space
(file:, http:, etc..) are supported as well as the
path is being resolved to an URL.
If no prefix is specified, the bundle space will be used for
locating a resource.
Note: When the bundle space (bundle jar and its
attached fragments) is being searched, multiple URLs can be found but this
implementation will return only the first one. Consider using
OsgiBundleResourcePatternResolver to retrieve all entries.| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
ABSOLUTE_PATH_PREFIX |
private org.osgi.framework.Bundle |
bundle |
static java.lang.String |
BUNDLE_JAR_URL_PREFIX
Prefix for searching only the bundle raw jar.
|
static java.lang.String |
BUNDLE_URL_PREFIX
Prefix for searching inside the owning bundle space.
|
private java.lang.String |
path |
private java.lang.String |
pathWithoutPrefix |
private static char |
PREFIX_SEPARATOR |
private int |
searchType |
| Constructor and Description |
|---|
OsgiBundleResource(org.osgi.framework.Bundle bundle,
java.lang.String path)
Constructs a new
OsgiBundleResource instance. |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.core.io.Resource |
createRelative(java.lang.String relativePath)
Returns a resource relative to this resource.
|
boolean |
equals(java.lang.Object obj)
This implementation compares the underlying bundle and path locations.
|
boolean |
exists()
Return whether this resource actually exists in physical form.
|
(package private) org.springframework.core.io.ContextResource[] |
getAllUrlsFromBundleSpace(java.lang.String location)
Used internally to get all the URLs matching a certain location.
|
(package private) org.osgi.framework.Bundle |
getBundle()
Returns the bundle for this resource.
|
java.lang.String |
getDescription()
This implementation returns a description that includes the bundle
location.
|
java.io.File |
getFile()
Returns a
File handle for this resource. |
java.lang.String |
getFilename()
Returns the filename of this resources.
|
java.io.InputStream |
getInputStream()
Returns an
InputStream to this resource. |
(package private) java.lang.String |
getPath()
Returns the path for this resource.
|
java.lang.String |
getPathWithinContext() |
(package private) java.net.URL |
getResourceFromBundleClasspath(java.lang.String bundlePath)
Resolves a resource from the bundle's classpath.
|
(package private) java.net.URL |
getResourceFromBundleJar(java.lang.String bundlePath)
Resolves a resource from the *bundle jar* only.
|
(package private) org.springframework.core.io.ContextResource |
getResourceFromBundleSpace(java.lang.String bundlePath)
Resolves a resource from *the bundle space* only.
|
(package private) int |
getSearchType() |
java.net.URL |
getURL()
Locates the resource in the underlying bundle based on the prefix, if it
exists.
|
int |
hashCode()
This implementation returns the hash code of the underlying class path
location.
|
(package private) boolean |
isRelativePath(java.lang.String locationPath)
Determine if the given path is relative or absolute.
|
long |
lastModified() |
contentLength, getFileForLastModifiedCheck, getURI, isOpen, isReadable, toStringpublic static final java.lang.String BUNDLE_URL_PREFIX
public static final java.lang.String BUNDLE_JAR_URL_PREFIX
private static final char PREFIX_SEPARATOR
private static final java.lang.String ABSOLUTE_PATH_PREFIX
private final org.osgi.framework.Bundle bundle
private final java.lang.String path
private final java.lang.String pathWithoutPrefix
private int searchType
public OsgiBundleResource(org.osgi.framework.Bundle bundle,
java.lang.String path)
OsgiBundleResource instance.bundle - OSGi bundle used by this resourcepath - resource path inside the bundle.final java.lang.String getPath()
final org.osgi.framework.Bundle getBundle()
public java.io.InputStream getInputStream()
throws java.io.IOException
InputStream to this resource. This implementation
opens an InputStream for the given URL. It sets
the UseCaches flag to false, mainly to avoid jar
file locking on Windows.getInputStream in interface org.springframework.core.io.InputStreamSourcejava.io.IOException - if the stream could not be openedURL.openConnection(),
URLConnection.setUseCaches(boolean),
URLConnection.getInputStream()public java.net.URL getURL()
throws java.io.IOException
getURL in interface org.springframework.core.io.ResourcegetURL in class org.springframework.core.io.AbstractResourcejava.io.IOException - if the resource cannot be resolved as URL, i.e. if
the resource is not available as descriptorBundle.getEntry(String),
Bundle.getResource(String)org.springframework.core.io.ContextResource getResourceFromBundleSpace(java.lang.String bundlePath)
throws java.io.IOException
OsgiBundleResourcePatternResolver.bundlePath - the path to resolvejava.io.IOExceptionorg.osgi.framework.Bundle#findEntries(String, String, boolean)}java.net.URL getResourceFromBundleJar(java.lang.String bundlePath)
throws java.io.IOException
bundlePath - the path to resolvejava.io.IOExceptionBundle#getEntry(String)}java.net.URL getResourceFromBundleClasspath(java.lang.String bundlePath)
bundlePath - Bundle.getResource(String)boolean isRelativePath(java.lang.String locationPath)
locationPath - public org.springframework.core.io.Resource createRelative(java.lang.String relativePath)
OsgiBundleResource, applying the given path relative to
the path of the underlying resource of this descriptor.createRelative in interface org.springframework.core.io.ResourcecreateRelative in class org.springframework.core.io.AbstractResourcerelativePath - the relative path (relative to this resource)java.io.IOException - if the relative resource cannot be determinedStringUtils.applyRelativePath(String,
String)public java.lang.String getFilename()
getFilename in interface org.springframework.core.io.ResourcegetFilename in class org.springframework.core.io.AbstractResourceStringUtils.getFilename(String)public java.io.File getFile()
throws java.io.IOException
File handle for this resource. This method does a
best-effort attempt to locate the bundle resource on the file system. It
is strongly recommended to use getInputStream() method instead
which works no matter if the bundles are saved (in exploded form or not)
on the file system.getFile in interface org.springframework.core.io.ResourcegetFile in class org.springframework.core.io.AbstractResourcejava.io.IOException - if the resource cannot be resolved as absolute file
path, i.e. if the resource is not available in a file systempublic java.lang.String getDescription()
getDescription in interface org.springframework.core.io.Resourcepublic boolean equals(java.lang.Object obj)
equals in class org.springframework.core.io.AbstractResourcepublic int hashCode()
hashCode in class org.springframework.core.io.AbstractResourcepublic long lastModified()
throws java.io.IOException
lastModified in interface org.springframework.core.io.ResourcelastModified in class org.springframework.core.io.AbstractResourcejava.io.IOExceptionint getSearchType()
org.springframework.core.io.ContextResource[] getAllUrlsFromBundleSpace(java.lang.String location)
throws java.io.IOException
location - location to look forjava.io.IOExceptionpublic java.lang.String getPathWithinContext()
getPathWithinContext in interface org.springframework.core.io.ContextResourcepublic boolean exists()
This method performs a definitive existence check, whereas the existence
of a Resource handle only guarantees a valid descriptor
handle.
exists in interface org.springframework.core.io.Resourceexists in class org.springframework.core.io.AbstractResource