Class ImageManager
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.commons.logging.Log
logger -
Constructor Summary
ConstructorsConstructorDescriptionImageManager
(ImageContext context) Main constructor.ImageManager
(ImageImplRegistry registry, ImageContext context) Constructor for testing purposes. -
Method Summary
Modifier and TypeMethodDescriptionchoosePipeline
(ImageProviderPipeline[] candidates) Chooses the bestImageProviderPipeline
from a set of candidates.void
closeImage
(String uri, ImageSessionContext session) Closes the resources associated to the given image.convertImage
(Image image, ImageFlavor[] flavors) Converts an image with no hints.convertImage
(Image image, ImageFlavor[] flavors, Map hints) Converts an image.getCache()
Returns the ImageCache in use by the ImageManager.getImage
(ImageInfo info, ImageFlavor[] flavors, Map hints, ImageSessionContext session) Loads an image.getImage
(ImageInfo info, ImageFlavor[] flavors, ImageSessionContext session) Loads an image with no hints.getImage
(ImageInfo info, ImageFlavor flavor, Map hints, ImageSessionContext session) Loads an image.getImage
(ImageInfo info, ImageFlavor flavor, ImageSessionContext session) Loads an image with no hints.Returns the ImageContext in use by the ImageManager.getImageInfo
(String uri, ImageSessionContext session) Returns an ImageInfo object containing its intrinsic size for a given URI.Returns the PipelineFactory in use by the ImageManager.Returns the ImageImplRegistry in use by the ImageManager.preloadImage
(String uri, Source src) Preloads an image, i.e.preloadImage
(String uri, ImageSessionContext session) Preloads an image, i.e.
-
Field Details
-
log
protected static final org.apache.commons.logging.Log loglogger
-
-
Constructor Details
-
ImageManager
Main constructor.- Parameters:
context
- the session-independent context information
-
ImageManager
Constructor for testing purposes.- Parameters:
registry
- the implementation registry with all plug-inscontext
- the session-independent context information
-
-
Method Details
-
getRegistry
Returns the ImageImplRegistry in use by the ImageManager.- Returns:
- the ImageImplRegistry
-
getImageContext
Returns the ImageContext in use by the ImageManager.- Returns:
- the ImageContext
-
getCache
Returns the ImageCache in use by the ImageManager.- Returns:
- the ImageCache
-
getPipelineFactory
Returns the PipelineFactory in use by the ImageManager.- Returns:
- the PipelineFactory
-
getImageInfo
public ImageInfo getImageInfo(String uri, ImageSessionContext session) throws ImageException, IOException Returns an ImageInfo object containing its intrinsic size for a given URI. The ImageInfo is retrieved from an image cache if it has been requested before.- Parameters:
uri
- the URI of the imagesession
- the session context through which to resolve the URI if the image is not in the cache- Returns:
- the ImageInfo object created from the image
- Throws:
ImageException
- If no suitable ImagePreloader can be found to load the image or if an error occurred while preloading the image.IOException
- If an I/O error occurs while preloading the image
-
preloadImage
public ImageInfo preloadImage(String uri, ImageSessionContext session) throws ImageException, IOException Preloads an image, i.e. the format of the image is identified and some basic information (MIME type, intrinsic size and possibly other values) are loaded and returned as an ImageInfo object. Note that the image is not fully loaded normally. Only with certain formats the image is already fully loaded and references added to the ImageInfo's custom objects (seeImageInfo.getOriginalImage()
).The reason for the preloading: Apache FOP, for example, only needs the image's intrinsic size during layout. Only when the document is rendered to the final format does FOP need to load the full image. Like this a lot of memory can be saved.
- Parameters:
uri
- the original URI of the imagesession
- the session context through which to resolve the URI- Returns:
- the ImageInfo object created from the image
- Throws:
ImageException
- If no suitable ImagePreloader can be found to load the image or if an error occurred while preloading the image.IOException
- If an I/O error occurs while preloading the image
-
preloadImage
Preloads an image, i.e. the format of the image is identified and some basic information (MIME type, intrinsic size and possibly other values) are loaded and returned as an ImageInfo object. Note that the image is not fully loaded normally. Only with certain formats the image is already fully loaded and references added to the ImageInfo's custom objects (seeImageInfo.getOriginalImage()
).The reason for the preloading: Apache FOP, for example, only needs the image's intrinsic size during layout. Only when the document is rendered to the final format does FOP need to load the full image. Like this a lot of memory can be saved.
- Parameters:
uri
- the original URI of the imagesrc
- the Source object to load the image from- Returns:
- the ImageInfo object created from the image
- Throws:
ImageException
- If no suitable ImagePreloader can be found to load the image or if an error occurred while preloading the image.IOException
- If an I/O error occurs while preloading the image
-
getImage
public Image getImage(ImageInfo info, ImageFlavor flavor, Map hints, ImageSessionContext session) throws ImageException, IOException Loads an image. The caller can indicate what kind of image flavor is requested. When this method is called the code looks for a suitable ImageLoader and, if necessary, builds a conversion pipeline so it can return the image in exactly the form the caller needs.Optionally, it is possible to pass in Map of hints. These hints may be used by ImageLoaders and ImageConverters to act on the image. See
ImageProcessingHints
for common hints used by the bundled implementations. You can, of course, define your own hints.- Parameters:
info
- the ImageInfo instance for the image (obtained bygetImageInfo(String, ImageSessionContext)
)flavor
- the requested image flavor.hints
- a Map of hints to any of the background components or nullsession
- the session context- Returns:
- the fully loaded image
- Throws:
ImageException
- If no suitable loader/converter combination is available to fulfill the request or if an error occurred while loading the image.IOException
- If an I/O error occurs
-
getImage
public Image getImage(ImageInfo info, ImageFlavor[] flavors, Map hints, ImageSessionContext session) throws ImageException, IOException Loads an image. The caller can indicate what kind of image flavors are requested. When this method is called the code looks for a suitable ImageLoader and, if necessary, builds a conversion pipeline so it can return the image in exactly the form the caller needs. The array of image flavors is ordered, so the first image flavor is given highest priority.Optionally, it is possible to pass in Map of hints. These hints may be used by ImageLoaders and ImageConverters to act on the image. See
ImageProcessingHints
for common hints used by the bundled implementations. You can, of course, define your own hints.- Parameters:
info
- the ImageInfo instance for the image (obtained bygetImageInfo(String, ImageSessionContext)
)flavors
- the requested image flavors (in preferred order).hints
- a Map of hints to any of the background components or nullsession
- the session context- Returns:
- the fully loaded image
- Throws:
ImageException
- If no suitable loader/converter combination is available to fulfill the request or if an error occurred while loading the image.IOException
- If an I/O error occurs
-
getImage
public Image getImage(ImageInfo info, ImageFlavor flavor, ImageSessionContext session) throws ImageException, IOException Loads an image with no hints. SeegetImage(ImageInfo, ImageFlavor, Map, ImageSessionContext)
for more information.- Parameters:
info
- the ImageInfo instance for the image (obtained bygetImageInfo(String, ImageSessionContext)
)flavor
- the requested image flavor.session
- the session context- Returns:
- the fully loaded image
- Throws:
ImageException
- If no suitable loader/converter combination is available to fulfill the request or if an error occurred while loading the image.IOException
- If an I/O error occurs
-
getImage
public Image getImage(ImageInfo info, ImageFlavor[] flavors, ImageSessionContext session) throws ImageException, IOException Loads an image with no hints. SeegetImage(ImageInfo, ImageFlavor[], Map, ImageSessionContext)
for more information.- Parameters:
info
- the ImageInfo instance for the image (obtained bygetImageInfo(String, ImageSessionContext)
)flavors
- the requested image flavors (in preferred order).session
- the session context- Returns:
- the fully loaded image
- Throws:
ImageException
- If no suitable loader/converter combination is available to fulfill the request or if an error occurred while loading the image.IOException
- If an I/O error occurs
-
closeImage
Closes the resources associated to the given image. This method should be used only when none of thegetImage
methods is called by the client application.- Parameters:
uri
- the URI of the imagesession
- the session context that was used to resolve the URI
-
convertImage
public Image convertImage(Image image, ImageFlavor[] flavors, Map hints) throws ImageException, IOException Converts an image. The caller can indicate what kind of image flavors are requested. When this method is called the code looks for a suitable combination of ImageConverters so it can return the image in exactly the form the caller needs. The array of image flavors is ordered, so the first image flavor is given highest priority.Optionally, it is possible to pass in Map of hints. These hints may be used by ImageConverters to act on the image. See
ImageProcessingHints
for common hints used by the bundled implementations. You can, of course, define your own hints.- Parameters:
image
- the image to convertflavors
- the requested image flavors (in preferred order).hints
- a Map of hints to any of the background components or null- Returns:
- the fully loaded image
- Throws:
ImageException
- If no suitable loader/converter combination is available to fulfill the request or if an error occurred while loading the image.IOException
- If an I/O error occurs
-
convertImage
Converts an image with no hints. SeeconvertImage(Image, ImageFlavor[], Map)
for more information.- Parameters:
image
- the image to convertflavors
- the requested image flavors (in preferred order).- Returns:
- the fully loaded image
- Throws:
ImageException
- If no suitable loader/converter combination is available to fulfill the request or if an error occurred while loading the image.IOException
- If an I/O error occurs
-
choosePipeline
Chooses the bestImageProviderPipeline
from a set of candidates.- Parameters:
candidates
- the candidates- Returns:
- the best pipeline
-