org.springframework.richclient.image
Class Handler

java.lang.Object
  extended by java.net.URLStreamHandler
      extended by org.springframework.richclient.image.Handler

public class Handler
extends URLStreamHandler

A URL protocol handler that resolves images from an ImageSource.

The syntax of an "image:" URL is: image:{imageKey}

There are three methods to register/use this custom protocol:
  1. Supply the URLStreamHandler when constructing your URL object.
  2. Create an URLStreamHandlerFactory and register it on the URL class by using the setURLStreamFactory method.
  3. Create the URLStreamHandler by naming it Handler and placing it in a package which ends in the name if the protocol. Then register the package prefix before the protocol name by supplying it to the vm with the property -Djava.protocol.handler.pkgs. (thus setting it to eg 'my.company.protocols', your protocol is named image and your class name must be Handler which lives in package 'my.company.protocols.image') Multiple packages can be supplied by separating them with a '|'.
Now all of these have drawbacks:
  1. obviously you don't want to construct each URL object with its specific handler.
  2. the factory can be set only once, if set twice an exception will be thrown. This was the initial error of this issue.
  3. you need to supply this system parameter at startup. The static method in the image Handler can only be used if no URL was created before and the system parameter wasn't read yet.

We recommend that you use the system parameter at startup to ensure that the handler is registered:

 -Djava.protocol.handler.pkgs=org.springframework.richclient
 

A static method installImageUrlHandler(org.springframework.richclient.image.ImageSource) is provided that extends the system property and includes the 'org.springframework.richclient'. This method can also be triggered by creating an imageSource using DefaultImageSource.DefaultImageSource(boolean, java.util.Map). Note that this will only work if the system property isn't already read. If an URL was created and an URLStreamHandlerFactory is available, extending the system property won't have any effect.

Author:
Oliver Hutchison, Jan Hoskens

Constructor Summary
Handler()
          Creates an instance of Handler.
 
Method Summary
static void installImageUrlHandler(ImageSource urlHandlerImageSource)
          Installs this class as a handler for the "image:" protocol.
protected  URLConnection openConnection(URL url)
           
 
Methods inherited from class java.net.URLStreamHandler
equals, getDefaultPort, getHostAddress, hashCode, hostsEqual, openConnection, parseURL, sameFile, setURL, setURL, toExternalForm
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Handler

public Handler()
Creates an instance of Handler.

Method Detail

installImageUrlHandler

public static void installImageUrlHandler(ImageSource urlHandlerImageSource)
Installs this class as a handler for the "image:" protocol. Images will be resolved from the provided image source.


openConnection

protected URLConnection openConnection(URL url)
                                throws IOException
Specified by:
openConnection in class URLStreamHandler
Throws:
IOException


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.