Class AbstractImageSessionContext
- java.lang.Object
-
- org.apache.xmlgraphics.image.loader.impl.AbstractImageSessionContext
-
- All Implemented Interfaces:
ImageSessionContext
- Direct Known Subclasses:
DefaultImageSessionContext
public abstract class AbstractImageSessionContext extends java.lang.Object implements ImageSessionContext
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 Classes Modifier and Type Class Description static interface
AbstractImageSessionContext.FallbackResolver
Implementations of this interface will be used as the mechanism for creating theSource
that wraps resources.private static class
AbstractImageSessionContext.ObservingImageInputStreamInvocationHandler
static class
AbstractImageSessionContext.RestrictedFallbackResolver
This fallback resolver is to be used in environments where controlling file access is of critical importance.static class
AbstractImageSessionContext.UnrestrictedFallbackResolver
An unrestricted resolver that has various contingency mechanisms that access the file-system.
-
Field Summary
Fields Modifier and Type Field Description private AbstractImageSessionContext.FallbackResolver
fallbackResolver
private static org.apache.commons.logging.Log
log
loggerprivate static boolean
noSourceReuse
private SoftMapCache
sessionSources
-
Constructor Summary
Constructors Constructor Description AbstractImageSessionContext()
AbstractImageSessionContext(AbstractImageSessionContext.FallbackResolver fallbackResolver)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static javax.imageio.stream.ImageInputStream
createImageInputStream(java.io.InputStream in)
private static ImageSource
createImageSource(java.io.InputStream in, javax.xml.transform.Source source)
javax.xml.transform.Source
getSource(java.lang.String uri)
Returns a Source object for a URI.protected boolean
isReusable(javax.xml.transform.Source src)
Indicates whether a Source is reusable.javax.xml.transform.Source
needSource(java.lang.String uri)
Returns a Source object for a URI.javax.xml.transform.Source
newSource(java.lang.String uri)
Attempts to create a Source object from the given URI.protected abstract javax.xml.transform.Source
resolveURI(java.lang.String uri)
Attempts to resolve the given URI.void
returnSource(java.lang.String uri, javax.xml.transform.Source src)
Returns a Source object to a pool.static java.io.File
toFile(java.net.URL url)
Convert from aURL
to aFile
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.xmlgraphics.image.loader.ImageSessionContext
getParentContext, getTargetResolution
-
-
-
-
Field Detail
-
log
private static final org.apache.commons.logging.Log log
logger
-
noSourceReuse
private static boolean noSourceReuse
-
fallbackResolver
private final AbstractImageSessionContext.FallbackResolver fallbackResolver
-
sessionSources
private SoftMapCache sessionSources
-
-
Constructor Detail
-
AbstractImageSessionContext
public AbstractImageSessionContext()
-
AbstractImageSessionContext
public AbstractImageSessionContext(AbstractImageSessionContext.FallbackResolver fallbackResolver)
- Parameters:
fallbackResolver
- the fallback resolution mechanism to be used when simply getting anInputStream
that backs aSource
isn't possible.
-
-
Method Detail
-
resolveURI
protected abstract javax.xml.transform.Source resolveURI(java.lang.String uri)
Attempts to resolve the given URI.- Parameters:
uri
- URI to access- Returns:
- A
Source
object, or null if the URI cannot be resolved.
-
newSource
public javax.xml.transform.Source newSource(java.lang.String uri)
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:
newSource
in interfaceImageSessionContext
- Parameters:
uri
- URI to access- Returns:
- A
Source
object, or null if the URI cannot be resolved.
-
createImageInputStream
protected static javax.imageio.stream.ImageInputStream createImageInputStream(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
toFile
public static java.io.File toFile(java.net.URL url)
Convert from aURL
to aFile
.This method will decode the URL. Syntax such as
file:///my%20docs/file.txt
will 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,null
returnsnull
- Returns:
- the equivalent
File
object, ornull
if the URL's protocol is notfile
- Throws:
java.lang.IllegalArgumentException
- if the file is incorrectly encoded
-
getSource
public javax.xml.transform.Source getSource(java.lang.String uri)
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:
getSource
in interfaceImageSessionContext
- Parameters:
uri
- the URI of the image- Returns:
- the Source object to load the image from, or null
-
needSource
public javax.xml.transform.Source needSource(java.lang.String uri) throws java.io.FileNotFoundException
Returns a Source object for a URI. This method is guaranteed to return a Source object. If the image cannot be found, aFileNotFoundException
is thrown.- Specified by:
needSource
in interfaceImageSessionContext
- Parameters:
uri
- the URI of the image- Returns:
- the Source object to load the image from
- Throws:
java.io.FileNotFoundException
- if the image cannot be found
-
returnSource
public void returnSource(java.lang.String uri, javax.xml.transform.Source src)
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:
returnSource
in interfaceImageSessionContext
- Parameters:
uri
- the URI of the imagesrc
- the Source object belonging to the URI
-
isReusable
protected boolean isReusable(javax.xml.transform.Source src)
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
-
createImageSource
private static ImageSource createImageSource(java.io.InputStream in, javax.xml.transform.Source source)
-
-