Class AbstractImageSessionContext
java.lang.Object
org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext
- All Implemented Interfaces:
ImageSessionContext
- Direct Known Subclasses:
DefaultImageSessionContext
Abstract base class for classes implementing ImageSessionContext. This class provides all the
special treatment for Source creation, i.e. it provides optimized Source objects where possible.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplementations of this interface will be used as the mechanism for creating theSourcethat wraps resources.static final classThis fallback resolver is to be used in environments where controlling file access is of critical importance.static final classAn unrestricted resolver that has various contingency mechanisms that access the file-system. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractImageSessionContext(AbstractImageSessionContext.FallbackResolver fallbackResolver) -
Method Summary
Modifier and TypeMethodDescriptionprotected static ImageInputStreamReturns a Source object for a URI.protected booleanisReusable(Source src) Indicates whether a Source is reusable.needSource(String uri) Returns a Source object for a URI.Attempts to create a Source object from the given URI.protected abstract SourceresolveURI(String uri) Attempts to resolve the given URI.voidreturnSource(String uri, Source src) Returns a Source object to a pool.static FileConvert from aURLto aFile.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ImageSessionContext
getParentContext, getSourceResolution, getTargetResolution
-
Constructor Details
-
AbstractImageSessionContext
public AbstractImageSessionContext() -
AbstractImageSessionContext
- Parameters:
fallbackResolver- the fallback resolution mechanism to be used when simply getting anInputStreamthat backs aSourceisn't possible.
-
-
Method Details
-
resolveURI
-
newSource
Attempts to create a Source object from the given URI. If possible this method returns an ImageSource instance which provides the best possible method to access the image.- Specified by:
newSourcein interfaceImageSessionContext- Parameters:
uri- URI to access- Returns:
- A
Sourceobject, or null if the URI cannot be resolved.
-
createImageInputStream
- Throws:
IOException
-
toFile
Convert from aURLto aFile.This method will decode the URL. Syntax such as
file:///my%20docs/file.txtwill be correctly decoded to/my docs/file.txt.Note: this method has been copied over from Apache Commons IO and enhanced to support UNC paths.
- Parameters:
url- the file URL to convert,nullreturnsnull- Returns:
- the equivalent
Fileobject, ornullif the URL's protocol is notfile - Throws:
IllegalArgumentException- if the file is incorrectly encoded
-
getSource
Returns a Source object for a URI. This method is not guaranteed to return an instance. Implementations normally return already created Sources from a pool (normally populated through theImageSessionContext.returnSource(String, Source)method).- Specified by:
getSourcein interfaceImageSessionContext- Parameters:
uri- the URI of the image- Returns:
- the Source object to load the image from, or null
-
needSource
Returns a Source object for a URI. This method is guaranteed to return a Source object. If the image cannot be found, aFileNotFoundExceptionis thrown.- Specified by:
needSourcein interfaceImageSessionContext- Parameters:
uri- the URI of the image- Returns:
- the Source object to load the image from
- Throws:
FileNotFoundException- if the image cannot be found
-
returnSource
Returns a Source object to a pool. This is provided in order to reuse a Source object between the preloading and the final loading of an image. Note that not all Source objects can be reused! Non-reusable Sources are discarded.- Specified by:
returnSourcein interfaceImageSessionContext- Parameters:
uri- the URI of the imagesrc- the Source object belonging to the URI
-
isReusable
Indicates whether a Source is reusable. A Source object is reusable if it's anImageSource(containing anImageInputStream) or aDOMSource.- Parameters:
src- the Source object- Returns:
- true if the Source is reusable
-