Fields Summary |
---|
protected static final String | IMAGE_REQUESTEDConstant used to indicate that an image has been requested to the
ExternalResourceHandler but that the handler has not delivered the
result yet. |
protected javax.microedition.m2g.ExternalResourceHandler | handlerHandles any external resource referenced in the image document. |
protected SVGImageImpl | svgImageThe SVGImage associated to this SVGImageLoader |
protected Hashtable | rasterImageConsumerTableSimple hashtable used to track ImageNode objects. |
protected com.sun.perseus.j2d.ImageLoaderUtil | loaderUtilImageLoaderUtil contains helper methods which make this
implementation easier. |
protected boolean | documentLoadedSet to true once the associated DocumentNode has fully loaded. |
protected Vector | pendingNeedsURIKeeps track of pending absoluteURI requests. |
Methods Summary |
---|
public void | addRasterImageConsumer(java.lang.String absoluteURI, RasterImageConsumer imageNode)In cases where the ImageLoader may update the images associated to a URI,
RasterImageConsumer interested in updates need to register their interest
throught this method.
if (absoluteURI == null) {
return;
}
synchronized (rasterImageConsumerTable) {
Vector v = (Vector) rasterImageConsumerTable.get(absoluteURI);
if (v == null) {
v = new Vector(1);
v.addElement(imageNode);
rasterImageConsumerTable.put(absoluteURI, v);
} else {
if (!v.contains(imageNode)) {
v.addElement(imageNode);
}
}
}
|
void | addToCache(java.lang.String uri, java.lang.Object image)Adds image to the Image cache.
synchronized (cache) {
cache.put(uri, image);
}
|
public boolean | allowsRelativeURI()Determines whether this ImageLoader can handle relative uri's
return true;
|
public void | documentLoaded(DocumentNode doc)Some ImageLoader implementations may wish to wait until the end of the
Document load to start retrieving resources. This method notifies
the implementation that the DocumentNode completed loading successfully.
// Place a needsURIDocumentLoaded call for each entry in the
// pendingNeedsURI vector. See the needsURI method.
documentLoaded = true;
int n = pendingNeedsURI.size();
for (int i = 0; i < n; i++) {
needsURIDocumentLoaded((String) pendingNeedsURI.elementAt(i));
}
// Empty pending requests
pendingNeedsURI.removeAllElements();
|
public com.sun.perseus.j2d.RasterImage | getImageAndWait(java.lang.String uri)Requests the given image. This call blocks until an image is
returned.
// If we are dealing with a data URI, decode the image
// now. Data URIs do not go in the cache.
if (loaderUtil.isDataURI(uri)) {
return loaderUtil.getEmbededImage(uri);
}
Object img;
// We are dealing with a regular URI which requires IO.
// The image might already be in the loading queue from
// a call in needsURI.
synchronized (cache) {
img = cache.get(uri);
}
if ((img != null) && (img != IMAGE_REQUESTED)) {
return (RasterImage) img;
}
// Make the sure the image is requested
if (img == null) {
needsURI(uri);
}
// The URI has not been retrieved yet...
img = ((SVGImageImpl) svgImage).waitOnRequestCompleted(uri);
return (RasterImage) img;
|
public com.sun.perseus.j2d.RasterImage | getImageFromCache(java.lang.String uri)Returns the Image that was previously loaded.
Object img;
synchronized (cache) {
img = cache.get(uri);
if (IMAGE_REQUESTED == img) {
img = null;
}
}
return (RasterImage) img;
|
public void | getImageLater(java.lang.String uri, RasterImageConsumer rasterImageConsumer)Requests the given image. This call returns immediately and
the image is set on the input ImageNode when the
image becomes available.
// Only load later images which have not been loaded yet
// and which are not data URIs.
if (loaderUtil.isDataURI(uri)) {
rasterImageConsumer.setImage(loaderUtil.getEmbededImage(uri), uri);
return;
}
Object img = null;
synchronized (cache) {
img = cache.get(uri);
}
if ((img != null) && (img != IMAGE_REQUESTED)) {
rasterImageConsumer.setImage((RasterImage) img, uri);
return;
}
// Save ImageNode associated with the uri for use with SVGImage's
// requestCompleted().
addRasterImageConsumer(uri, rasterImageConsumer);
|
public void | needsURI(java.lang.String absoluteURI)Notifies the URILoader that the given uri will be needed.
// SVGImageLoader waits until the document has loaded before actually
// requesting any image from the ResourceHandler.
if (documentLoaded) {
needsURIDocumentLoaded(absoluteURI);
} else {
if (!loaderUtil.isDataURI(absoluteURI) &&
!pendingNeedsURI.contains(absoluteURI)) {
// Cache the request for future use (see documentLoaded method)
pendingNeedsURI.addElement(absoluteURI);
}
}
|
protected void | needsURIDocumentLoaded(java.lang.String absoluteURI)In SVGImageLoader, we wait until the document has been loaded before
acting on required raster images.
// Do not load base64 images as we do not want to
// store the base64 string in the cache, because it
// might be huge.
//
// Correct content should not have the same base64
// string duplicated. Rather, the same image element
// can be referenced by a use element.
if (!loaderUtil.isDataURI(absoluteURI)) {
boolean isRequested = true;
synchronized (cache) {
// First check if the image is already available (implies that
// images has been requested and obtained successfully)
Object imgObj = cache.get(absoluteURI);
if (null == imgObj) {
// The image has not been requested yet
isRequested = false;
addToCache(absoluteURI, IMAGE_REQUESTED);
} else if (IMAGE_REQUESTED != imgObj) {
// The image has been requested and retrieved
setRasterImageConsumerImage(absoluteURI,
(RasterImage) imgObj);
return;
}
}
// requestResource() called outside of synchronized block
// so that the cache is not unnecessarily locked. handler is an
// external implementation and the behavior is unpredictable.
if (!isRequested) {
System.err.println("handler.requestResource: " + absoluteURI);
handler.requestResource(svgImage, absoluteURI);
}
}
|
public void | removeRasterImageConsumer(java.lang.String absoluteURI, RasterImageConsumer imageNode)In cases where the ImageLoader may update the images associated to a URI,
RasterImageConsumer interested in updates need to de-register their
interest throught this method.
if (absoluteURI != null) {
synchronized (rasterImageConsumerTable) {
Vector v = (Vector) rasterImageConsumerTable.get(absoluteURI);
if (v != null) {
v.removeElement(imageNode);
}
}
}
|
void | setRasterImageConsumerImage(java.lang.String uri, com.sun.perseus.j2d.RasterImage image)Implementation helper.
((DocumentNode) svgImage.getDocument()).safeInvokeAndWait(
new Runnable() {
public void run() {
synchronized (rasterImageConsumerTable) {
Vector v =
(Vector) rasterImageConsumerTable.get(uri);
if (v != null) {
int n = v.size();
for (int i = 0; i < n; i++) {
final RasterImageConsumer in
= (RasterImageConsumer) v.elementAt(i);
in.setImage(image, uri);
}
}
}
}
});
|